You are here

protected function date_ical_plugin_row_ical_fields::get_row_date in Date iCal 7.3

Same name and namespace in other branches
  1. 7.2 includes/date_ical_plugin_row_ical_fields.inc \date_ical_plugin_row_ical_fields::get_row_date()

Returns an normalized array for the current row's datefield/timestamp.

Parameters

object $row: The current row object.

string $date_field_name: The name of the date field.

Return value

array The normalized array.

1 call to date_ical_plugin_row_ical_fields::get_row_date()
date_ical_plugin_row_ical_fields::render in includes/date_ical_plugin_row_ical_fields.inc
Returns an Event array row in the query with index: $row->index.

File

includes/date_ical_plugin_row_ical_fields.inc, line 288
Defines the iCal Fields row style plugin, which lets users map view fields to the components of the VEVENTs in the iCal feed.

Class

date_ical_plugin_row_ical_fields
A Views plugin which builds an iCal VEVENT from a views row with Fields.

Code

protected function get_row_date($row, $date_field_name) {
  $start = NULL;
  $end = NULL;
  $rrule = NULL;
  $delta = 0;
  $is_date_field = FALSE;

  // Fetch the date field value.
  $date_field_value = $this->view->style_plugin
    ->get_field_value($row->index, $date_field_name);

  // Handle date fields.
  if (isset($date_field_value[$delta]) && is_array($date_field_value[$delta])) {
    $is_date_field = TRUE;
    $date_field = $date_field_value[$delta];
    $start = new DateObject($date_field['value'], $date_field['timezone_db']);
    if (!empty($date_field['value2'])) {
      $end = new DateObject($date_field['value2'], $date_field['timezone_db']);
    }
    else {
      $end = clone $start;
    }
    if (isset($date_field['rrule'])) {
      $rrule = $date_field['rrule'];
    }
  }
  elseif (is_numeric($date_field_value)) {

    // Handle timestamps, which are always in UTC.
    $start = new DateObject($date_field_value, 'UTC');
    $end = new DateObject($date_field_value, 'UTC');
  }
  else {

    // Processing cannot proceed with a blank date value.
    $title = strip_tags($this->view->style_plugin
      ->get_field($row->index, $this->options['title_field']));
    throw new BlankDateFieldException(t("The row %title has a blank date. An iCal entry cannot be created for it.", array(
      '%title' => $title,
    )));
  }

  // Set the display timezone to whichever tz is stored for this field.
  // If there isn't a stored TZ, use the site default.
  $timezone = isset($date_field['timezone']) ? $date_field['timezone'] : date_default_timezone(FALSE);
  $dtz = new DateTimeZone($timezone);
  $start
    ->setTimezone($dtz);
  $end
    ->setTimezone($dtz);
  $granularity = 'second';
  if ($is_date_field) {
    $granularity_settings = $this->view->field[$date_field_name]->field_info['settings']['granularity'];
    $granularity = date_granularity_precision($granularity_settings);
  }

  // Check if the start and end dates indicate that this is an All Day event.
  $all_day = date_is_all_day(date_format($start, DATE_FORMAT_DATETIME), date_format($end, DATE_FORMAT_DATETIME), $granularity);
  if ($all_day) {

    // According to RFC 2445 (clarified in RFC 5545) the DTEND value is
    // non-inclusive. When dealing with All Day values, they are DATEs rather
    // than DATETIMEs, so we need to add a day to conform to RFC.
    $end
      ->modify("+1 day");
  }
  $date = array(
    'start' => $start,
    'end' => $end,
    'all_day' => $all_day,
    'rrule' => $rrule,
  );
  return $date;
}