You are here

class calendar_view_plugin_style in Calendar 7

Same name and namespace in other branches
  1. 6.2 includes/calendar_view_plugin_style.inc \calendar_view_plugin_style
  2. 7.2 includes/calendar_view_plugin_style.inc \calendar_view_plugin_style

Style plugin to render the year, month, week, or day calendar view.

Hierarchy

Expanded class hierarchy of calendar_view_plugin_style

1 string reference to 'calendar_view_plugin_style'
calendar_views_plugins in includes/calendar.views.inc
Implementation of hook_views_plugins

File

includes/calendar_view_plugin_style.inc, line 11
Views calendar style plugin for the Calendar module.

View source
class calendar_view_plugin_style extends calendar_plugin_style {

  /**
   * Init will be called after construct, when the plugin is attached to a
   * view and a display.
   */
  function init(&$view, &$display, $options = NULL) {
    parent::init($view, $display, $options);
    if (!isset($view->date_info)) {
      $view->date_info = new stdClass();
    }
    $calendar_type = $this->display->handler
      ->get_option('calendar_type');
    $view->date_info->calendar_popup = $this->display->handler
      ->get_option('calendar_popup');
    $view->date_info->style_name_size = $this->options['name_size'];
    $view->date_info->style_with_weekno = $this->options['with_weekno'];
    $view->date_info->style_multiday_theme = $this->options['multiday_theme'];
    $view->date_info->style_theme_style = $this->options['theme_style'];
    $view->date_info->style_max_items = $this->options['max_items'];
    $view->date_info->style_max_items_behavior = $this->options['max_items_behavior'];
    $view->date_info->style_truncated_fields = $this->options['truncated_fields'];
    $view->date_info->style_truncate_length = $this->options['truncate_length'];
    if (!empty($this->options['groupby_times_custom'])) {
      $view->date_info->style_groupby_times = explode(',', $this->options['groupby_times_custom']);
    }
    else {
      $view->date_info->style_groupby_times = calendar_groupby_times($this->options['groupby_times']);
    }
    $view->date_info->style_groupby_field = $this->options['groupby_field'];

    // TODO make this an option setting.
    $view->date_info->style_show_empty_times = !empty($this->options['groupby_times_custom']) ? TRUE : FALSE;

    // Make sure views does't try to limit the number of items in this view.
    $this->view->pager['items_per_page'] = 0;
  }

  /**
   * Set default options
   */
  function options(&$options) {
    $options['name_size'] = 3;
    $options['with_weekno'] = 0;
    $options['multiday_theme'] = module_exists('calendar_multiday') ? '1' : '0';
    $options['theme_style'] = module_exists('calendar_multiday') ? '1' : '0';
    $options['max_items'] = 0;
    $options['max_items_behavior'] = 'more';
    $options['truncated_fields'] = array();
    $options['truncate_length'] = '';
    $options['groupby_times'] = 'hour';
    $options['groupby_times_custom'] = '';
    $options['groupby_field'] = '';
  }

