perfart.module 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. <?php
  2. /**
  3. * @file
  4. * This is the file description for Perfart module.
  5. *
  6. * In this more verbose, multi-line description, you can specify what this
  7. * file does exactly. Make sure to wrap your documentation in column 78 so
  8. * that the file can be displayed nicely in default-sized consoles.
  9. */
  10. define('PERFART_ELMTS_BY_PAGE', 100);
  11. /**
  12. * Implements hook_menu().
  13. */
  14. function perfart_menu() {
  15. $items = array();
  16. $base = array(
  17. 'access arguments' => array('access content'),
  18. 'type' => MENU_CALLBACK,
  19. 'file' => 'perfart.pages.inc',
  20. );
  21. $items['perfart/ajax/dates'] = $base+array(
  22. 'title' => 'List of dates',
  23. 'page callback' => 'perfart_get_dates',
  24. 'page arguments' => array(3),
  25. );
  26. $items['perfart/ajax/perf'] = $base+array(
  27. 'title' => 'content of one perf',
  28. 'page callback' => 'perfart_get_perf',
  29. 'page arguments' => array(3),
  30. );
  31. $items['perfart/ajax/home'] = $base+array(
  32. 'title' => 'content of home page',
  33. 'page callback' => 'perfart_get_home',
  34. 'page arguments' => array(),
  35. );
  36. $items['perfart/performances'] = $base+array(
  37. 'title' => 'List of performances',
  38. 'page callback' => 'perfart_get_performances',
  39. 'page arguments' => array(),
  40. );
  41. $items['perfart/search'] = $base+array(
  42. 'title' => 'search performances',
  43. 'page callback' => 'perfart_search',
  44. 'page arguments' => array(),
  45. );
  46. $items['perfart/search_api'] = $base+array(
  47. 'title' => 'search performances (through search_api)',
  48. 'page callback' => 'perfart_search_api',
  49. 'page arguments' => array(),
  50. );
  51. // $items['perfart/ajax/filters'] = array(
  52. // 'title' => 'List of filters blocks (taxonomy terms)',
  53. // 'page callback' => 'perfart_get_filters',
  54. // 'access callback' => TRUE,
  55. // 'file' => 'perfart.pages.inc',
  56. // 'page arguments' => array(),
  57. // );
  58. // $items['perfart/update_cer'] = array(
  59. // 'title' => 'Updating Corresponding entity reference',
  60. // 'page callback' => 'perfart_update_cer',
  61. // 'access callback' => TRUE,
  62. // 'file' => 'perfart.pages.inc',
  63. // 'page arguments' => array(2),
  64. // );
  65. return $items;
  66. }
  67. /**
  68. * Implements hook_ctools_plugin_directory -
  69. * This lets ctools know to scan my module for a content_type plugin file
  70. * Detailed docks in ctools/ctools.api.php
  71. */
  72. function perfart_ctools_plugin_directory($owner, $plugin_type) {
  73. // we'll be nice and limit scandir() calls
  74. if ($owner == 'ctools' && $plugin_type == 'content_types') {
  75. return 'plugins/content_types';
  76. }
  77. }
  78. /**
  79. * Implements hook_entity_info_alter().
  80. */
  81. function perfart_entity_info_alter(&$entity_info) {
  82. // Set the controller class for nodes to an alternate implementation of the
  83. // DrupalEntityController interface.
  84. // dsm($entity_info, '$entity_info');
  85. $entity_info['node']['view modes']['short_infos'] = array(
  86. 'label' => t('Short infos'),
  87. 'custom settings' => TRUE,
  88. );
  89. $entity_info['node']['view modes']['views_table_cel'] = array(
  90. 'label' => t('Views table cel'),
  91. 'custom settings' => TRUE,
  92. );
  93. $entity_info['node']['view modes']['gridready'] = array(
  94. 'label' => t('Grid ready (timeline)'),
  95. 'custom settings' => TRUE,
  96. );
  97. }
  98. /**
  99. * Implements hook_preprocess_node().
  100. */
  101. function perfart_preprocess_node(&$vars) {
  102. // dsm($vars, '$vars node');
  103. // if($vars['view_mode'] == 'short_infos') {
  104. // $vars['theme_hook_suggestions'][] = 'node__short_infos';
  105. // $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__short_infos';
  106. // }
  107. // if($vars['view_mode'] == 'views_table_cel') {
  108. // $vars['theme_hook_suggestions'][] = 'node__cel';
  109. // $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__cel';
  110. // }
  111. $vars['theme_hook_suggestions'][] = 'node__'.$vars['view_mode'];
  112. $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
  113. }
  114. function perfart_preprocess_field(&$vars) {
  115. // dsm($vars, '$vars field');
  116. $vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#view_mode'];
  117. $vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_type'] . '__' . $vars['element']['#view_mode'];
  118. $vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_name'] . '__' . $vars['element']['#view_mode'];
  119. }
  120. /**
  121. * Implements hook_theme().
  122. */
  123. function perfart_theme($existing, $type, $theme, $path) {
  124. $items = array();
  125. $path = drupal_get_path('module', 'perfart') .'/templates';
  126. $items['node__document__short_infos'] = array(
  127. 'render element' => 'form',
  128. 'path' => $path,
  129. 'template' => 'node--document--short_infos',
  130. // 'preprocess functions' => array(
  131. // 'rubik_preprocess_form_confirm'
  132. // ),
  133. );
  134. $items['node__document__cel'] = array(
  135. 'render element' => 'form',
  136. 'path' => $path,
  137. 'template' => 'node--document--cel',
  138. );
  139. /*
  140. TODO themable timeline item content
  141. */
  142. // $items['timeline__item_content'] = array(
  143. // 'render element' => 'form',
  144. // 'path' => $path,
  145. // 'template' => 'timeline--item-content',
  146. // );
  147. // $items['perfart_performances'] = array(
  148. // 'path' => $path,
  149. // 'template' => 'perfart-performances',
  150. // );
  151. return $items;
  152. }
  153. /**
  154. * Implements hook_init().
  155. */
  156. function perfart_init() {
  157. $query = new EffectuationEntityFieldQuery;
  158. $count = $query->count()->execute();
  159. $pages = ceil($count / PERFART_ELMTS_BY_PAGE);
  160. // drupal_set_message("pages : ".$pages);
  161. drupal_add_js(array('perfart' => array(
  162. 'effectuations_pages' => $pages,
  163. 'strings'=>array(
  164. 'topologies'=> t('topologies'),
  165. 'places'=> t('places'),
  166. 'peoples' => t('peoples'),
  167. ),
  168. )), 'setting');
  169. }
  170. /**
  171. * Implements hook_menu_get_item_alter().
  172. */
  173. // function perfart_menu_get_item_alter(&$router_item, $path, $original_map){
  174. // dsm($router_item, 'router_item');
  175. // dsm($path, 'path');
  176. // dsm($original_map, 'original_map');
  177. // }
  178. /**
  179. * Implements hook_block_info().
  180. */
  181. function perfart_block_info() {
  182. $blocks = array();
  183. $blocks['perf_prevnext'] = array(
  184. 'info' => t('Performance prev next btns'),
  185. );
  186. return $blocks;
  187. }
  188. /**
  189. * Implements hook_block_view().
  190. */
  191. function perfart_block_view($delta='') {
  192. $block = array();
  193. switch($delta) {
  194. case 'perf_prevnext' :
  195. $block['content'] = perf_prevnext_view();
  196. break;
  197. }
  198. return $block;
  199. }
  200. /**
  201. * Custom function to assemble renderable array for block content.
  202. * Returns a renderable array with the block content.
  203. * @return
  204. * returns a renderable array of block content.
  205. */
  206. function perf_prevnext_view() {
  207. global $language;
  208. // get current perf nid
  209. $current_perf = menu_get_object();
  210. if ($current_perf && $current_perf->nid && $current_perf->type == 'performance') {
  211. // dsm($current_perf);
  212. // You have a valid node to work with.
  213. // get all perfs
  214. $query = new EffectuationEntityFieldQuery;
  215. $result = $query->execute();
  216. $perfs = array();
  217. foreach ($result['node'] as $eff) {
  218. $eff = node_load($eff->nid);
  219. if(!isset($eff->field_date_de_debut) || !isset($eff->field_performances))
  220. continue;
  221. $debut = $eff->field_date_de_debut['und'][0]['value'];
  222. //1969/06/06-18:00
  223. $pattern = '/^(\d{4})\/?(\d{2})?\/?(\d{2})?-?(\d{2})?:?+(\d{2})?$/';
  224. preg_match($pattern, $debut, $debutMatches);
  225. if(!isset($debutMatches[1]))
  226. continue;
  227. $perfadded = array();
  228. foreach ($eff->field_performances['und'] as $perf) {
  229. if(in_array($perf['target_id'], $perfadded))
  230. continue;
  231. $perfadded[] = $perf['target_id'];
  232. $perfs[] = $perf['target_id'];
  233. }
  234. }
  235. // dsm($perfs);
  236. // get prev and next
  237. // build links
  238. $index = array_search($current_perf->nid, $perfs);
  239. // dsm($index);
  240. $list = array();
  241. if($index > 0){
  242. $prev_nid = $perfs[$index-1];
  243. $prev = node_load($prev_nid);
  244. $prev_path = drupal_get_path_alias('node/'.$prev->nid, $language->language);
  245. $prev_link = l('< ' . $prev->title, $prev_path, array('html'=>true));
  246. $list['items'][] = array(
  247. 'data' => $prev_link,
  248. 'class' => array('perf-prev-link'),
  249. );
  250. }
  251. if ($index < count($perfs)-1) {
  252. $next_nid = $perfs[$index+1];
  253. $next = node_load($next_nid);
  254. $next_path = drupal_get_path_alias('node/'.$next->nid, $language->language);
  255. $next_link = l($next->title . ' >', $next_path, array('html'=>true));
  256. $list['items'][] = array(
  257. 'data' => $next_link,
  258. 'class' => array('perf-next-link'),
  259. );
  260. }
  261. $list['attributes']['id'] = "perf-prev-next-btns";
  262. // dsm($list);
  263. return theme('item_list', $list);
  264. }
  265. return null;
  266. }