You are here

class fullcalendar_plugin_style_fullcalendar in FullCalendar 7.2

Same name and namespace in other branches
  1. 6.2 includes/views/plugins/fullcalendar_plugin_style_fullcalendar.inc \fullcalendar_plugin_style_fullcalendar

@file Contains the FullCalendar style plugin.

Hierarchy

Expanded class hierarchy of fullcalendar_plugin_style_fullcalendar

1 string reference to 'fullcalendar_plugin_style_fullcalendar'
fullcalendar_views_plugins in includes/views/fullcalendar.views.inc
Implements hook_views_plugins().

File

includes/views/plugins/fullcalendar_plugin_style_fullcalendar.inc, line 8
Contains the FullCalendar style plugin.

View source
class fullcalendar_plugin_style_fullcalendar extends views_plugin_style {

  /**
   * Check if there are no results behaviors set.
   */
  function even_empty() {
    return empty($this->view->empty) ? !empty($this->definition['even empty']) : FALSE;
  }

  /**
   * Map old setting names to new ones.
   * @todo Remove in 7.x-2.1.
   */
  function init(&$view, &$display, $options = NULL) {
    parent::init($view, $display, $options);
    if (!empty($options)) {

      // Set up a rename map from the old names to new names.
      $rename_map = array(
        'times' => array(
          'fc_default_date' => 'default_date',
          'fc_date' => 'date',
          'fc_timeformat' => 'timeformat',
        ),
        'header' => array(
          'fc_left' => 'left',
          'fc_center' => 'center',
          'fc_right' => 'right',
        ),
        'modules' => array(
          'fc_theme' => 'theme',
          'fc_window' => 'sameWindow',
          'fc_url_colorbox' => 'colorbox',
          'fc_url_colorbox_class' => 'colorboxClass',
          'fc_url_colorbox_height' => 'colorboxHeight',
          'fc_url_colorbox_width' => 'colorboxWidth',
        ),
        'display' => array(
          'fc_view' => 'defaultView',
          'fc_firstday' => 'firstDay',
          'fc_weekmode' => 'weekMode',
          'fc_content_height' => 'contentHeight',
        ),
      );
      $new_options = array();
      foreach ($options as $grouping => $option) {
        if (!isset($rename_map[$grouping])) {
          continue;
        }
        foreach ($rename_map[$grouping] as $old_option => $new_option) {
          if (!isset($options[$grouping][$old_option])) {
            continue;
          }

          // All new settings aren't nested, except date and default_date.
          if ($grouping == 'times' && in_array($old_option, array(
            'fc_default_date',
            'fc_date',
          ))) {
            $new_options[$grouping][$new_option] = $options[$grouping][$old_option];
          }
          else {
            $new_options[$new_option] = $options[$grouping][$old_option];
          }
        }
      }

      // Set out new variable for later usage.
      $this->time = empty($options['times']['fc_clock']) ? '12' : '24';

      // Add new options to defaults.
      $this
        ->unpack_options($this->options, array_filter($new_options));

      // Unset the obsolete settings.
      unset($this->options['display']);
      unset($this->options['modules']);
      unset($this->options['header']);
      unset($this->options['times']['fc_clock']);
      unset($this->options['times']['fc_date']);
      unset($this->options['times']['fc_default_date']);
      unset($this->options['times']['fc_timeformat']);
    }

    // Move Colorbox settings into their own array.
    $options = $this->options;
    if (isset($options['colorbox']) && !is_array($options['colorbox'])) {
      $colorbox = array();
      foreach ($options as $key => $value) {
        if (substr($key, 0, 8) == 'colorbox') {
          $colorbox[$key] = $value;
          unset($options[$key]);
        }
      }
      $options['colorbox'] = $colorbox;
      $this
        ->unpack_options($this->options, $options);
    }
  }
  function option_definition() {

    // Load all FullCalendar options and merge in their form info.
    fullcalendar_include_api();
    return module_invoke_all('fullcalendar_options_definition');
  }
  function options_form(&$form, &$form_state) {

    // Load all FullCalendar options and merge in their form info.
    fullcalendar_include_api();
    $fullcalendar_options = module_invoke_all('fullcalendar_options_info');
    uasort($fullcalendar_options, 'drupal_sort_weight');
    if (!empty($fullcalendar_options)) {
      $arguments = array(
        &$form,
        &$form_state,
        &$this,
      );

      // Create a separate fieldset for each module.
      foreach (array_intersect(array_keys($fullcalendar_options), module_implements('fullcalendar_options_form')) as $module) {
        if (empty($fullcalendar_options[$module]['no_fieldset'])) {
          $form[$module] = array(
            '#type' => 'fieldset',
            '#title' => t('@module options', array(
              '@module' => $fullcalendar_options[$module]['name'],
            )),
            '#collapsible' => TRUE,
            '#collapsed' => TRUE,
            '#attributes' => array(
              'class' => array(
                $module,
              ),
            ),
          );
        }
        $function = $module . '_fullcalendar_options_form';
        call_user_func_array($function, $arguments);
      }
    }
  }
  function options_validate(&$form, &$form_state) {
    parent::options_validate($form, $form_state);

    // If an option was defined with #data_type, cast the value to that.
    if (is_array($form_state['values']['style_options'])) {
      $this
        ->fullcalendar_cast_nested_value($form_state['values']['style_options'], $form);
    }
    fullcalendar_include_api();
    $arguments = array(
      &$form,
      &$form_state,
      &$this,
    );
    foreach (module_implements('fullcalendar_options_validate') as $module) {
      $function = $module . '_fullcalendar_options_validate';
      call_user_func_array($function, $arguments);
    }
  }
  function options_submit(&$form, &$form_state) {
    parent::options_submit($form, $form_state);
    fullcalendar_include_api();
    $arguments = array(
      &$form,
      &$form_state,
      $this,
    );
    foreach (module_implements('fullcalendar_options_submit') as $module) {
      $function = $module . '_fullcalendar_options_submit';
      call_user_func_array($function, $arguments);
    }
  }
  function validate() {
    if ($this->display->display_plugin != 'default') {

      // Get the date fields.
      $date_fields = $this
        ->fullcalendar_parse_fields();
      if (empty($date_fields)) {
        drupal_set_message(t('Display "@display" requires at least one date field.', array(
          '@display' => $this->display->display_title,
        )), 'error');
      }
    }
    return parent::validate();
  }
  function fullcalendar_parse_fields($include_gcal = TRUE) {

    // Ensure the handlers are there.
    $this->view
      ->init_handlers();
    $labels = $this->display->handler
      ->get_field_labels();
    $date_fields = array();
    foreach ($this->view->field as $id => $field) {
      if (fullcalendar_field_is_date($field, $include_gcal)) {
        $date_fields[$id] = $labels[$id];
      }
    }
    return $date_fields;
  }