  /**
   * Style options.
   */
  function options_form(&$form, &$form_state) {
    $calendar_type = $this->display->handler
      ->get_option('calendar_type');
    $form['name_size'] = array(
      '#title' => t('Calendar day of week names'),
      '#default_value' => $this->options['name_size'],
      '#type' => in_array($calendar_type, array(
        'year',
        'month',
        'week',
      )) ? 'radios' : 'value',
      '#options' => array(
        1 => t('First letter of name'),
        2 => t('First two letters of name'),
        3 => t('Abbreviated name'),
        99 => t('Full name'),
      ),
      '#description' => t('The way day of week names should be displayed in a calendar.'),
    );
    $form['with_weekno'] = array(
      '#title' => t('Show week numbers'),
      '#default_value' => $this->options['with_weekno'],
      '#type' => in_array($calendar_type, array(
        'month',
      )) ? 'radios' : 'value',
      '#options' => array(
        0 => t('No'),
        1 => t('Yes'),
      ),
      '#description' => t('Whether or not to show week numbers in the left column of calendar weeks and months.'),
    );
    $form['max_items'] = array(
      '#title' => t('Maximum items'),
      '#type' => in_array($calendar_type, array(
        'month',
      )) ? 'select' : 'value',
      '#options' => array(
        0 => t('Unlimited'),
        3 => t('3 items'),
        5 => t('5 items'),
        10 => t('10 items'),
      ),
      '#default_value' => $calendar_type != 'day' ? $this->options['max_items'] : 0,
      '#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.'),
    );
    $form['max_items_behavior'] = array(
      '#title' => t('Too many items'),
      '#type' => in_array($calendar_type, array(
        'month',
      )) ? 'select' : 'value',
      '#options' => array(
        'more' => t("Show maximum, add 'more' link"),
        'hide' => t('Hide all, add link to day'),
      ),
      '#default_value' => $calendar_type != 'day' ? $this->options['max_items_behavior'] : 'more',
      '#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.'),
    );
    $form['groupby_times'] = array(
      '#title' => t('Time grouping'),
      '#type' => in_array($calendar_type, array(
        'day',
        'week',
      )) ? 'select' : 'value',
      '#default_value' => $this->options['groupby_times'],
      '#description' => t("Group items together into time periods based on their start time."),
      '#options' => array(
        '' => t('None'),
        'hour' => t('Hour'),
        'half' => t('Half hour'),
        'custom' => t('Custom'),
      ),
    );
    $form['groupby_times_custom'] = array(
      '#title' => t('Custom time grouping'),
      '#type' => in_array($calendar_type, array(
        'day',
        'week',
      )) ? 'textarea' : 'value',
      '#default_value' => $this->options['groupby_times_custom'],
      '#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."),
    );

    // Create a list of fields that are available for grouping and truncation,
    // excluding the date fields in the view from the grouping options.
    $field_options = array();
    $date_field_options = array();
    $fields = $this->display->handler
      ->get_option('fields');
    $date_fields = array_keys($this
      ->date_fields());
    foreach ($fields as $field_name => $field) {
      $handler = views_get_handler($field['table'], $field['field'], 'field');
      if (!in_array($field['table'] . '.' . $field['field'], $date_fields)) {
        $field_options[$field['table'] . '_' . $field['field']] = $handler
          ->ui_name();
      }
      else {
        $date_field_options[$field['table'] . '_' . $field['field']] = $handler
          ->ui_name();
      }
    }
    $form['groupby_field'] = array(
      '#title' => t('Field grouping'),
      '#type' => in_array($calendar_type, array(
        'day',
      )) ? 'select' : 'value',
      '#default_value' => $this->options['groupby_field'],
      '#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."),
      '#options' => array(
        '' => '',
      ) + $field_options,
    );
    if (module_exists('calendar_multiday')) {
      $form['multiday_theme'] = array(
        '#title' => t('Multi-day style'),
        '#default_value' => $this->options['multiday_theme'],
        '#type' => in_array($calendar_type, array(
          'month',
          'week',
        )) ? 'select' : 'value',
        '#options' => array(
          0 => t('Display multi-day item as a single column'),
          1 => t('Display multi-day item as a multiple column row'),
        ),
        '#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.'),
      );
      $form['theme_style'] = array(
        '#title' => t('Overlapping time style'),
        '#default_value' => $this->options['theme_style'],
        '#type' => in_array($calendar_type, array(
          'day',
          'week',
        )) ? 'select' : 'value',
        '#options' => array(
          0 => t('Do not display overlapping items'),
          1 => t('Display overlapping items'),
        ),
        '#description' => t('Select whether calendar items are displayed as overlapping items.'),
      );
    }
    $form['truncated_fields'] = array(
      '#title' => t('Truncated fields'),
      '#type' => in_array($calendar_type, array(
        'month',
        'week',
        'day',
      )) ? 'checkboxes' : 'value',
      '#options' => $field_options + $date_field_options,
      '#default_value' => $this->options['truncated_fields'],
      '#multiple' => TRUE,
      '#description' => t("Fields that should be truncated to fit in the calendar cell. For instance, change the title from 'Very Very Very Long Name' to something like 'Very Very...'."),
    );
    $form['truncate_length'] = array(
      '#title' => t('Truncate length'),
      '#type' => in_array($calendar_type, array(
        'month',
        'week',
        'day',
      )) ? 'textfield' : 'value',
      '#default_value' => $this->options['truncate_length'],
      '#description' => t("Maximum number of characters to leave in truncated fields."),
      '#maxlength' => 4,
      '#size' => 4,
    );
    foreach ($form as $key => $value) {
      if ($value['#type'] == 'value') {
        $form[$key]['#value'] = $value['#default_value'];
      }
    }
  }
  function options_submit(&$form, &$form_state) {
    $form_state['values']['style_options']['truncated_fields'] = array_filter($form_state['values']['style_options']['truncated_fields']);
  }

  /**
   * Render the calendar attachment style.
   */
  function render() {
    $calendar_type = $this->display->handler
      ->get_option('calendar_type');

    // Adjust the theme to match the currently selected default.
    // Only the month view needs the special 'mini' class,
    // which is used to retrieve a different, more compact, theme.
    if (!empty($this->view->date_info->mini) && $this->view->date_info->granularity == 'month') {
      $this->definition['theme'] = 'calendar_mini';
    }
    elseif (module_exists('calendar_multiday') && $calendar_type == 'week') {
      $this->view->date_info->mini = FALSE;
      $this->definition['theme'] = !isset($this->view->style_options['multiday_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;
    }
    elseif (module_exists('calendar_multiday') && $calendar_type == 'day') {
      $this->view->date_info->mini = FALSE;
      $this->definition['theme'] = !isset($this->view->style_options['multiday_theme']) || $this->view->style_options['theme_style'] == '1' ? 'calendar_' . $this->view->date_info->granularity . '_overlap' : 'calendar_' . $this->view->date_info->granularity;
    }
    else {
      $this->view->date_info->mini = FALSE;
      $this->definition['theme'] = 'calendar_' . $this->view->date_info->granularity;
    }
    $this->view->date_info->hide_admin_links = TRUE;
    return theme($this
      ->theme_functions(), array(
      'view' => $this->view,
      'options' => $this->options,
      'items' => array(),
    ));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
calendar_plugin_style::date_fields function Calendar argument date fields used in this view.
calendar_plugin_style::display_types function
calendar_plugin_style::query function Add anything to the query that we might need to. Overrides views_plugin_style::query
calendar_plugin_style::validate function Style validation. Overrides views_plugin_style::validate
calendar_view_plugin_style::init function Init will be called after construct, when the plugin is attached to a view and a display. Overrides calendar_plugin_style::init
calendar_view_plugin_style::options function Set default options Overrides views_object::options
calendar_view_plugin_style::options_form function Style options. Overrides views_plugin_style::options_form
calendar_view_plugin_style::options_submit function Handle any special handling on the validate form. Overrides views_plugin::options_submit
calendar_view_plugin_style::render function Render the calendar attachment style. Overrides calendar_plugin_style::render
views_object::$definition public property Handler's definition.
views_object::$options public property Except for displays, options for the object will be held here. 1
views_object::altered_option_definition function Collect this handler's option definition and alter them, ready for use.
views_object::construct public function Views handlers use a special construct function. 4
views_object::export_option public function 1
views_object::export_options public function
views_object::export_option_always public function Always exports the option, regardless of the default value.
views_object::set_default_options public function Set default options.
views_object::set_definition public function Let the handler know what its full definition is.
views_object::unpack_options public function Unpack options over our existing defaults, drilling down into arrays so that defaults don't get totally blown away.
views_object::unpack_translatable public function Unpack a single option definition.
views_object::unpack_translatables public function Unpacks each handler to store translatable texts.
views_object::_set_option_defaults public function
views_plugin::$display public property The current used views display.
views_plugin::$plugin_name public property The plugin name of this plugin, for example table or full.
views_plugin::$plugin_type public property The plugin type of this plugin, for example style or query.
views_plugin::$view public property The top object of a view. Overrides views_object::$view 1
views_plugin::additional_theme_functions public function Provide a list of additional theme functions for the theme info page.
views_plugin::plugin_title public function Return the human readable name of the display.
views_plugin::summary_title public function Returns the summary of the settings in the display. 8
views_plugin::theme_functions public function Provide a full list of possible theme templates used by this style.
views_plugin_style::$row_plugin public property The row plugin, if it's initialized and the style itself supports it.
views_plugin_style::$row_tokens public property Store all available tokens row rows.
views_plugin_style::build_sort public function Called by the view builder to see if this style handler wants to interfere with the sorts. If so it should build; if it returns any non-TRUE value, normal sorting will NOT be added to the query. 1
views_plugin_style::build_sort_post public function Called by the view builder to let the style build a second set of sorts that will come after any other sorts in the view. 1
views_plugin_style::destroy public function Destructor. Overrides views_object::destroy
views_plugin_style::even_empty public function Should the output of the style plugin be rendered even if it's empty. 1
views_plugin_style::get_field public function Get a rendered field.
views_plugin_style::get_field_value public function Get the raw field value.
views_plugin_style::get_row_class public function Return the token replaced row class for the specified row.
views_plugin_style::options_validate public function Validate the options form. Overrides views_plugin::options_validate
views_plugin_style::option_definition public function Information about options for all kinds of purposes will be held here. Overrides views_object::option_definition 8
views_plugin_style::pre_render public function Allow the style to do stuff before each row is rendered.
views_plugin_style::render_fields public function Render all of the fields for a given style and store them on the object.
views_plugin_style::render_grouping public function Group records as needed for rendering.
views_plugin_style::render_grouping_sets public function Render the grouping sets.
views_plugin_style::tokenize_value public function Take a value and apply token replacement logic to it.
views_plugin_style::uses_fields public function Return TRUE if this style also uses fields.
views_plugin_style::uses_row_class public function Return TRUE if this style also uses a row plugin.
views_plugin_style::uses_row_plugin public function Return TRUE if this style also uses a row plugin.
views_plugin_style::uses_tokens public function Return TRUE if this style uses tokens.