clameursmod.module 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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'], 'style'=>'normal'));
  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. $entity_info['node']['view modes']['attente'] = array(
  41. 'label' => t('attente'),
  42. 'custom settings' => TRUE,
  43. );
  44. }
  45. /**
  46. * Implements hook_block_info().
  47. */
  48. function clameursmod_block_info() {
  49. $blocks['thematiques'] = array(
  50. 'info' => t('Clameurs thematiques'),
  51. 'cache' => DRUPAL_NO_CACHE
  52. );
  53. $blocks['thematiques-anchor-links'] = array(
  54. 'info' => t('Clameurs thematiques anchor links'),
  55. 'cache' => DRUPAL_NO_CACHE
  56. );
  57. return $blocks;
  58. }
  59. /**
  60. * Implements hook_block_view().
  61. */
  62. function clameursmod_block_view($delta = '') {
  63. $block = array();
  64. switch ($delta) {
  65. case 'thematiques':
  66. $block['subject'] = t('Thématiques');
  67. $block['content'] = _clameursmod_thematiques();
  68. break;
  69. case 'thematiques-anchor-links':
  70. $block['subject'] = t('Thématiques menu');
  71. $block['content'] = _clameursmod_thematiques_anchor_links();
  72. break;
  73. }
  74. return $block;
  75. }
  76. /**
  77. * Implements hook_theme().
  78. */
  79. function clameursmod_theme($existing, $type, $theme, $path) {
  80. return array(
  81. 'thematiques' => array(
  82. 'render element' => 'element'
  83. ),
  84. 'thematiques_anchor_links' => array(
  85. 'render element' => 'element'
  86. ),
  87. );
  88. }
  89. // ________ __ _
  90. // /_ __/ /_ ___ ____ ___ ____ _/ /_(_)___ ___ _____ _____
  91. // / / / __ \/ _ \/ __ `__ \/ __ `/ __/ / __ `/ / / / _ \/ ___/
  92. // / / / / / / __/ / / / / / /_/ / /_/ / /_/ / /_/ / __(__ )
  93. // /_/ /_/ /_/\___/_/ /_/ /_/\__,_/\__/_/\__, /\__,_/\___/____/
  94. // /_/
  95. function _clameursmod_thematiques(){
  96. $query = new EntityFieldQuery();
  97. $query
  98. ->entityCondition('entity_type', 'node')
  99. ->entityCondition('bundle', 'thematique')
  100. ->propertyCondition('status', 1)
  101. ->fieldOrderBy('field_poid', 'value', 'ASC');
  102. $result = $query->execute();
  103. // dsm($result['node'], "result");
  104. $nids = array_keys($result['node']);
  105. $nodes = array();
  106. foreach ($nids as $nid) {
  107. $nodes[] = node_load($nid);
  108. }
  109. return theme('thematiques', array("items"=>$nodes));
  110. }
  111. function theme_thematiques($vars){
  112. $nodes = $vars['items'];
  113. $rendered = "";
  114. foreach ($nodes as $key => $node) {
  115. // dsm($node, 'node');
  116. switch ($node->workflow) {
  117. case 7:
  118. $view_mode = "accueil";
  119. break;
  120. default:
  121. $view_mode = "attente";
  122. break;
  123. }
  124. $entity_view = entity_view('node', array($node), $view_mode);
  125. $rendered .= render($entity_view);
  126. }
  127. return $rendered;
  128. }
  129. // ___ __
  130. // / | ____ _____/ /_ ____ __________
  131. // / /| | / __ \/ ___/ __ \/ __ \/ ___/ ___/
  132. // / ___ |/ / / / /__/ / / / /_/ / / (__ )
  133. // /_/ |_/_/ /_/\___/_/ /_/\____/_/ /____/
  134. function _clameursmod_thematiques_anchor_links(){
  135. $query = new EntityFieldQuery();
  136. $query
  137. ->entityCondition('entity_type', 'node')
  138. ->entityCondition('bundle', 'thematique')
  139. ->propertyCondition('status', 1)
  140. ->fieldOrderBy('field_poid', 'value', 'ASC');
  141. $result = $query->execute();
  142. $nids = array_keys($result['node']);
  143. $nodes = [];
  144. foreach ($nids as $nid) {
  145. $node = node_load($nid);
  146. // dsm($node);
  147. $alias = str_replace('/', '-', drupal_get_path_alias('node/'.$nid));
  148. // get the workflow state ID
  149. $current_state = workflow_state_load_single($node->workflow);
  150. // dsm($current_state, 'current_state');
  151. // $workflow = $current_state->getWorkflow();
  152. // dsm($workflow, "workflow");
  153. $scheduled_transitions = WorkflowScheduledTransition::load('node', $nid, NULL, 1);
  154. $transition = false;
  155. if(count($scheduled_transitions)){
  156. // dsm($scheduled_transitions, "scheduled_transitions");
  157. $transition = $scheduled_transitions[0];
  158. }
  159. $nodes[$nid] = array(
  160. "alias"=>$alias,
  161. "title"=>$node->title,
  162. "wf_sid"=>$node->workflow,
  163. "wf_stamp"=> $transition ? $transition->scheduled : false,
  164. "wf_state"=>$current_state->getName(),
  165. );
  166. }
  167. return theme('thematiques_anchor_links', array("items"=>$nodes));
  168. }
  169. function theme_thematiques_anchor_links($vars){
  170. $list = array(
  171. 'items'=>array(),
  172. 'type'=>'ul',
  173. 'attributes'=>array(
  174. "class"=>array("thematique-anchor-links")
  175. )
  176. );
  177. $i=0;
  178. foreach ($vars["items"] as $nid => $val) {
  179. // TODO: display the workflow state ID
  180. $options = array(
  181. "attributes"=>array(
  182. "class"=>array("anchor","pos-".$i, $val['wf_state'], 'node-'.$nid),
  183. ),
  184. "fragment"=>$val['alias'],
  185. "html"=>true,
  186. );
  187. $content = $val['title'];
  188. if($val["wf_stamp"]){
  189. $content .= "<span>" . format_date($val["wf_stamp"], 'custom', "d M Y") . "</span>";
  190. }
  191. $list['items'][] = l($content, '' , $options);
  192. $i++;
  193. }
  194. return theme('item_list', $list);
  195. }