123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- /**
- * Implements hook_menu().
- */
- // function clameursmod_menu() {
- // $items['accueil'] = array(
- // 'title' => '',
- // 'page callback' => '',
- // 'page arguments' => array(),
- // 'access arguments' => array(''),
- // 'type' => ,
- // 'file' => ,
- // );
- //
- // return $items;
- // }
- /**
- * Implements hook_entity_info_alter().
- */
- function clameursmod_entity_info_alter(&$entity_info) {
- $entity_info['node']['view modes']['accueil'] = array(
- 'label' => t('Accueil'),
- 'custom settings' => TRUE,
- );
- }
- /**
- * Implements hook_block_info().
- */
- function clameursmod_block_info() {
- $blocks['thematiques'] = array(
- 'info' => t('Clameurs thematiques'),
- 'cache' => DRUPAL_NO_CACHE
- );
- $blocks['thematiques-anchor-links'] = array(
- 'info' => t('Clameurs thematiques anchor links'),
- 'cache' => DRUPAL_NO_CACHE
- );
- return $blocks;
- }
- /**
- * Implements hook_block_view().
- */
- function clameursmod_block_view($delta = '') {
- $block = array();
- switch ($delta) {
- case 'thematiques':
- $block['subject'] = t('Thématiques');
- $block['content'] = _clameursmod_thematiques();
- break;
- case 'thematiques-anchor-links':
- $block['subject'] = t('Thématiques menu');
- $block['content'] = _clameursmod_thematiques_anchor_links();
- break;
- }
- return $block;
- }
- /**
- * Implements hook_theme().
- */
- function clameursmod_theme($existing, $type, $theme, $path) {
- return array(
- 'thematiques' => array(
- 'render element' => 'element'
- ),
- 'thematiques_anchor_links' => array(
- 'render element' => 'element'
- ),
- );
- }
- // ________ __ _
- // /_ __/ /_ ___ ____ ___ ____ _/ /_(_)___ ___ _____ _____
- // / / / __ \/ _ \/ __ `__ \/ __ `/ __/ / __ `/ / / / _ \/ ___/
- // / / / / / / __/ / / / / / /_/ / /_/ / /_/ / /_/ / __(__ )
- // /_/ /_/ /_/\___/_/ /_/ /_/\__,_/\__/_/\__, /\__,_/\___/____/
- // /_/
- function _clameursmod_thematiques(){
- $query = new EntityFieldQuery();
- $query
- ->entityCondition('entity_type', 'node')
- ->entityCondition('bundle', 'thematique')
- ->propertyCondition('status', 1)
- ->fieldOrderBy('field_poid', 'value', 'ASC');
- $result = $query->execute();
- // dsm($result['node'], "result");
- $nids = array_keys($result['node']);
- $nodes = array();
- foreach ($nids as $nid) {
- $nodes[] = node_load($nid);
- }
- return theme('thematiques', array("items"=>$nodes));
- }
- function theme_thematiques($vars){
- $nodes = $vars['items'];
- $view_mode = "accueil";
- $entity_view = entity_view('node', $nodes, $view_mode);
- return render($entity_view);
- }
- // ___ __
- // / | ____ _____/ /_ ____ __________
- // / /| | / __ \/ ___/ __ \/ __ \/ ___/ ___/
- // / ___ |/ / / / /__/ / / / /_/ / / (__ )
- // /_/ |_/_/ /_/\___/_/ /_/\____/_/ /____/
- function _clameursmod_thematiques_anchor_links(){
- $query = new EntityFieldQuery();
- $query
- ->entityCondition('entity_type', 'node')
- ->entityCondition('bundle', 'thematique')
- ->propertyCondition('status', 1)
- ->fieldOrderBy('field_poid', 'value', 'ASC');
- $result = $query->execute();
- $nids = array_keys($result['node']);
- $nodes = [];
- foreach ($nids as $nid) {
- $node = node_load($nid);
- // dsm($node);
- $alias = drupal_get_path_alias('node/'.$nid);
- // get the workflow state ID
- $current_state = workflow_state_load_single($node->workflow);
- // dsm($current_state, 'current_state');
- // $workflow = $current_state->getWorkflow();
- // dsm($workflow, "workflow");
- $scheduled_transitions = WorkflowScheduledTransition::load('node', $nid, NULL, 1);
- $transition = false;
- if(count($scheduled_transitions)){
- // dsm($scheduled_transitions, "scheduled_transitions");
- $transition = $scheduled_transitions[0];
- }
- $nodes[$nid] = array(
- "alias"=>$alias,
- "title"=>$node->title,
- "wf_sid"=>$node->workflow,
- "wf_stamp"=> $transition ? $transition->scheduled : false,
- "wf_state"=>$current_state->getName(),
- );
- }
- return theme('thematiques_anchor_links', array("items"=>$nodes));
- }
- function theme_thematiques_anchor_links($vars){
- $list = array(
- 'items'=>array(),
- 'type'=>'ul',
- 'attributes'=>array(
- "class"=>array("thematique-anchor-links")
- )
- );
- $i=0;
- foreach ($vars["items"] as $nid => $val) {
- // TODO: display the workflow state ID
- $options = array(
- "attributes"=>array(
- "class"=>array("anchor","pos-".$i, $val['wf_state'], 'node-'.$nid),
- ),
- "fragment"=>$val['alias'],
- "html"=>true,
- );
- $content = $val['title'];
- if($val["wf_stamp"]){
- $content .= "<span>" . format_date($val["wf_stamp"], 'custom', "d M Y") . "</span>";
- }
- $list['items'][] = l($content, '' , $options);
- $i++;
- }
- return theme('item_list', $list);
- }
|