function calendar_plugin_row::render in Calendar 7.3
Render a row object. This usually passes through to a theme template of some form, but not always.
Parameters
stdClass $row: A single row of the query result, so an element of $view->result.
Return value
string The rendered output of a single row, used by the style plugin.
Overrides views_plugin_row::render
File
- includes/
calendar_plugin_row.inc, line 371 - Contains the Calendar row style plugin.
Class
- calendar_plugin_row
- Plugin which creates a view on the resulting object and formats it as a Calendar node.
Code
function render($row) {
global $base_url;
$rows = array();
$date_info = $this->date_argument->view->date_info;
$id = $row->{$this->field_alias};
if (!is_numeric($id)) {
return $rows;
}
// There could be more than one date field in a view
// so iterate through all of them to find the right values
// for this view result.
foreach ($this->date_fields as $field_name => $info) {
// Load the specified node:
// We have to clone this or nodes on other views on this page,
// like an Upcoming block on the same page as a calendar view,
// will end up acquiring the values we set here.
$entity = clone $this->entities[$id];
if (empty($entity)) {
return $rows;
}
$table_name = $info['table_name'];
$delta_field = $info['delta_field'];
$tz_handling = $info['tz_handling'];
$tz_field = $info['timezone_field'];
$rrule_field = $info['rrule_field'];
$is_field = $info['is_field'];
$info = entity_get_info($this->entity_type);
$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;
$this->title = entity_label($this->entity_type, $entity);
$uri = entity_uri($this->entity_type, $entity);
$uri['options']['absolute'] = TRUE;
$this->url = '';
if (isset($uri['path'])) {
$this->url = url($uri['path'], $uri['options']);
}
// Retrieve the field value(s) that matched our query from the cached node.
// Find the date and set it to the right timezone.
$entity->date_id = array();
$item_start_date = NULL;
$item_end_date = NULL;
$granularity = 'second';
$increment = 1;
if ($is_field) {
// Set the date_id for the node, used to identify which field value to display for
// fields that have multiple values. The theme expects it to be an array.
$date_id = 'date_id_' . $field_name;
$date_delta = 'date_delta_' . $field_name;
if (isset($row->{$date_id})) {
$delta = $row->{$date_delta};
$entity->date_id = array(
'calendar-' . $row->{$date_id} . '-' . $field_name . '-' . $delta,
);
$delta_field = $date_delta;
}
else {
$delta = isset($row->{$delta_field}) ? $row->{$delta_field} : 0;
$entity->date_id = array(
'calendar-' . $id . '-' . $field_name . '-' . $delta,
);
}
$items = field_get_items($this->entity_type, $entity, $field_name, $this->language);
$item = $items[$delta];
$db_tz = date_get_timezone_db($tz_handling, isset($item->{$tz_field}) ? $item->{$tz_field} : $date_info->display_timezone_name);
$to_zone = date_get_timezone($tz_handling, isset($item->{$tz_field}) ? $item->{$tz_field} : $date_info->display_timezone_name);
if (isset($item['value'])) {
$item_start_date = new dateObject($item['value'], $db_tz);
$item_end_date = array_key_exists('value2', $item) && !empty($item['value2']) ? new dateObject($item['value2'], $db_tz) : $item_start_date;
}
$cck_field = field_info_field($field_name);
$instance = field_info_instance($this->entity_type, $field_name, $this->type);
$granularity = date_granularity_precision($cck_field['settings']['granularity']);
if ($instance) {
$increment = $instance['widget']['settings']['increment'];
}
}
elseif (!empty($entity->{$field_name})) {
$item = $entity->{$field_name};
$db_tz = date_get_timezone_db($tz_handling, isset($item->{$tz_field}) ? $item->{$tz_field} : $date_info->display_timezone_name);
$to_zone = date_get_timezone($tz_handling, isset($item->{$tz_field}) ? $item->{$tz_field} : $date_info->display_timezone_name);
$item_start_date = new dateObject($item, $db_tz);
$item_end_date = $item_start_date;
$entity->date_id = array(
'calendar-' . $id . '-' . $field_name,
);
}
// If we don't have a date value, go no further.
if (empty($item_start_date)) {
continue;
}
// Set the item date to the proper display timezone;
$item_start_date
->setTimezone(new dateTimezone($to_zone));
$item_end_date
->setTimezone(new dateTimezone($to_zone));
$event = new stdClass();
$event->id = $this->id;
$event->title = $this->title;
$event->type = $this->type;
$event->date_start = $item_start_date;
$event->date_end = $item_end_date;
$event->db_tz = $db_tz;
$event->to_zone = $to_zone;
$event->granularity = $granularity;
$event->increment = $increment;
$event->field = $is_field ? $item : NULL;
$event->url = $this->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];
// We are working with an array of partially rendered items
// as we process the calendar, so we can group and organize them.
// At the end of our processing we'll need to swap in the fully formatted
// display of the row. We save it here and switch it in
// template_preprocess_calendar_item().
$event->rendered = theme($this
->theme_functions(), array(
'view' => $this->view,
'options' => $this->options,
'row' => $row,
'field_alias' => isset($this->field_alias) ? $this->field_alias : '',
));
$entities = $this
->explode_values($event);
$date_info = $this->date_argument->view->date_info;
$from = $date_info->date_range[0];
$to = $date_info->date_range[1];
foreach ($entities as $entity) {
if ($entity->date_start < $from && $entity->date_end < $from || $entity->date_start > $to && $entity->date_end > $to) {
continue;
}
switch ($this->options['colors']['legend']) {
case 'type':
$this
->calendar_node_type_stripe($entity);
break;
case 'taxonomy':
$this
->calendar_taxonomy_stripe($entity);
break;
case 'group':
$this
->calendar_group_stripe($entity);
break;
}
$rows[] = $entity;
}
}
return $rows;
}