123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329 |
- <?php
- /**
- * @file
- * This is the file description for Perfart module.
- *
- * In this more verbose, multi-line description, you can specify what this
- * file does exactly. Make sure to wrap your documentation in column 78 so
- * that the file can be displayed nicely in default-sized consoles.
- */
- define('PERFART_ELMTS_BY_PAGE', 100);
- /**
- * Implements hook_menu().
- */
- function perfart_menu() {
- $items = array();
- $base = array(
- 'access arguments' => array('access content'),
- 'type' => MENU_CALLBACK,
- 'file' => 'perfart.pages.inc',
- );
- $items['perfart/ajax/dates'] = $base+array(
- 'title' => 'List of dates',
- 'page callback' => 'perfart_get_dates',
- 'page arguments' => array(3),
- );
- $items['perfart/ajax/perf'] = $base+array(
- 'title' => 'content of one perf',
- 'page callback' => 'perfart_get_perf',
- 'page arguments' => array(3),
- );
- $items['perfart/ajax/home'] = $base+array(
- 'title' => 'content of home page',
- 'page callback' => 'perfart_get_home',
- 'page arguments' => array(),
- );
- $items['perfart/performances'] = $base+array(
- 'title' => 'List of performances',
- 'page callback' => 'perfart_get_performances',
- 'page arguments' => array(),
- );
- $items['perfart/search'] = $base+array(
- 'title' => 'search performances',
- 'page callback' => 'perfart_search',
- 'page arguments' => array(),
- );
- $items['perfart/search_api'] = $base+array(
- 'title' => 'search performances (through search_api)',
- 'page callback' => 'perfart_search_api',
- 'page arguments' => array(),
- );
- // $items['perfart/ajax/filters'] = array(
- // 'title' => 'List of filters blocks (taxonomy terms)',
- // 'page callback' => 'perfart_get_filters',
- // 'access callback' => TRUE,
- // 'file' => 'perfart.pages.inc',
- // 'page arguments' => array(),
- // );
- // $items['perfart/update_cer'] = array(
- // 'title' => 'Updating Corresponding entity reference',
- // 'page callback' => 'perfart_update_cer',
- // 'access callback' => TRUE,
- // 'file' => 'perfart.pages.inc',
- // 'page arguments' => array(2),
- // );
- return $items;
- }
- /**
- * Implements hook_ctools_plugin_directory -
- * This lets ctools know to scan my module for a content_type plugin file
- * Detailed docks in ctools/ctools.api.php
- */
- function perfart_ctools_plugin_directory($owner, $plugin_type) {
- // we'll be nice and limit scandir() calls
- if ($owner == 'ctools' && $plugin_type == 'content_types') {
- return 'plugins/content_types';
- }
- }
- /**
- * Implements hook_entity_info_alter().
- */
- function perfart_entity_info_alter(&$entity_info) {
- // Set the controller class for nodes to an alternate implementation of the
- // DrupalEntityController interface.
-
- // dsm($entity_info, '$entity_info');
- $entity_info['node']['view modes']['short_infos'] = array(
- 'label' => t('Short infos'),
- 'custom settings' => TRUE,
- );
- $entity_info['node']['view modes']['views_table_cel'] = array(
- 'label' => t('Views table cel'),
- 'custom settings' => TRUE,
- );
- $entity_info['node']['view modes']['gridready'] = array(
- 'label' => t('Grid ready (timeline)'),
- 'custom settings' => TRUE,
- );
- }
- /**
- * Implements hook_preprocess_node().
- */
- function perfart_preprocess_node(&$vars) {
- // dsm($vars, '$vars node');
- // if($vars['view_mode'] == 'short_infos') {
- // $vars['theme_hook_suggestions'][] = 'node__short_infos';
- // $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__short_infos';
- // }
- // if($vars['view_mode'] == 'views_table_cel') {
- // $vars['theme_hook_suggestions'][] = 'node__cel';
- // $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__cel';
- // }
- $vars['theme_hook_suggestions'][] = 'node__'.$vars['view_mode'];
- $vars['theme_hook_suggestions'][] = 'node__' . $vars['type'] . '__' . $vars['view_mode'];
- }
- function perfart_preprocess_field(&$vars) {
- // dsm($vars, '$vars field');
- $vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#view_mode'];
- $vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_type'] . '__' . $vars['element']['#view_mode'];
- $vars['theme_hook_suggestions'][] = 'field__' . $vars['element']['#field_name'] . '__' . $vars['element']['#view_mode'];
- }
- /**
- * Implements hook_theme().
- */
- function perfart_theme($existing, $type, $theme, $path) {
- $items = array();
- $path = drupal_get_path('module', 'perfart') .'/templates';
-
- $items['node__document__short_infos'] = array(
- 'render element' => 'form',
- 'path' => $path,
- 'template' => 'node--document--short_infos',
- // 'preprocess functions' => array(
- // 'rubik_preprocess_form_confirm'
- // ),
- );
- $items['node__document__cel'] = array(
- 'render element' => 'form',
- 'path' => $path,
- 'template' => 'node--document--cel',
- );
-
- /*
- TODO themable timeline item content
- */
- // $items['timeline__item_content'] = array(
- // 'render element' => 'form',
- // 'path' => $path,
- // 'template' => 'timeline--item-content',
- // );
-
- // $items['perfart_performances'] = array(
- // 'path' => $path,
- // 'template' => 'perfart-performances',
- // );
- return $items;
- }
- /**
- * Implements hook_init().
- */
- function perfart_init() {
- $query = new EffectuationEntityFieldQuery;
- $count = $query->count()->execute();
-
- $pages = ceil($count / PERFART_ELMTS_BY_PAGE);
-
- // drupal_set_message("pages : ".$pages);
-
- drupal_add_js(array('perfart' => array(
- 'effectuations_pages' => $pages,
- 'strings'=>array(
- 'topologies'=> t('topologies'),
- 'places'=> t('places'),
- 'peoples' => t('peoples'),
- ),
- )), 'setting');
- }
- /**
- * Implements hook_menu_get_item_alter().
- */
- // function perfart_menu_get_item_alter(&$router_item, $path, $original_map){
- // dsm($router_item, 'router_item');
- // dsm($path, 'path');
- // dsm($original_map, 'original_map');
- // }
- /**
- * Implements hook_block_info().
- */
- function perfart_block_info() {
- $blocks = array();
- $blocks['perf_prevnext'] = array(
- 'info' => t('Performance prev next btns'),
- );
- $blocks['perf_prevnext_bottom'] = array(
- 'info' => t('Performance prev next btns bottom'),
- );
-
- return $blocks;
- }
- /**
- * Implements hook_block_view().
- */
- function perfart_block_view($delta='') {
- $block = array();
-
- switch($delta) {
- case 'perf_prevnext' :
- $block['content'] = perf_prevnext_view();
- break;
- case 'perf_prevnext_bottom' :
- $block['content'] = perf_prevnext_view();
- break;
- }
-
- return $block;
- }
- /**
- * Custom function to assemble renderable array for block content.
- * Returns a renderable array with the block content.
- * @return
- * returns a renderable array of block content.
- */
- function perf_prevnext_view() {
- global $language;
-
- // get current perf nid
- $current_perf = menu_get_object();
- if ($current_perf && $current_perf->nid && $current_perf->type == 'performance') {
- // dsm($current_perf);
- // You have a valid node to work with.
- // get all perfs
-
- $query = new EffectuationEntityFieldQuery;
- $result = $query->execute();
- $perfs = array();
- foreach ($result['node'] as $eff) {
- $eff = node_load($eff->nid);
-
- if(!isset($eff->field_date_de_debut) || !isset($eff->field_performances))
- continue;
- $debut = $eff->field_date_de_debut['und'][0]['value'];
- //1969/06/06-18:00
- $pattern = '/^(\d{4})\/?(\d{2})?\/?(\d{2})?-?(\d{2})?:?+(\d{2})?$/';
- preg_match($pattern, $debut, $debutMatches);
- if(!isset($debutMatches[1]))
- continue;
- $perfadded = array();
- foreach ($eff->field_performances['und'] as $perf) {
-
- if(in_array($perf['target_id'], $perfadded))
- continue;
-
- $perfadded[] = $perf['target_id'];
- $perfs[] = $perf['target_id'];
- }
- }
- // dsm($perfs);
- // get prev and next
- // build links
- $index = array_search($current_perf->nid, $perfs);
- // dsm($index);
- $list = array();
- if($index > 0){
- $prev_nid = $perfs[$index-1];
- $prev = node_load($prev_nid);
- $prev_path = drupal_get_path_alias('node/'.$prev->nid, $language->language);
- $prev_link = l('< ' . $prev->title, $prev_path, array('html'=>true));
- $list['items'][] = array(
- 'data' => $prev_link,
- 'class' => array('perf-prev-link'),
- );
- }
- if ($index < count($perfs)-1) {
- $next_nid = $perfs[$index+1];
- $next = node_load($next_nid);
- $next_path = drupal_get_path_alias('node/'.$next->nid, $language->language);
- $next_link = l($next->title . ' >', $next_path, array('html'=>true));
- $list['items'][] = array(
- 'data' => $next_link,
- 'class' => array('perf-next-link'),
- );
-
- }
- $list['attributes']['class'] = "perf-prev-next-btns";
- // dsm($list);
- return theme('item_list', $list);
- }
- return null;
- }
|