clameursmod.module 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. /**
  3. * Implements hook_menu().
  4. */
  5. // function clameursmod_menu() {
  6. // $items['accueil'] = array(
  7. // 'title' => '',
  8. // 'page callback' => '',
  9. // 'page arguments' => array(),
  10. // 'access arguments' => array(''),
  11. // 'type' => ,
  12. // 'file' => ,
  13. // );
  14. //
  15. // return $items;
  16. // }
  17. /**
  18. * Implements hook_entity_info_alter().
  19. */
  20. function clameursmod_entity_info_alter(&$entity_info) {
  21. $entity_info['node']['view modes']['accueil'] = array(
  22. 'label' => t('Accueil'),
  23. 'custom settings' => TRUE,
  24. );
  25. }
  26. /**
  27. * Implements hook_block_info().
  28. */
  29. function clameursmod_block_info() {
  30. $blocks['thematiques'] = array(
  31. 'info' => t('Clameurs thematiques'),
  32. 'cache' => DRUPAL_NO_CACHE
  33. );
  34. $blocks['thematiques-anchor-links'] = array(
  35. 'info' => t('Clameurs thematiques anchor links'),
  36. 'cache' => DRUPAL_NO_CACHE
  37. );
  38. return $blocks;
  39. }
  40. /**
  41. * Implements hook_block_view().
  42. */
  43. function clameursmod_block_view($delta = '') {
  44. $block = array();
  45. switch ($delta) {
  46. case 'thematiques':
  47. $block['subject'] = t('Thématiques');
  48. $block['content'] = _clameursmod_thematiques();
  49. break;
  50. case 'thematiques-anchor-links':
  51. $block['subject'] = t('Thématiques menu');
  52. $block['content'] = _clameursmod_thematiques_anchor_links();
  53. break;
  54. }
  55. return $block;
  56. }
  57. /**
  58. * Implements hook_theme().
  59. */
  60. function clameursmod_theme($existing, $type, $theme, $path) {
  61. return array(
  62. 'thematiques' => array(
  63. 'render element' => 'element'
  64. ),
  65. 'thematiques_anchor_links' => array(
  66. 'render element' => 'element'
  67. ),
  68. );
  69. }
  70. // ________ __ _
  71. // /_ __/ /_ ___ ____ ___ ____ _/ /_(_)___ ___ _____ _____
  72. // / / / __ \/ _ \/ __ `__ \/ __ `/ __/ / __ `/ / / / _ \/ ___/
  73. // / / / / / / __/ / / / / / /_/ / /_/ / /_/ / /_/ / __(__ )
  74. // /_/ /_/ /_/\___/_/ /_/ /_/\__,_/\__/_/\__, /\__,_/\___/____/
  75. // /_/
  76. function _clameursmod_thematiques(){
  77. $query = new EntityFieldQuery();
  78. $query
  79. ->entityCondition('entity_type', 'node')
  80. ->entityCondition('bundle', 'thematique')
  81. ->propertyCondition('status', 1)
  82. ->fieldOrderBy('field_poid', 'value', 'ASC');
  83. $result = $query->execute();
  84. // dsm($result['node'], "result");
  85. $nids = array_keys($result['node']);
  86. $nodes = array();
  87. foreach ($nids as $nid) {
  88. $nodes[] = node_load($nid);
  89. }
  90. return theme('thematiques', array("items"=>$nodes));
  91. }
  92. function theme_thematiques($vars){
  93. $nodes = $vars['items'];
  94. $view_mode = "accueil";
  95. $entity_view = entity_view('node', $nodes, $view_mode);
  96. return render($entity_view);
  97. }
  98. // ___ __
  99. // / | ____ _____/ /_ ____ __________
  100. // / /| | / __ \/ ___/ __ \/ __ \/ ___/ ___/
  101. // / ___ |/ / / / /__/ / / / /_/ / / (__ )
  102. // /_/ |_/_/ /_/\___/_/ /_/\____/_/ /____/
  103. function _clameursmod_thematiques_anchor_links(){
  104. $query = new EntityFieldQuery();
  105. $query
  106. ->entityCondition('entity_type', 'node')
  107. ->entityCondition('bundle', 'thematique')
  108. ->propertyCondition('status', 1)
  109. ->fieldOrderBy('field_poid', 'value', 'ASC');
  110. $result = $query->execute();
  111. $nids = array_keys($result['node']);
  112. $nodes = [];
  113. foreach ($nids as $nid) {
  114. $node = node_load($nid);
  115. // dsm($node);
  116. $alias = drupal_get_path_alias('node/'.$nid);
  117. // get the workflow state ID
  118. $current_state = workflow_state_load_single($node->workflow);
  119. // dsm($current_state, 'current_state');
  120. // $workflow = $current_state->getWorkflow();
  121. // dsm($workflow, "workflow");
  122. $scheduled_transitions = WorkflowScheduledTransition::load('node', $nid, NULL, 1);
  123. $transition = false;
  124. if(count($scheduled_transitions)){
  125. // dsm($scheduled_transitions, "scheduled_transitions");
  126. $transition = $scheduled_transitions[0];
  127. }
  128. $nodes[$nid] = array(
  129. "alias"=>$alias,
  130. "title"=>$node->title,
  131. "wf_sid"=>$node->workflow,
  132. "wf_stamp"=> $transition ? $transition->scheduled : false,
  133. "wf_state"=>$current_state->getName(),
  134. );
  135. }
  136. return theme('thematiques_anchor_links', array("items"=>$nodes));
  137. }
  138. function theme_thematiques_anchor_links($vars){
  139. $list = array(
  140. 'items'=>array(),
  141. 'type'=>'ul',
  142. 'attributes'=>array(
  143. "class"=>array("thematique-anchor-links")
  144. )
  145. );
  146. $i=0;
  147. foreach ($vars["items"] as $nid => $val) {
  148. // TODO: display the workflow state ID
  149. $options = array(
  150. "attributes"=>array(
  151. "class"=>array("anchor","pos-".$i, $val['wf_state'], 'node-'.$nid),
  152. ),
  153. "fragment"=>$val['alias'],
  154. "html"=>true,
  155. );
  156. $content = $val['title'];
  157. if($val["wf_stamp"]){
  158. $content .= "<span>" . format_date($val["wf_stamp"], 'custom', "d M Y") . "</span>";
  159. }
  160. $list['items'][] = l($content, '' , $options);
  161. $i++;
  162. }
  163. return theme('item_list', $list);
  164. }