class ParserIcalDateTimeElement in iCal feed parser 6.2
Same name and namespace in other branches
- 7 includes/ParserIcalFeedsParser.inc \ParserIcalDateTimeElement
Overridden version of FeedsDateTimeElement that supports iCal specific parsing and repetition.
@todo repeating date storage not iCal specific, could be moved to base class.
Hierarchy
- class \FeedsElement
- class \FeedsDateTimeElement
- class \ParserIcalDateTimeElement
- class \FeedsDateTimeElement
Expanded class hierarchy of ParserIcalDateTimeElement
File
- includes/
ParserIcalFeedsParser.inc, line 9
View source
class ParserIcalDateTimeElement extends FeedsDateTimeElement {
public $repeat_vals = NULL;
/**
* Construct from an iCal VEVENT date array.
*/
public function __construct($feed_element) {
if (empty($feed_element['DTSTART']['datetime'])) {
return;
}
include_once drupal_get_path('module', 'date_api') . '/date_api_ical.inc';
$timezone = $feed_element['DTSTART']['tz'];
if (!empty($timezone)) {
$timezone = new DateTimeZone($timezone);
}
$this->start = new FeedsDateTime($feed_element['DTSTART']['datetime'], $timezone);
if (!empty($feed_element['DTEND']) && !empty($feed_element['DTEND']['datetime'])) {
$this->end = new FeedsDateTime($feed_element['DTEND']['datetime'], $timezone);
}
if ($feed_element['DTSTART']['all_day']) {
// All day event; remove time granularity, set to = from
$this->start
->setTime(0, 0, 0);
$this->start
->removeGranularity('hour');
$this->start
->removeGranularity('minute');
$this->start
->removeGranularity('second');
$this->end = clone $this->start;
}
if (array_key_exists('RRULE', $feed_element) && !empty($feed_element['RRULE']) && module_exists('date_repeat')) {
// Explode the RRULE into parts so we can analyze it.
$rrule = $feed_element['RRULE']['DATA'] . (!empty($feed_element['EXDATE']) ? "/n" . $feed_element['EXDATE'] : "");
// In current API the first variable, $field, is unused--may change?
$form_values = date_ical_parse_rrule(NULL, $rrule);
/**
* Make sure we don't end up with thousands of values with RRULES
* that have no UNTIL or COUNT.
* @todo could be adjusted or made configurable later.
* NOTE: This is not properly timezone converted; that's the least of its
* problems.
*/
$max = date_now();
$max_repeats = 52;
date_modify($max, '+5 years');
$until = date_format($max, 'Y-m-d H:i:s');
if (empty($form_values['COUNT']) && (empty($form_values['UNTIL']) || $until < $form_values['UNTIL']['datetime'])) {
$form_values['UNTIL'] = array(
'datetime' => $until,
'tz' => 'UTC',
);
$form_values['COUNT'] = $max_repeats;
}
elseif (empty($form_values['COUNT'])) {
$form_values['COUNT'] = $max_repeats;
}
elseif (empty($form_values['UNTIL'])) {
$form_values['UNTIL'] = array(
'datetime' => $until,
'tz' => 'UTC',
);
}
// Save these in the form_values format, which date can convert to an
// rrule with date_api_ical_build_rrule()
$this->repeat_vals = $form_values;
}
}
/**
* Overridden merge method to combine two iCal date elements.
* Most of the heavy lifting still handled by parent merge method.
*/
public function merge(FeedsDateTimeElement $other) {
$ret = parent::merge($other);
if ($other instanceof FeedsIcalDateTimeElement && !$ret->repeat_vals && $other->repeat_vals) {
$ret->repeat_vals = $other->repeat_vals;
}
return $ret;
}
/**
* Build a node's date CCK field from our object.
*/
public function buildDateField($node, $field_name) {
parent::buildDateField($node, $field_name);
if (empty($this->repeat_vals)) {
return;
}
if (module_exists('date') && module_exists('date_repeat')) {
include_once './' . drupal_get_path('module', 'date_repeat') . '/date_repeat_calc.inc';
include_once './' . drupal_get_path('module', 'date') . '/date_repeat.inc';
$field = content_fields($field_name);
$node_field = $node->{$field_name}[0];
$values = date_repeat_build_dates(NULL, $this->repeat_vals, $field, $node_field);
$node->{$field_name} = $values;
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
FeedsDateTimeElement:: |
public | property | ||
FeedsDateTimeElement:: |
public | property | ||
FeedsDateTimeElement:: |
public | function |
Override FeedsElement::getValue(). Overrides FeedsElement:: |
|
FeedsDateTimeElement:: |
protected static | function | Helper method for buildDateField(). Build a FeedsDateTimeElement object from a standard formatted node. | |
FeedsDateTimeElement:: |
public | function |
Implementation of toString magic php method. Overrides FeedsElement:: |
|
FeedsElement:: |
protected | property | ||
ParserIcalDateTimeElement:: |
public | property | ||
ParserIcalDateTimeElement:: |
public | function |
Build a node's date CCK field from our object. Overrides FeedsDateTimeElement:: |
|
ParserIcalDateTimeElement:: |
public | function |
Overridden merge method to combine two iCal date elements.
Most of the heavy lifting still handled by parent merge method. Overrides FeedsDateTimeElement:: |
|
ParserIcalDateTimeElement:: |
public | function |
Construct from an iCal VEVENT date array. Overrides FeedsDateTimeElement:: |