Ejemplo n.º 1
0
 /**
  * Call this method on a document if you're done using it.
  *
  * It's intended to remove all circular references, so PHP can easily clean
  * it up.
  *
  * @return void
  */
 function destroy()
 {
     parent::destroy();
     foreach ($this->children as $childGroup) {
         foreach ($childGroup as $child) {
             $child->destroy();
         }
     }
     $this->children = [];
 }
 /**
  * Validates if a component matches the given time range.
  *
  * This is all based on the rules specified in rfc4791, which are quite
  * complex.
  *
  * @param VObject\Node $component
  * @param DateTime $start
  * @param DateTime $end
  * @return bool
  */
 protected function validateTimeRange(VObject\Node $component, $start, $end)
 {
     if (is_null($start)) {
         $start = new DateTime('1900-01-01');
     }
     if (is_null($end)) {
         $end = new DateTime('3000-01-01');
     }
     switch ($component->name) {
         case 'VEVENT':
         case 'VTODO':
         case 'VJOURNAL':
             return $component->isInTimeRange($start, $end);
         case 'VALARM':
             // If the valarm is wrapped in a recurring event, we need to
             // expand the recursions, and validate each.
             //
             // Our datamodel doesn't easily allow us to do this straight
             // in the VALARM component code, so this is a hack, and an
             // expensive one too.
             if ($component->parent->name === 'VEVENT' && $component->parent->RRULE) {
                 // Fire up the iterator!
                 $it = new VObject\RecurrenceIterator($component->parent->parent, (string) $component->parent->UID);
                 while ($it->valid()) {
                     $expandedEvent = $it->getEventObject();
                     // We need to check from these expanded alarms, which
                     // one is the first to trigger. Based on this, we can
                     // determine if we can 'give up' expanding events.
                     $firstAlarm = null;
                     if ($expandedEvent->VALARM !== null) {
                         foreach ($expandedEvent->VALARM as $expandedAlarm) {
                             $effectiveTrigger = $expandedAlarm->getEffectiveTriggerTime();
                             if ($expandedAlarm->isInTimeRange($start, $end)) {
                                 return true;
                             }
                             if ((string) $expandedAlarm->TRIGGER['VALUE'] === 'DATE-TIME') {
                                 // This is an alarm with a non-relative trigger
                                 // time, likely created by a buggy client. The
                                 // implication is that every alarm in this
                                 // recurring event trigger at the exact same
                                 // time. It doesn't make sense to traverse
                                 // further.
                             } else {
                                 // We store the first alarm as a means to
                                 // figure out when we can stop traversing.
                                 if (!$firstAlarm || $effectiveTrigger < $firstAlarm) {
                                     $firstAlarm = $effectiveTrigger;
                                 }
                             }
                         }
                     }
                     if (is_null($firstAlarm)) {
                         // No alarm was found.
                         //
                         // Or technically: No alarm that will change for
                         // every instance of the recurrence was found,
                         // which means we can assume there was no match.
                         return false;
                     }
                     if ($firstAlarm > $end) {
                         return false;
                     }
                     $it->next();
                 }
                 return false;
             } else {
                 return $component->isInTimeRange($start, $end);
             }
         case 'VFREEBUSY':
             throw new \Sabre\DAV\Exception\NotImplemented('time-range filters are currently not supported on ' . $component->name . ' components');
         case 'COMPLETED':
         case 'CREATED':
         case 'DTEND':
         case 'DTSTAMP':
         case 'DTSTART':
         case 'DUE':
         case 'LAST-MODIFIED':
             return $start <= $component->getDateTime() && $end >= $component->getDateTime();
         default:
             throw new \Sabre\DAV\Exception\BadRequest('You cannot create a time-range filter on a ' . $component->name . ' component');
     }
 }
Ejemplo n.º 3
0
 /**
  * Call this method on a document if you're done using it.
  *
  * It's intended to remove all circular references, so PHP can easily clean
  * it up.
  *
  * @return void
  */
 function destroy()
 {
     parent::destroy();
     foreach ($this->parameters as $param) {
         $param->destroy();
     }
     $this->parameters = [];
 }
Ejemplo n.º 4
0
 /**
  * Removes one or more parameters with the specified name.
  *
  * @param string $name
  *
  * @return void
  */
 function offsetUnset($name)
 {
     if (is_int($name)) {
         parent::offsetUnset($name);
         // @codeCoverageIgnoreStart
         // This will never be reached, because an exception is always
         // thrown.
         return;
         // @codeCoverageIgnoreEnd
     }
     unset($this->parameters[strtoupper($name)]);
 }