[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/calendar/includes/ -> calendar_view_plugin_style.inc (source)

   1  <?php
   2  // $Id: calendar_view_plugin_style.inc,v 1.1.2.21 2010/12/28 15:35:50 karens Exp $
   3  
   4  /**
   5   * Style plugin to render the year, month, week, or day calendar view.
   6   */
   7  class calendar_view_plugin_style extends calendar_plugin_style {
   8  
   9    /**
  10     * Init will be called after construct, when the plugin is attached to a
  11     * view and a display. 
  12     */
  13    function init(&$view, &$display, $options = NULL) {
  14      parent::init($view, $display, $options);
  15      $calendar_type = $this->display->handler->get_option('calendar_type');
  16      $view->date_info->style_name_size = $this->options['name_size'];
  17      $view->date_info->style_with_weekno = $this->options['with_weekno'];
  18      $view->date_info->style_multiday_theme = $this->options['multiday_theme'];
  19      $view->date_info->style_theme_style = $this->options['theme_style'];
  20      $view->date_info->style_max_items = $this->options['max_items'];
  21      $view->date_info->style_max_items_behavior = $this->options['max_items_behavior'];
  22      if (!empty($this->options['groupby_times_custom'])) {
  23        $view->date_info->style_groupby_times = explode(',', $this->options['groupby_times_custom']);
  24      }
  25      else {
  26        $view->date_info->style_groupby_times = calendar_groupby_times($this->options['groupby_times']);
  27      }
  28      $view->date_info->style_groupby_field = $this->options['groupby_field'];
  29      
  30      // TODO make this an option setting.
  31      $view->date_info->style_show_empty_times = !empty($this->options['groupby_times_custom']) ? TRUE : FALSE;
  32      
  33      // Make sure views does't try to limit the number of items in this view.
  34      $this->view->pager['items_per_page'] = 0;
  35      
  36    }
  37    
  38    /**
  39     * Set default options
  40     */
  41    function options(&$options) {
  42      $options['name_size'] = 3;
  43      $options['with_weekno'] = 0;
  44      $options['multiday_theme'] = '1';
  45      $options['theme_style'] = '1';
  46      $options['max_items'] = 0;
  47      $options['max_items_behavior'] = 'more';
  48      $options['groupby_times'] = 'hour';
  49      $options['groupby_times_custom'] = '';
  50      $options['groupby_field'] = '';
  51    }
  52  
  53    /**
  54     * Style options.
  55     */
  56    function options_form(&$form, &$form_state) {
  57      $calendar_type = $this->display->handler->get_option('calendar_type');
  58      $form['name_size'] = array(
  59        '#title' => t('Calendar day of week names'),
  60        '#default_value' => $this->options['name_size'],
  61        '#type' => in_array($calendar_type, array('year', 'month', 'week')) ? 'radios' : 'value',
  62        '#options' => array(1 => t('First letter of name'), 2 => t('First two letters of name'), 3 => t('Abbreviated name'), 99 => t('Full name')),
  63        '#description' => t('The way day of week names should be displayed in a calendar.'),
  64        );
  65        
  66      $form['with_weekno'] = array(
  67        '#title' => t('Show week numbers'),
  68        '#default_value' => $this->options['with_weekno'],
  69        '#type' => in_array($calendar_type, array('month')) ? 'radios' : 'value',
  70        '#options' => array(0 => t('No'), 1 => t('Yes')),
  71        '#description' => t('Whether or not to show week numbers in the left column of calendar weeks and months.'),
  72      );
  73      $form['max_items'] = array(
  74        '#title' => t('Maximum items'),
  75        '#type' => in_array($calendar_type, array('month')) ? 'select' : 'value',
  76        '#options' => array(CALENDAR_SHOW_ALL => t('Unlimited'), CALENDAR_HIDE_ALL => t('No items'), 3 => t('3 items'), 5 => t('5 items'), 10 => t('10 items')),
  77        '#default_value' => $calendar_type != 'day' ? $this->options['max_items'] : 0,
  78        '#description' => t('Maximum number of items to show in calendar cells, used to keep the calendar from expanding to a huge size when there are lots of items in one day. '),
  79        );
  80      $form['max_items_behavior'] = array(
  81        '#title' => t('Too many items'),
  82        '#type' => in_array($calendar_type, array('month')) ? 'select' : 'value',
  83        '#options' => array('more' => t("Show maximum, add 'more' link"), 'hide' => t('Hide all, add link to day')),
  84        '#default_value' => $calendar_type != 'day' ? $this->options['max_items_behavior'] : 'more',
  85        '#description' => t('Behavior when there are more than the above number of items in a single day. When there more items than this limit, a link to the day view will be displayed.'),
  86        );
  87      $form['groupby_times'] = array(
  88        '#title' => t('Time grouping'),
  89        '#type' => in_array($calendar_type, array('day', 'week')) ? 'select' : 'value',
  90        '#default_value' => $this->options['groupby_times'],
  91        '#description' => t("Group items together into time periods based on their start time."),
  92        '#options' => array('' => t('None'), 'hour' => t('Hour'), 'half' => t('Half hour'), 'custom' => t('Custom')),
  93        );
  94      $form['groupby_times_custom'] = array(
  95        '#title' => t('Custom time grouping'),
  96        '#type' => in_array($calendar_type, array('day', 'week')) ? 'textarea' : 'value',
  97        '#default_value' => $this->options['groupby_times_custom'],
  98        '#description' => t("When choosing the 'custom' Time grouping option above, create custom time period groupings as a comma-separated list of 24-hour times in the format HH:MM:SS, like '00:00:00,08:00:00,18:00:00'. Be sure to start with '00:00:00'. All items after the last time will go in the final group."),
  99        );
 100      // Create a list of fields that are available for grouping and truncation,
 101      // excluding the date fields in the view from the grouping options.  
 102      $field_options = array();
 103      $date_field_options = array();
 104      $fields = $this->display->handler->get_option('fields');
 105      $date_fields = array_keys($this->date_fields());
 106      foreach ($fields as $field_name => $field) {
 107        $handler = views_get_handler($field['table'], $field['field'], 'field');
 108        if (!in_array($field['table'] .'.'. $field['field'], $date_fields)) {
 109          $field_options[$field['table'] .'_'. $field['field']] = $handler->ui_name();
 110        }
 111        else {
 112          $date_field_options[$field['table'] .'_'. $field['field']] = $handler->ui_name();
 113        }
 114      }
 115      $form['groupby_field'] = array(
 116        '#title' => t('Field grouping'),
 117        '#type' => in_array($calendar_type, array('day')) ? 'select' : 'value',
 118        '#default_value' => $this->options['groupby_field'],
 119        '#description' => t("Optionally group items into columns by a field value, for instance select the content type to show items for each content type in their own column, or use a location field to organize items into columns by location."),
 120        '#options' => array('' => '') + $field_options,
 121        );
 122        
 123      if (module_exists('calendar_multiday')) {  
 124        $form['multiday_theme'] = array(
 125          '#title' => t('Multi-day style'),
 126          '#default_value' => $this->options['multiday_theme'],
 127          '#type' => in_array($calendar_type, array('month', 'week')) ? 'select' : 'value',
 128          '#options' => array(0 => t('Display multi-day item as a single column'), 1 => t('Display multi-day item as a multiple column row')),
 129          '#description' => t('If selected, items which span multiple days will displayed as a multi-column row.  If not selected, items will be displayed as an individual column.'),
 130          );
 131        $form['theme_style'] = array(
 132          '#title' => t('Overlapping time style'),
 133          '#default_value' => $this->options['theme_style'],
 134          '#type' => in_array($calendar_type, array('day', 'week')) ? 'select' : 'value',
 135          '#options' => array(0 => t('Do not display overlapping items'), 1 => t('Display overlapping items')),
 136          '#description' => t('Select whether calendar items are displayed as overlapping items.'),
 137          );
 138      }  
 139        
 140      foreach ($form as $key => $value) {
 141        if ($value['#type'] == 'value') {
 142          $form[$key]['#value'] = $value['#default_value'];
 143        }
 144      }
 145    }
 146  
 147    /**
 148     * Render the calendar attachment style.
 149     */
 150    function render() {
 151      $calendar_type = $this->display->handler->get_option('calendar_type');
 152      // Adjust the theme to match the currently selected default.
 153      // Only the month view needs the special 'mini' class,
 154      // which is used to retrieve a different, more compact, theme.
 155      if (!empty($this->view->date_info->mini) && $this->view->date_info->granularity == 'month') {
 156        $this->definition['theme'] = 'calendar_mini';
 157      }
 158      elseif (  module_exists('calendar_multiday') && $calendar_type == 'week') {
 159        $this->view->date_info->mini = FALSE;
 160        $this->definition['theme'] = ($this->view->style_options['multiday_theme'] == '1' && $this->view->style_options['theme_style'] == '1') ? 'calendar_'. $this->view->date_info->granularity .'_overlap' : 'calendar_'. $this->view->date_info->granularity;
 161      }
 162      elseif ( module_exists('calendar_multiday') && $calendar_type == 'day') {
 163        $this->view->date_info->mini = FALSE;
 164        $this->definition['theme'] = ($this->view->style_options['theme_style'] == '1') ? 'calendar_'. $this->view->date_info->granularity .'_overlap' : 'calendar_'. $this->view->date_info->granularity;
 165      }
 166      else {
 167        $this->view->date_info->mini = FALSE;
 168        $this->definition['theme'] ='calendar_'. $this->view->date_info->granularity;
 169      }
 170      $this->view->date_info->hide_admin_links = TRUE;
 171      return theme($this->theme_functions(), $this->view, $this->options, array());
 172    }
 173  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7