perfart.pages.inc 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <?php
  2. /**
  3. * perfart_get_dates()
  4. *
  5. */
  6. function perfart_get_dates($page = 0, $debug = false){
  7. // dsm($page, '$page');
  8. global $language;
  9. // dsm($language, '$language : '.$language->language);
  10. $query = new EffectuationEntityFieldQuery;
  11. $query
  12. ->range(PERFART_ELMTS_BY_PAGE*$page, PERFART_ELMTS_BY_PAGE);
  13. // ->pager(10, $page);
  14. // ->propertyOrderBy('created', 'DESC');
  15. $result = $query->execute();
  16. // dsm($result, '$result');
  17. $data = array();
  18. foreach ($result['node'] as $eff) {
  19. $eff = node_load($eff->nid);
  20. //$eff = entity_load('node', array($eff->nid), NULL, FALSE);
  21. // dsm($eff, '$eff');
  22. # dates
  23. if(!isset($eff->field_date_de_debut) || !isset($eff->field_performances))
  24. continue;
  25. $debut = $eff->field_date_de_debut['und'][0]['value'];
  26. //1969/06/06-18:00
  27. $pattern = '/^(\d{4})\/?(\d{2})?\/?(\d{2})?-?(\d{2})?:?+(\d{2})?$/';
  28. preg_match($pattern, $debut, $debutMatches);
  29. if(!isset($debutMatches[1]))
  30. continue;
  31. if(isset($eff->field_date_de_fin['und'])){
  32. $fin = $eff->field_date_de_fin['und'][0]['value'];
  33. preg_match($pattern, $fin, $finMatches);
  34. }else{
  35. $fin = false;
  36. }
  37. # lieu
  38. $lieu_values = field_get_items('node',$eff,'field_lieu');
  39. $lieu_values = $lieu_values ? $lieu_values : array();
  40. // dsm($lieu_values, '$lieu_values');
  41. $lieu = array();
  42. foreach ($lieu_values as $value) {
  43. $term = taxonomy_term_load($value['tid']);
  44. if(!$term) continue;
  45. $term = i18n_taxonomy_localize_terms($term);
  46. // dsm($term, '$term');
  47. $lieu[$term->tid] = array(
  48. 'tid' => $term->tid,
  49. 'name' => t($term->name),
  50. );
  51. }
  52. # topologie
  53. $topologie_values = field_get_items('node',$eff,'field_topologie');
  54. // dsm($topologie_values, '$topologie_values');
  55. $topologies = array();
  56. if($topologie_values){
  57. foreach ($topologie_values as $value) {
  58. $term = taxonomy_term_load($value['tid']);
  59. if(!$term) continue;
  60. $term = i18n_taxonomy_localize_terms($term);
  61. $topologies[$term->tid] = array(
  62. 'tid' => $term->tid,
  63. 'name' => $term->name,
  64. );
  65. }
  66. }
  67. $perfadded = array();
  68. foreach ($eff->field_performances['und'] as $perf) {
  69. if(in_array($perf['target_id'], $perfadded))
  70. continue;
  71. $perfadded[] = $perf['target_id'];
  72. $perf = node_load($perf['target_id']);
  73. // $perf = entity_load('node', array($perf['target_id']), NULL, FALSE);
  74. // dsm($perf, '$perf');
  75. $prefix = $language->language == 'fr' ? 'en/' : '';
  76. $date = array(
  77. "nid"=>$perf->nid,
  78. "filters" => array(),
  79. 'ajax_link'=> 'perfart/ajax/perf/'.$perf->nid,
  80. 'node_link'=> drupal_get_path_alias('node/'.$perf->nid, $language->language),
  81. 'node_translation'=> $prefix . drupal_get_path_alias('node/'.$perf->nid, $language->language == 'fr' ? 'en' : 'fr'),
  82. 'perf_title'=>$perf->title,
  83. 'language'=>$language,
  84. );
  85. #images
  86. if($images_values= field_get_items('node',$perf,'field_images')){
  87. //dsm($images_values, '$images_values');
  88. $image = theme('image_style', array(
  89. 'style_name'=>'timeline_thumbnail',
  90. 'path'=>$images_values[0]['uri'],
  91. ));
  92. //$content .= $image;
  93. // dsm($image, 'image');
  94. $date['thumb'] = $image;
  95. }
  96. # timeline content + concepteurs filter
  97. $content = '<div href="perfart/ajax/perf/'.$perf->nid.'" class="date" nid="'.$perf->nid.'" >';//thumb="'.$date['thumb'].'"
  98. $content .= '<div class="text-content">';
  99. $content .= '<h4>'.$perf->title.'</h4>';
  100. #concepteur
  101. $concepteurs_values= field_get_items('node',$perf,'field_concepteur');
  102. $personnes = array();
  103. if($concepteurs_values){
  104. $concepteurs = array();
  105. foreach ($concepteurs_values as $concepteur) {
  106. $concepteur_term = taxonomy_term_load($concepteur['tid']);
  107. if(!$concepteur_term) continue;
  108. // dsm($concepteur_term);
  109. $field_nom_values = field_get_items('taxonomy_term', $concepteur_term , 'field_nom');
  110. $field_prenom_values = field_get_items('taxonomy_term', $concepteur_term, 'field_prenom');
  111. $concepteurs[] = $concepteur_term->name;
  112. $personnes[$concepteur_term->tid] = array(
  113. "tid" => $concepteur_term->tid,
  114. "name" => $concepteur_term->name,
  115. "nom" => $field_nom_values[0]['value'],
  116. "prenom" => $field_prenom_values[0]['value'],
  117. );
  118. }
  119. $content .= '<h5>'.implode(', ', $concepteurs).'</h5>';
  120. }
  121. $content .= '</div>';
  122. ## close content link
  123. $content .= '</div>';
  124. # timeline array with dates
  125. $date += array(
  126. 'content'=> $content,
  127. 'start'=>array(
  128. 'year'=>$debutMatches[1],
  129. 'month'=>isset($debutMatches[2]) ? $debutMatches[2] : null,
  130. 'day'=>isset($debutMatches[3]) ? $debutMatches[3] : null,
  131. ),
  132. );
  133. if($fin && false) // deactivated end date because ranges cause display probleme on the timeline
  134. $date['end'] = array(
  135. 'year'=>isset($finMatches[1]) ? $finMatches[1] : null,
  136. 'month'=>isset($finMatches[2]) ? $finMatches[2] : null,
  137. 'day'=>isset($finMatches[3]) ? $finMatches[3] : null,
  138. );
  139. # filter organisateur
  140. $organisateur_values= field_get_items('node',$perf,'field_organisateur');
  141. // dsm($organisateur_values, 'org');
  142. if($organisateur_values){
  143. foreach ($organisateur_values as $personne) {
  144. $term = taxonomy_term_load($personne['tid']);
  145. if(!$term) continue;
  146. // dsm($term);
  147. $field_nom_values = field_get_items('taxonomy_term', $term , 'field_nom');
  148. $field_prenom_values = field_get_items('taxonomy_term', $term, 'field_prenom');
  149. $personnes[$term->tid] = array(
  150. "tid" => $term->tid,
  151. "name" => $term->name,
  152. "nom" => $field_nom_values[0]['value'],
  153. "prenom" => $field_prenom_values[0]['value'],
  154. );
  155. }
  156. }
  157. # filter participants
  158. $participants_values= field_get_items('node',$perf,'field_participant');
  159. // dsm(count($participants_values), 'part');
  160. if($participants_values){
  161. foreach ($participants_values as $personne) {
  162. $term = taxonomy_term_load($personne['tid']);
  163. if(!$term) continue;
  164. // dsm($term);
  165. $field_nom_values = field_get_items('taxonomy_term', $term , 'field_nom');
  166. $field_prenom_values = field_get_items('taxonomy_term', $term, 'field_prenom');
  167. $personnes[$term->tid] = array(
  168. "tid" => $term->tid,
  169. "name" => $term->name,
  170. "nom" => $field_nom_values[0]['value'],
  171. "prenom" => $field_prenom_values[0]['value'],
  172. );
  173. }
  174. }
  175. # filter topologie flag
  176. $date["filters"]['topologies'] = $topologies;
  177. # filter lieu flag
  178. $date['filters']['places'] = $lieu;
  179. # filter artistes
  180. $date['filters']['peoples'] = $personnes;
  181. $data[] = $date;
  182. }
  183. }
  184. // if($debug){
  185. // dsm($data, '$data');
  186. // return t('perfart_get_dates debug mode');
  187. // }else{
  188. drupal_json_output($data);
  189. // }
  190. }
  191. /**
  192. * perfart_get_perf()
  193. * home page classical (no-js)
  194. *
  195. */
  196. function perfart_get_performances(){
  197. // dsm($page, '$page');
  198. global $language;
  199. // dsm($language, '$language : '.$language->language);
  200. $limit = 100;//variable_get($viewmode.'_limite', '10');
  201. $offset = pager_find_page() * $limit;
  202. $query = new EffectuationEntityFieldQuery;
  203. $query
  204. ->range($offset,$limit);
  205. // ->pager(10, $page);
  206. // ->propertyOrderBy('created', 'DESC');
  207. $result = $query->execute();
  208. // dsm($result, '$result');
  209. $count_query = new EffectuationEntityFieldQuery;
  210. $count = $count_query->count()->execute();
  211. pager_default_initialize($count, $limit);
  212. $data = array();
  213. foreach ($result['node'] as $eff) {
  214. $eff = node_load($eff->nid);
  215. //$eff = entity_load('node', array($eff->nid), NULL, FALSE);
  216. // dsm($eff, '$eff');
  217. # dates
  218. if(!isset($eff->field_date_de_debut) || !isset($eff->field_performances))
  219. continue;
  220. $debut = $eff->field_date_de_debut['und'][0]['value'];
  221. //1969/06/06-18:00
  222. $pattern = '/^(\d{4})\/?(\d{2})?\/?(\d{2})?-?(\d{2})?:?+(\d{2})?$/';
  223. preg_match($pattern, $debut, $debutMatches);
  224. if(!isset($debutMatches[1]))
  225. continue;
  226. if(isset($eff->field_date_de_fin['und'])){
  227. $fin = $eff->field_date_de_fin['und'][0]['value'];
  228. preg_match($pattern, $fin, $finMatches);
  229. }else{
  230. $fin = false;
  231. }
  232. # lieu
  233. // $lieu_values = field_get_items('node',$eff,'field_lieu');
  234. // $lieu_values = $lieu_values ? $lieu_values : array();
  235. // // dsm($lieu_values, '$lieu_values');
  236. // $lieu = array();
  237. // foreach ($lieu_values as $value) {
  238. // $term = taxonomy_term_load($value['tid']);
  239. // $term = i18n_taxonomy_localize_terms($term);
  240. // // dsm($term, '$term');
  241. // $lieu[$term->tid] = array(
  242. // 'tid' => $term->tid,
  243. // 'name' => t($term->name),
  244. // );
  245. // }
  246. # topologie
  247. // $topologie_values = field_get_items('node',$eff,'field_topologie');
  248. // // dsm($topologie_values, '$topologie_values');
  249. // $topologies = array();
  250. // if($topologie_values){
  251. // foreach ($topologie_values as $value) {
  252. // $term = taxonomy_term_load($value['tid']);
  253. // $term = i18n_taxonomy_localize_terms($term);
  254. // $topologies[$term->tid] = array(
  255. // 'tid' => $term->tid,
  256. // 'name' => $term->name,
  257. // );
  258. // }
  259. // }
  260. $perfadded = array();
  261. foreach ($eff->field_performances['und'] as $perf) {
  262. if(in_array($perf['target_id'], $perfadded))
  263. continue;
  264. $perfadded[] = $perf['target_id'];
  265. $perf = node_load($perf['target_id']);
  266. // $perf = entity_load('node', array($perf['target_id']), NULL, FALSE);
  267. // dsm($perf, '$perf');
  268. // $prefix = $language->language == 'fr' ? 'en/' : '';
  269. // $date = array(
  270. // "nid"=>$perf->nid,
  271. // "filters" => array(),
  272. // 'ajax_link'=> 'perfart/ajax/perf/'.$perf->nid,
  273. // 'node_link'=> drupal_get_path_alias('node/'.$perf->nid, $language->language),
  274. // 'node_translation'=> $prefix . drupal_get_path_alias('node/'.$perf->nid, $language->language == 'fr' ? 'en' : 'fr'),
  275. // 'perf_title'=>$perf->title,
  276. // 'language'=>$language,
  277. // );
  278. $node_path = drupal_get_path_alias('node/'.$perf->nid, $language->language);
  279. $node_link = l($debutMatches[1] .' | '. $perf->title,$node_path, array('html'=>true));
  280. # timeline content + concepteurs filter
  281. $content = '<div class="date" nid="'.$perf->nid.'" >';
  282. // $content .= '<div class="text-content">';
  283. $content .= '<h4>'.$node_link.'</h4>';
  284. #concepteur
  285. $concepteurs_values= field_get_items('node',$perf,'field_concepteur');
  286. $personnes = array();
  287. if($concepteurs_values){
  288. $concepteurs = array();
  289. foreach ($concepteurs_values as $concepteur) {
  290. // $concepteur_term = taxonomy_term_load($concepteur['tid']);
  291. try {
  292. $concepteur_term = taxonomy_term_load($concepteur['tid']);
  293. } catch (Exception $e) {
  294. throw new Exception( 'taxonomy_term_load didn\'t', 0, $e);
  295. continue;
  296. }
  297. // dsm($concepteur_term);
  298. $concepteurs[] = $concepteur_term->name;
  299. // $personnes[$concepteur_term->tid] = array(
  300. // "tid" => $concepteur_term->tid,
  301. // "name" => $concepteur_term->name,
  302. // );
  303. }
  304. $content .= '<h5>'.implode(', ', $concepteurs).'</h5>';
  305. }
  306. #images
  307. if($images_values= field_get_items('node',$perf,'field_images')){
  308. //dsm($images_values, '$images_values');
  309. $image = theme('image_style', array(
  310. 'style_name'=>'home_no_js',
  311. 'path'=>$images_values[0]['uri'],
  312. ));
  313. //$content .= $image;
  314. // dsm($image, 'image');
  315. $date['thumb'] = l($image, $node_path, array('html'=>true));
  316. $content .= $date['thumb'];
  317. }
  318. // $content .= '</div>';
  319. ## close content link
  320. $content .= '</div>';
  321. # timeline array with dates
  322. // $date += array(
  323. // 'content'=> $content,
  324. // 'start'=>array(
  325. // 'year'=>$debutMatches[1],
  326. // 'month'=>isset($debutMatches[2]) ? $debutMatches[2] : null,
  327. // 'day'=>isset($debutMatches[3]) ? $debutMatches[3] : null,
  328. // ),
  329. // );
  330. # filter organisateur
  331. // $organisateur_values= field_get_items('node',$perf,'field_organisateur');
  332. // // dsm($organisateur_values, 'org');
  333. // if($organisateur_values){
  334. // foreach ($organisateur_values as $personne) {
  335. // $term = taxonomy_term_load($personne['tid']);
  336. // // dsm($term);
  337. // $personnes[$term->tid] = array(
  338. // "tid" => $term->tid,
  339. // "name" => $term->name,
  340. // );
  341. // }
  342. // }
  343. # filter participants
  344. // $participants_values= field_get_items('node',$perf,'field_participant');
  345. // // dsm(count($participants_values), 'part');
  346. // if($participants_values){
  347. // foreach ($participants_values as $personne) {
  348. // $term = taxonomy_term_load($personne['tid']);
  349. // // dsm($term);
  350. // $personnes[$term->tid] = array(
  351. // "tid" => $term->tid,
  352. // "name" => $term->name,
  353. // );
  354. // }
  355. // }
  356. # filter topologie flag
  357. // $date["filters"]['topologies'] = $topologies;
  358. # filter lieu flag
  359. // $date['filters']['places'] = $lieu;
  360. # filter artistes
  361. // $date['filters']['peoples'] = $personnes;
  362. pager_default_initialize($count, $limit);
  363. // $data[] = $date;
  364. $list['items'][] = $content;
  365. }
  366. }
  367. // dsm($data, '$data');
  368. return theme('item_list', $list) . theme('pager');
  369. }
  370. /**
  371. * perfart_search()
  372. * ajax search
  373. *
  374. */
  375. function perfart_search(){
  376. $keys = rawurldecode($_GET['keys']);
  377. $return = array('keys' => $keys);
  378. $module = 'node';
  379. if (!empty($module)) {
  380. $active_module_info = search_get_info();
  381. if (isset($active_module_info[$module])) {
  382. $info = $active_module_info[$module];
  383. }
  384. }
  385. $return['info'] = $info;
  386. // $results = search_data($keys, $info['module'], $conditions);
  387. if($results = search_data($keys, $info['module'])){
  388. foreach ($results['#results'] as $result) {
  389. $return['results'][] = $result['node']->nid;
  390. }
  391. }
  392. drupal_json_output($return);
  393. }
  394. /**
  395. * perfart_search_api()
  396. * ajax search_api
  397. *
  398. */
  399. function perfart_search_api(){
  400. $typed = rawurldecode($_GET['typed']);
  401. preg_match_all('/\s?[^\s]+\s?/', $typed, $words);
  402. // dsm($words, "words");
  403. foreach ($words[0] as $word) {
  404. // dsm($word);
  405. $word = trim($word);
  406. // $word = str_replace($match, $replace, $word);
  407. // dsm($word, 'word');
  408. $keys[] = $word;
  409. }
  410. // dsm($keys, 'keys');
  411. global $language;
  412. $return = array('keys' => $keys);
  413. $index_machine_name = $language->language == 'fr' ? 'performances_fr' : 'performance_en';
  414. $index = search_api_index_load($index_machine_name);
  415. if ($keys) {
  416. $query = search_api_query($index_machine_name, array('conjunction'=>'OR', 'parse mode'=>'direct'))->keys(implode(' ', $keys));
  417. $results = $query->execute();
  418. $return['results'] = $index->loadItems(array_keys($results['results']));
  419. }
  420. drupal_json_output($return);
  421. }
  422. /**
  423. * perfart_get_perf()
  424. * get one perf through ajax
  425. *
  426. */
  427. function perfart_get_perf($nid = false){
  428. if($nid){
  429. global $language;
  430. //dsm($language, 'language');
  431. $node = node_load($nid);
  432. // dsm($node, '$node');
  433. $node_view = node_view($node, "gridready", $language->language);
  434. // dsm($node_view, '$node_view');
  435. $response = array(
  436. "node_view"=>render($node_view),
  437. "nid"=>$nid,
  438. );
  439. // dsm($response, '$response');
  440. // return 'debug mode of perfart_get_perf()';
  441. drupal_json_output($response);
  442. }else{
  443. return false;
  444. }
  445. }
  446. /**
  447. *
  448. * perfart_get_home()
  449. *
  450. */
  451. function perfart_get_home(){
  452. $return = array();
  453. global $language;
  454. $return['language'] = $language;
  455. $front = node_view(node_load(1), 'full', $language->language);
  456. // dsm($front, 'front');
  457. $frontrendered = drupal_render($front);
  458. $return['front'] = $frontrendered;
  459. // dsm($frontrendered, '$frontrendered');
  460. // return 'debug mode of perfart_get_home()';
  461. drupal_json_output($return);
  462. }
  463. /**
  464. * DEV
  465. *
  466. */
  467. function perfart_update_cer($page = 0){
  468. $itemsbypage = 100;
  469. $query = new EntityFieldQuery;
  470. $query
  471. ->entityCondition('entity_type', 'node')
  472. ->entityCondition('bundle', array('performance'))
  473. ->fieldCondition('field_effectuations', 'target_id', 'NULL', '!=')
  474. ->range($page*$itemsbypage, $itemsbypage);
  475. // ->propertyCondition('status', 1)
  476. // ->pager(100, 1);
  477. // ->propertyOrderBy('created', 'DESC');
  478. $result = $query->execute();
  479. //
  480. $delta = 0;
  481. if(count($result['node'])){
  482. foreach ($result['node'] as $nid => $node) {
  483. $node = node_load($nid);
  484. // dsm($node);
  485. // // module_invoke_all('entity_update', $node, 'node');
  486. corresponding_entity_references_processing_entity('update', $node, 'node');
  487. // node_save($node);
  488. $delta++;
  489. }
  490. }
  491. // dsm($delta);
  492. return $delta." nodes where updated.";
  493. }
  494. function perfart_clear_effectuations_perf_ref($page = 0){
  495. $itemsbypage = 100;
  496. $query = new EntityFieldQuery;
  497. $query
  498. ->entityCondition('entity_type', 'node')
  499. ->entityCondition('bundle', array('effectuation'))
  500. ->fieldCondition('field_performances', 'target_id', 'NULL', '!=')
  501. ->range($page*$itemsbypage, $itemsbypage);
  502. // ->propertyCondition('status', 1)
  503. // ->pager(100, 1);
  504. // ->propertyOrderBy('created', 'DESC');
  505. $result = $query->execute();
  506. //
  507. $delta = 0;
  508. if(count($result['node'])){
  509. foreach ($result['node'] as $nid => $node) {
  510. $node = node_load($nid);
  511. // dsm($node);
  512. $node->field_performances = NULL;
  513. // // module_invoke_all('entity_update', $node, 'node');
  514. // corresponding_entity_references_processing_entity('update', $node, 'node');
  515. node_save($node);
  516. $delta++;
  517. }
  518. }
  519. // dsm($delta);
  520. return $delta." nodes where updated.";
  521. }