clameursmod.module 5.3 KB

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