  /**
   * If #data_type is defined, use that as the type for casting the value.
   *
   * @param array $values
   *   An array of View option form values.
   * @param array $form
   *   The Views option form definition.
   * @param string $current_key
   *   The current key being processed.
   * @param array $parents
   *   An array of parent keys when recursing through the nested array.
   */
  function fullcalendar_cast_nested_value(&$values, $form, $current_key = NULL, $parents = array()) {
    foreach ($values as $key => &$value) {

      // We are leaving a recursive loop, remove the last parent key.
      if (empty($current_key)) {
        array_pop($parents);
      }

      // In case we recurse into an array, or need to specify the key for
      // drupal_array_get_nested_value(), add the current key to $parents.
      $parents[] = $key;
      if (is_array($value)) {

        // Enter another recursive loop.
        $this
          ->fullcalendar_cast_nested_value($value, $form, $key, $parents);
      }
      else {

        // Get the form definition for this key.
        $form_value = drupal_array_get_nested_value($form, $parents);

        // Check to see if #data_type is specified, if so, cast the value.
        if (isset($form_value['#data_type'])) {
          settype($value, $form_value['#data_type']);
        }

        // Remove the current key from $parents to move on to the next key.
        array_pop($parents);
      }
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
fullcalendar_plugin_style_fullcalendar::even_empty function Check if there are no results behaviors set. Overrides views_plugin_style::even_empty
fullcalendar_plugin_style_fullcalendar::fullcalendar_cast_nested_value function If #data_type is defined, use that as the type for casting the value.
fullcalendar_plugin_style_fullcalendar::fullcalendar_parse_fields function
fullcalendar_plugin_style_fullcalendar::init function Map old setting names to new ones. @todo Remove in 7.x-2.1. Overrides views_plugin_style::init
fullcalendar_plugin_style_fullcalendar::options_form function Provide a form to edit options for this plugin. Overrides views_plugin_style::options_form
fullcalendar_plugin_style_fullcalendar::options_submit function Handle any special handling on the validate form. Overrides views_plugin::options_submit
fullcalendar_plugin_style_fullcalendar::options_validate function Validate the options form. Overrides views_plugin_style::options_validate
fullcalendar_plugin_style_fullcalendar::option_definition function Information about options for all kinds of purposes will be held here. Overrides views_plugin_style::option_definition
fullcalendar_plugin_style_fullcalendar::validate function Validate that the plugin is correct and can be saved. Overrides views_plugin_style::validate
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::options Deprecated public function Set default options on this object. 1
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::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::pre_render public function Allow the style to do stuff before each row is rendered.
views_plugin_style::query public function Add anything to the query that we might need to. Overrides views_plugin::query 2
views_plugin_style::render public function Render the display in this style. 5
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.