fullcalendar.views.inc

Tracking 7.x-2.x branch
  1. drupal
    1. 7 contributions/fullcalendar/includes/views/fullcalendar.views.inc

Contains Views module hooks.

Functions & methods

NameDescription
fullcalendar_views_ajax_data_alterImplements hook_views_ajax_data_alter().
fullcalendar_views_dataImplements hook_views_data().
fullcalendar_views_pluginsImplements hook_views_plugins().
fullcalendar_views_plugins_alterImplements hook_views_plugins_alter().
fullcalendar_views_pre_viewImplements hook_views_pre_view().
fullcalendar_views_query_alterImplements hook_views_query_alter().

File

View source
  1. <?php
  2. /**
  3. * @file
  4. * Contains Views module hooks.
  5. */
  6. /**
  7. * Implements hook_views_plugins().
  8. */
  9. function fullcalendar_views_plugins() {
  10. $path = drupal_get_path('module', 'fullcalendar');
  11. return array(
  12. 'module' => 'fullcalendar',
  13. 'style' => array(
  14. 'fullcalendar' => array(
  15. 'title' => t('FullCalendar'),
  16. 'help' => t('Displays items on a calendar.'),
  17. 'handler' => 'fullcalendar_plugin_style_fullcalendar',
  18. 'path' => $path . '/includes/views/plugins',
  19. 'theme' => 'fullcalendar',
  20. 'theme file' => 'theme.inc',
  21. 'theme path' => $path . '/theme',
  22. 'uses row plugin' => FALSE,
  23. 'uses fields' => TRUE,
  24. 'uses options' => TRUE,
  25. 'uses grouping' => TRUE,
  26. 'even empty' => TRUE,
  27. 'type' => 'normal',
  28. ),
  29. ),
  30. );
  31. }
  32. /**
  33. * Implements hook_views_plugins_alter().
  34. */
  35. function fullcalendar_views_plugins_alter(&$plugins) {
  36. $plugins['display']['fullcalendar'] = array(
  37. 'title' => t('FullCalendar - Deprecated, use page display instead!'),
  38. 'help' => t('Stop using this display, use page instead'),
  39. 'no ui' => TRUE,
  40. ) + $plugins['display']['page'];
  41. }
  42. /**
  43. * Implements hook_views_data().
  44. */
  45. function fullcalendar_views_data() {
  46. $data = array();
  47. $data['fullcalendar'] = array(
  48. 'table' => array(
  49. 'group' => t('FullCalendar'),
  50. 'join' => array('#global' => array()),
  51. ),
  52. 'gcal' => array(
  53. 'title' => t('Google Calendar'),
  54. 'help' => t('Display events from a Google Calendar.'),
  55. 'field' => array(
  56. 'handler' => 'fullcalendar_handler_field_gcal',
  57. ),
  58. ),
  59. );
  60. return $data;
  61. }
  62. /**
  63. * Implements hook_views_pre_view().
  64. *
  65. * Add an argument that provides the current date for each date field present.
  66. */
  67. function fullcalendar_views_pre_view(&$view, &$display_id, &$args) {
  68. if ($view->display_handler->get_option('style_plugin') != 'fullcalendar') {
  69. return;
  70. }
  71. // Get the current view settings.
  72. $view->init_style();
  73. $settings = $view->style_plugin->options;
  74. fullcalendar_include_api();
  75. $fullcalendar_options = module_invoke_all('fullcalendar_options_info');
  76. uasort($fullcalendar_options, 'drupal_sort_weight');
  77. foreach (array_intersect(array_keys($fullcalendar_options), module_implements('fullcalendar_options_pre_view')) as $module) {
  78. $function = $module . '_fullcalendar_options_pre_view';
  79. $function($settings, $view);
  80. }
  81. $settings['ajax'] = FALSE;
  82. // If we're not using ajax, we're done.
  83. if (!$view->display_handler->get_option('use_ajax')) {
  84. // Set the new view settings.
  85. $view->style_plugin->options = $settings;
  86. return;
  87. }
  88. $settings['fullcalendar_fields_count'] = 0;
  89. $exposed_input = $view->get_exposed_input();
  90. // Loop through each date field and provide an argument for it.
  91. foreach ($view->display_handler->get_handlers('field') as $field_id => $field) {
  92. if (!fullcalendar_field_is_date($field)) {
  93. continue;
  94. }
  95. $settings['ajax'] = TRUE;
  96. // Add an exposed filter for the date field.
  97. $field_value_id = $field->real_field . str_replace($field->field, '', $field_id);
  98. if (isset($exposed_input[$field_value_id])) {
  99. $timestamp = (strtotime($exposed_input[$field_value_id]['min']['date']) + strtotime($exposed_input[$field_value_id]['max']['date'])) / 2;
  100. $min = date('Y-m', $timestamp);
  101. $max = date('Y-m', strtotime($min . ' +1 month'));
  102. }
  103. else {
  104. $min = $settings['date']['year'] . '-' . ($settings['date']['month'] + 1);
  105. $max = $settings['date']['year'] . '-' . ($settings['date']['month'] + 2);
  106. }
  107. $min = date('Y-m-d', strtotime($min . ' -2 weeks'));
  108. $max = date('Y-m-d', strtotime($max . ' +2 weeks'));
  109. $options = array(
  110. 'exposed' => TRUE,
  111. 'form_type' => 'date_text',
  112. 'operator' => 'between',
  113. 'default_date' => $min,
  114. 'default_to_date' => $max,
  115. 'group' => 0,
  116. );
  117. if (!empty($field->options['relationship'])) {
  118. $options['relationship'] = $field->options['relationship'];
  119. }
  120. $option_id = $view->add_item($display_id, 'filter', 'field_data_' . $field->field, $field->field . '_value', $options);
  121. $settings['fullcalendar_fields'][$option_id] = drupal_html_class($option_id);
  122. $settings['fullcalendar_fields_count']++;
  123. $view->set_item_option($display_id, 'filter', $option_id, 'expose', array('identifier' => $option_id, 'operator' => $option_id . '_op'));
  124. }
  125. if (isset($timestamp)) {
  126. $settings['date']['date'] = date('d', $timestamp);
  127. $settings['date']['month'] = date('n', $timestamp) - 1;
  128. $settings['date']['year'] = date('Y', $timestamp);
  129. }
  130. $view->style_plugin->options = $settings;
  131. }
  132. /**
  133. * Implements hook_views_query_alter().
  134. *
  135. * Force the query to be distinct.
  136. */
  137. function fullcalendar_views_query_alter(&$view, &$query) {
  138. if ($view->display_handler->get_option('style_plugin') != 'fullcalendar') {
  139. return;
  140. }
  141. $query->distinct = TRUE;
  142. }
  143. /**
  144. * Implements hook_views_ajax_data_alter().
  145. */
  146. function fullcalendar_views_ajax_data_alter(&$commands, &$view) {
  147. if ($view->display_handler->get_option('style_plugin') == 'fullcalendar') {
  148. $commands = array();
  149. }
  150. }