diff --git a/includes/calendar_plugin_row.inc b/includes/calendar_plugin_row.inc index 1d6844b..e01ea12 100644 --- a/includes/calendar_plugin_row.inc +++ b/includes/calendar_plugin_row.inc @@ -104,20 +104,18 @@ class calendar_plugin_row extends views_plugin_row { foreach ($type_names as $key => $name) { $form['colors']['calendar_colors_type'][$key] = array( '#title' => check_plain($name), - '#type' => 'textfield', '#default_value' => isset($colors[$key]) ? $colors[$key] : '#ffffff', + '#type' => 'textfield', + '#dependency' => array('edit-row-options-colors-legend' => array('type')), '#size' => 7, '#maxlength' => 7, '#element_validate' => array('calendar_validate_hex_color'), - '#dependency' => array('edit-row-options-colors-legend' => array('type')), '#prefix' => '
', '#suffix' => '
', '#attributes' => array('class' => array('edit-calendar-colorpicker')), '#attached' => array( // Add Farbtastic color picker. - 'library' => array( - array('system', 'farbtastic'), - ), + 'library' => array(array('system', 'farbtastic'), ), // Add javascript to trigger the colorpicker. 'js' => array(drupal_get_path('module', 'calendar') . '/js/calendar_colorpicker.js'), ), @@ -168,21 +166,19 @@ class calendar_plugin_row extends views_plugin_row { foreach ($vocab as $tid => $term) { $form['colors']['calendar_colors_taxonomy'][$term->tid] = array( '#title' => check_plain(t($term->name)), - '#type' => 'textfield', '#default_value' => isset($term_colors[$term->tid]) ? $term_colors[$term->tid] : '#ffffff', + '#type' => 'textfield', + '#dependency' => array('edit-row-options-colors-legend' => array('taxonomy')), + '#access' => !empty($vocab_field_options), '#size' => 7, '#maxlength' => 7, - '#access' => !empty($vocab_field_options), - '#dependency' => array('edit-row-options-colors-legend' => array('taxonomy')), '#element_validate' => array('calendar_validate_hex_color'), '#prefix' => '
', '#suffix' => '
', '#attributes' => array('class' => array('edit-calendar-colorpicker')), '#attached' => array( // Add Farbtastic color picker. - 'library' => array( - array('system', 'farbtastic'), - ), + 'library' => array(array('system', 'farbtastic'), ), // Add javascript to trigger the colorpicker. 'js' => array(drupal_get_path('module', 'calendar') . '/js/calendar_colorpicker.js'), ), @@ -190,24 +186,25 @@ class calendar_plugin_row extends views_plugin_row { } } } + if (module_exists('og')) { $colors_group = $this->options['colors']['calendar_colors_group']; $groups = og_get_all_group(); foreach ($groups as $gid) { $form['colors']['calendar_colors_group'][$gid] = array( '#title' => check_plain(t(og_label($gid))), - '#type' => 'textfield', '#default_value' => isset($colors_group[$gid]) ? $colors_group[$gid] : '#ffffff', '#dependency' => array('edit-row-options-colors-legend' => array('group')), + '#type' => 'textfield', + '#size' => 7, + '#maxlength' => 7, '#element_validate' => array('calendar_validate_hex_color'), '#prefix' => '
', '#suffix' => '
', '#attributes' => array('class' => array('edit-calendar-colorpicker')), '#attached' => array( // Add Farbtastic color picker. - 'library' => array( - array('system', 'farbtastic'), - ), + 'library' => array(array('system', 'farbtastic'),), // Add javascript to trigger the colorpicker. 'js' => array(drupal_get_path('module', 'calendar') . '/js/calendar_colorpicker.js'), ), @@ -230,7 +227,6 @@ class calendar_plugin_row extends views_plugin_row { } function pre_render($values) { - // @TODO When the date is coming in through a relationship, the nid // of the view is not the right node to use, then we need the related node. // Need to sort out how that should be handled. @@ -243,22 +239,10 @@ class calendar_plugin_row extends views_plugin_row { foreach ($values as $row) { // Use the $id as the key so we don't create more than one value per entity. $id = $row->{$this->field_alias}; - - // Node revisions need special loading. - if ($this->view->base_table == 'node_revision') { - $this->entities[$id] = node_load(NULL, $id); - } - // For other entities we just create an array of ids to pass - // to entity_load(). - else { - $ids[$id] = $id; - } + $ids[$id] = $id; } - - $base_tables = date_views_base_tables(); - $this->entity_type = $base_tables[$this->view->base_table]; if (!empty($ids)) { - $this->entities = entity_load($this->entity_type, $ids); + $this->entities = entity_load($this->view->base_table, $ids); } // Let the style know if a link to create a new date is required. @@ -284,14 +268,6 @@ class calendar_plugin_row extends views_plugin_row { foreach ($handler->options['date_fields'] as $alias) { $info = $data[$alias]; $field_name = str_replace(array('_value2', '_value'), '', $info['real_field_name']); - - // This is ugly and hacky but I can't figure out any generic way to - // recognize that the node module is going to give some the revision timestamp - // a different field name on the entity than the actual column name in the database. - if ($this->view->base_table == 'node_revision' && $field_name == 'timestamp') { - $field_name = 'revision_timestamp'; - } - $date_fields[$field_name] = $info; } } @@ -338,28 +314,12 @@ class calendar_plugin_row extends views_plugin_row { $rrule_field = $info['rrule_field']; $is_field = $info['is_field']; - $info = entity_get_info($this->entity_type); + $info = entity_get_info($this->view->base_table); $this->id_field = $info['entity keys']['id']; - $this->id = $entity->{$this->id_field}; - $this->type = !empty($info['entity keys']['bundle']) ? $info['entity keys']['bundle'] : $this->entity_type; - - if (!empty($info['label callback'])) { - $function = $info['label callback']; - $this->title = $function($this->id); - } - else { - $this->title_field = $info['entity keys']['label']; - $this->title = $entity->{$this->title_field}; - } - - if (!empty($info['uri callback'])) { - $callback = $info['uri callback']; - $path = $callback($entity); - $this->url = $path['path']; - } - else { - $this->url = NULL; - } + $this->bundle = $info['entity keys']['bundle']; + $callback = $info['uri callback']; + $path = $callback($entity); + $entity->url = $path['path']; // Retrieve the field value(s) that matched our query from the cached node. // Find the date and set it to the right timezone. @@ -369,6 +329,7 @@ class calendar_plugin_row extends views_plugin_row { $item_end_date = NULL; $granularity = 'second'; $increment = 1; + if ($is_field) { $delta = isset($row->$delta_field) ? $row->$delta_field : 0; @@ -411,9 +372,9 @@ class calendar_plugin_row extends views_plugin_row { $item_end_date->setTimezone(new dateTimezone($to_zone)); $event = new stdClass(); - $event->id = $this->id; - $event->title = $this->title; - $event->type = $this->type; + $event->id = $entity->{$this->id_field}; + $event->title = $entity->title; + $event->type = $entity->{$this->bundle}; $event->date_start = $item_start_date; $event->date_end = $item_end_date; $event->db_tz = $db_tz; @@ -421,13 +382,14 @@ class calendar_plugin_row extends views_plugin_row { $event->granularity = $granularity; $event->increment = $increment; $event->field = $is_field ? $item : NULL; - $event->url = $this->url; + $event->url = $entity->url; $event->row = $row; $event->entity = $entity; + $event->stripe = array(); + $event->stripe_label = array(); // All calendar row plugins should provide a date_id that the theme can use. $event->date_id = $entity->date_id[0]; - $entities = $this->explode_values($event); foreach ($entities as $entity) { switch ($this->options['colors']['legend']) { @@ -443,7 +405,6 @@ class calendar_plugin_row extends views_plugin_row { } $rows[] = $entity; } - } return $rows; } @@ -525,85 +486,46 @@ class calendar_plugin_row extends views_plugin_row { } /** - * Create a stripe base on node type. + * Creates a stripe based on the node type. */ function calendar_node_type_stripe(&$entity) { $colors = isset($this->options['colors']['calendar_colors_type']) ? $this->options['colors']['calendar_colors_type'] : array(); if (empty($colors)) { return; } - if (empty($entity->type)) { - return; - } - $type_names = node_type_get_names(); - $type = $entity->type; - $label = ''; - $stripe = ''; - if (!(isset($entity->stripe))) { - $entity->stripe = array(); - $entity->stripe_label = array(); - } - if (array_key_exists($type, $type_names)) { - $label = $type_names[$type]; - } - if (array_key_exists($type, $colors)) { - $stripe = $colors[$type]; + if (!empty($entity->type)) { + $type = $entity->type; + $type_names = node_type_get_names(); + if (array_key_exists($type, $colors) + && array_key_exists($type, $type_names) ) { + $entity->stripe[] = $colors[$type]; + $entity->stripe_label[] = $type_names[$type]; + } } - - $entity->stripe[] = $stripe; - $entity->stripe_label[] = $label; - return $stripe; + return; } - /** + /** * Create a stripe based on a taxonomy term. */ - function calendar_taxonomy_stripe(&$entity) { - $term_colors = isset($this->options['colors']['calendar_colors_taxonomy']) ? $this->options['colors']['calendar_colors_taxonomy'] : array(); - if (empty($term_colors)) { + $colors = isset($this->options['colors']['calendar_colors_taxonomy']) ? $this->options['colors']['calendar_colors_taxonomy'] : array(); + if (empty($colors)) { return; } - $terms = array(); - if ($this->options['colors']['legend'] == 'taxonomy') { - $term_field_name = $this->options['colors']['taxonomy_field']; - - if ($term_field = field_get_items($this->view->base_table, $entity->entity, $term_field_name)) { - foreach ($term_field as $delta => $items) { - foreach ($items as $item) { - $terms[] = $item['tid']; - } - } - } - } - - if (empty($terms)) { - return; - } + $term_field_name = $this->options['colors']['taxonomy_field']; - if (!(isset($entity->stripe))) { - $entity->stripe = array(); - $entity->stripe_label = array(); - } - if (count($terms)) { - foreach ($terms as $tid) { - $term_for_entity = taxonomy_term_load($tid); - if (!array_key_exists($term_for_entity->tid, $term_colors)) { - continue; + if ($terms_for_entity = field_get_items($this->view->base_table, $entity->entity, $term_field_name)) { + foreach ($terms_for_entity as $delta => $item) { + $term_for_entity = taxonomy_term_load($item['tid']); + if (array_key_exists($term_for_entity->tid, $colors)) { + $entity->stripe[] = $colors[$term_for_entity->tid]; + $entity->stripe_label[] = $term_for_entity->name; } - $stripe = $term_colors[$term_for_entity->tid]; - $stripe_label = $term_for_entity->name; - $entity->stripe[] = $stripe; - $entity->stripe_label[] = $stripe_label; } } - else { - $entity->stripe[] = ''; - $entity->stripe_label[] = ''; - } - return; } @@ -611,35 +533,23 @@ class calendar_plugin_row extends views_plugin_row { * Create a stripe based on group. */ function calendar_group_stripe(&$entity) { - $colors_group = isset($this->options['colors']['calendar_colors_group']) ? $this->options['colors']['calendar_colors_group'] : array(); - - if (empty($colors_group)) { + $colors = isset($this->options['colors']['calendar_colors_group']) ? $this->options['colors']['calendar_colors_group'] : array(); + if (empty($colors)) { return; } + if (!function_exists('og_get_entity_groups')) { return; } - $groups_for_entity = og_get_entity_groups($this->view->base_table, $entity); - if (!(isset($entity->stripe))) { - $entity->stripe = array(); - $entity->stripe_label = array(); - } - if (count($groups_for_entity)) { + + if ($groups_for_entity = og_get_entity_groups($this->view->base_table, $entity)) { foreach ($groups_for_entity as $gid => $group_name) { - if (!array_key_exists($gid, $colors_group)) { - continue; + if (array_key_exists($gid, $colors)) { + $entity->stripe[] = $colors[$gid]; + $entity->stripe_label[] = $group_name; } - $stripe = $colors_group[$gid]; - $stripe_label = $group_name; - $entity->stripe[] = $stripe; - $entity->stripe_label[] = $stripe_label; } } - else { - $entity->stripe[] = ''; - $entity->stripe_label[] = ''; - } return; } } -