ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
Sabre\VObject\Component\VCalendar Class Reference

The VCalendar component. More...

+ Inheritance diagram for Sabre\VObject\Component\VCalendar:
+ Collaboration diagram for Sabre\VObject\Component\VCalendar:

Public Member Functions

static getDocumentType ()
 Returns the current document type. More...
 
 getBaseComponents ($componentName=null)
 Returns a list of all 'base components'. More...
 
 getBaseComponent ($componentName=null)
 Returns the first component that is not a VTIMEZONE, and does not have an RECURRENCE-ID. More...
 
 expand (DateTimeInterface $start, DateTimeInterface $end, DateTimeZone $timeZone=null)
 Expand all events in this VCalendar object and return a new VCalendar with the expanded events. More...
 
 getValidationRules ()
 
 validate ($options=0)
 Validates the node for correctness. More...
 
 getByUID ($uid)
 Returns all components with a specific UID value. More...
 
- Public Member Functions inherited from Sabre\VObject\Document
 __construct ()
 Creates a new document. More...
 
 getDocumentType ()
 Returns the current document type. More...
 
 create ($name)
 Creates a new component or property. More...
 
 createComponent ($name, array $children=null, $defaults=true)
 Creates a new component. More...
 
 createProperty ($name, $value=null, array $parameters=null, $valueType=null)
 Factory method for creating new properties. More...
 
 getClassNameForPropertyValue ($valueParam)
 This method returns a full class-name for a value parameter. More...
 
 getClassNameForPropertyName ($propertyName)
 Returns the default class for a property name. More...
 
- Public Member Functions inherited from Sabre\VObject\Component
 __construct (Document $root, $name, array $children=[], $defaults=true)
 Creates a new component. More...
 
 add ()
 Adds a new property or component, and returns the new item. More...
 
 remove ($item)
 This method removes a component or property from this component. More...
 
 children ()
 Returns a flat list of all the properties and components in this component. More...
 
 getComponents ()
 This method only returns a list of sub-components. More...
 
 select ($name)
 Returns an array with elements that match the specified name. More...
 
 serialize ()
 Turns the object back into a serialized blob. More...
 
 jsonSerialize ()
 This method returns an array, with the representation as it should be encoded in JSON. More...
 
 xmlSerialize (Xml\Writer $writer)
 This method serializes the data into XML. More...
 
 __isset ($name)
 This method checks if a sub-element with the specified name exists. More...
 
 __set ($name, $value)
 Using the setter method you can add properties or subcomponents. More...
 
 __unset ($name)
 Removes all properties and components within this component with the specified name. More...
 
 __clone ()
 This method is automatically called when the object is cloned. More...
 
 getValidationRules ()
 
 validate ($options=0)
 Validates the node for correctness. More...
 
 destroy ()
 Call this method on a document if you're done using it. More...
 
- Public Member Functions inherited from Sabre\VObject\Node
 serialize ()
 Serializes the node into a mimedir format. More...
 
 jsonSerialize ()
 This method returns an array, with the representation as it should be encoded in JSON. More...
 
 xmlSerialize (Xml\Writer $writer)
 This method serializes the data into XML. More...
 
 destroy ()
 Call this method on a document if you're done using it. More...
 
 getIterator ()
 Returns the iterator for this object. More...
 
 setIterator (ElementList $iterator)
 Sets the overridden iterator. More...
 
 validate ($options=0)
 Validates the node for correctness. More...
 
 count ()
 Returns the number of elements. More...
 
 offsetExists ($offset)
 Checks if an item exists through ArrayAccess. More...
 
 offsetGet ($offset)
 Gets an item through ArrayAccess. More...
 
 offsetSet ($offset, $value)
 Sets an item through ArrayAccess. More...
 
 offsetUnset ($offset)
 Sets an item through ArrayAccess. More...
 
- Public Member Functions inherited from Sabre\Xml\XmlSerializable
 xmlSerialize (Writer $writer)
 The xmlSerialize method is called during xml writing. More...
 

Static Public Attributes

static $defaultName = 'VCALENDAR'
 
static $componentMap
 
static $valueMap
 
static $propertyMap
 
- Static Public Attributes inherited from Sabre\VObject\Document
static $defaultName
 
static $propertyMap = []
 
static $componentMap = []
 
static $valueMap = []
 

Protected Member Functions

 getDefaults ()
 This method should return a list of default property values. More...
 
- Protected Member Functions inherited from Sabre\VObject\Component
 getDefaults ()
 This method should return a list of default property values. More...
 

Additional Inherited Members

- Data Fields inherited from Sabre\VObject\Document
const UNKNOWN = 1
 Unknown document type. More...
 
const VCALENDAR10 = 2
 vCalendar 1.0. More...
 
const ICALENDAR20 = 3
 iCalendar 2.0. More...
 
const VCARD21 = 4
 vCard 2.1. More...
 
const VCARD30 = 5
 vCard 3.0. More...
 
const VCARD40 = 6
 vCard 4.0. More...
 
- Data Fields inherited from Sabre\VObject\Component
 $name
 
- Data Fields inherited from Sabre\VObject\Node
const REPAIR = 1
 The following constants are used by the validate() method. More...
 
const PROFILE_CARDDAV = 2
 If this option is set, the validator will operate on the vcards on the assumption that the vcards need to be valid for CardDAV. More...
 
const PROFILE_CALDAV = 4
 If this option is set, the validator will operate on iCalendar objects on the assumption that the vcards need to be valid for CalDAV. More...
 
 $parent
 
- Protected Attributes inherited from Sabre\VObject\Component
 $children = []
 
- Protected Attributes inherited from Sabre\VObject\Node
 $iterator = null
 
 $root
 

Detailed Description

The VCalendar component.

This component adds functionality to a component, specific for a VCALENDAR.

Author
Evert Pot (http://evertpot.com/) http://sabre.io/license/ Modified BSD License

Definition at line 23 of file VCalendar.php.

Member Function Documentation

◆ expand()

Sabre\VObject\Component\VCalendar::expand ( DateTimeInterface  $start,
DateTimeInterface  $end,
DateTimeZone  $timeZone = null 
)

Expand all events in this VCalendar object and return a new VCalendar with the expanded events.

If this calendar object, has events with recurrence rules, this method can be used to expand the event into multiple sub-events.

Each event will be stripped from it's recurrence information, and only the instances of the event in the specified timerange will be left alone.

In addition, this method will cause timezone information to be stripped, and normalized to UTC.

Parameters
DateTimeInterface$start
DateTimeInterface$end
DateTimeZone$timeZonereference timezone for floating dates and times.
Returns
VCalendar

Definition at line 293 of file VCalendar.php.

References $end, $events, $start, $timeZone, Sabre\VObject\Component\children(), and Sabre\VObject\if.

293  {
294 
295  $newChildren = [];
296  $recurringEvents = [];
297 
298  if (!$timeZone) {
299  $timeZone = new DateTimeZone('UTC');
300  }
301 
302  $stripTimezones = function(Component $component) use ($timeZone, &$stripTimezones) {
303 
304  foreach ($component->children() as $componentChild) {
305  if ($componentChild instanceof Property\ICalendar\DateTime && $componentChild->hasTime()) {
306 
307  $dt = $componentChild->getDateTimes($timeZone);
308  // We only need to update the first timezone, because
309  // setDateTimes will match all other timezones to the
310  // first.
311  $dt[0] = $dt[0]->setTimeZone(new DateTimeZone('UTC'));
312  $componentChild->setDateTimes($dt);
313  } elseif ($componentChild instanceof Component) {
314  $stripTimezones($componentChild);
315  }
316 
317  }
318  return $component;
319 
320  };
321 
322  foreach ($this->children() as $child) {
323 
324  if ($child instanceof Property && $child->name !== 'PRODID') {
325  // We explictly want to ignore PRODID, because we want to
326  // overwrite it with our own.
327  $newChildren[] = clone $child;
328  } elseif ($child instanceof Component && $child->name !== 'VTIMEZONE') {
329 
330  // We're also stripping all VTIMEZONE objects because we're
331  // converting everything to UTC.
332  if ($child->name === 'VEVENT' && (isset($child->{'RECURRENCE-ID'}) || isset($child->RRULE) || isset($child->RDATE))) {
333  // Handle these a bit later.
334  $uid = (string)$child->UID;
335  if (!$uid) {
336  throw new InvalidDataException('Every VEVENT object must have a UID property');
337  }
338  if (isset($recurringEvents[$uid])) {
339  $recurringEvents[$uid][] = clone $child;
340  } else {
341  $recurringEvents[$uid] = [clone $child];
342  }
343  } elseif ($child->name === 'VEVENT' && $child->isInTimeRange($start, $end)) {
344  $newChildren[] = $stripTimezones(clone $child);
345  }
346 
347  }
348 
349  }
350 
351  foreach ($recurringEvents as $events) {
352 
353  try {
354  $it = new EventIterator($events, $timeZone);
355 
356  } catch (NoInstancesException $e) {
357  // This event is recurring, but it doesn't have a single
358  // instance. We are skipping this event from the output
359  // entirely.
360  continue;
361  }
362  $it->fastForward($start);
363 
364  while ($it->valid() && $it->getDTStart() < $end) {
365 
366  if ($it->getDTEnd() > $start) {
367 
368  $newChildren[] = $stripTimezones($it->getEventObject());
369 
370  }
371  $it->next();
372 
373  }
374 
375  }
376 
377  return new self($newChildren);
378 
379  }
foreach($paths as $path) if(!class_exists( 'Sabre\\VObject\\Version'))
if($argc< 2) $events
$start
Definition: bench.php:8
children()
Returns a flat list of all the properties and components in this component.
Definition: Component.php:187
+ Here is the call graph for this function:

◆ getBaseComponent()

Sabre\VObject\Component\VCalendar::getBaseComponent (   $componentName = null)

Returns the first component that is not a VTIMEZONE, and does not have an RECURRENCE-ID.

If there is no such component, null will be returned.

Parameters
string$componentNamefilter by component name
Returns
VObject|null

Definition at line 234 of file VCalendar.php.

References Sabre\VObject\Component\children(), and Sabre\VObject\Component\select().

234  {
235 
236  $isBaseComponent = function($component) {
237 
238  if (!$component instanceof VObject\Component) {
239  return false;
240  }
241  if ($component->name === 'VTIMEZONE') {
242  return false;
243  }
244  if (isset($component->{'RECURRENCE-ID'})) {
245  return false;
246  }
247  return true;
248 
249  };
250 
251  if ($componentName) {
252  foreach ($this->select($componentName) as $child) {
253  if ($isBaseComponent($child)) {
254  return $child;
255  }
256  }
257  return null;
258  }
259 
260  // Searching all components
261  foreach ($this->children as $childGroup) {
262  foreach ($childGroup as $child) {
263  if ($isBaseComponent($child)) {
264  return $child;
265  }
266  }
267 
268  }
269  return null;
270 
271  }
select($name)
Returns an array with elements that match the specified name.
Definition: Component.php:231
children()
Returns a flat list of all the properties and components in this component.
Definition: Component.php:187
+ Here is the call graph for this function:

◆ getBaseComponents()

Sabre\VObject\Component\VCalendar::getBaseComponents (   $componentName = null)

Returns a list of all 'base components'.

For instance, if an Event has a recurrence rule, and one instance is overridden, the overridden event will have the same UID, but will be excluded from this list.

VTIMEZONE components will always be excluded.

Parameters
string$componentNamefilter by component name
Returns
VObject[]

Definition at line 178 of file VCalendar.php.

References Sabre\VObject\Component\children(), and Sabre\VObject\Component\select().

178  {
179 
180  $isBaseComponent = function($component) {
181 
182  if (!$component instanceof VObject\Component) {
183  return false;
184  }
185  if ($component->name === 'VTIMEZONE') {
186  return false;
187  }
188  if (isset($component->{'RECURRENCE-ID'})) {
189  return false;
190  }
191  return true;
192 
193  };
194 
195  if ($componentName) {
196  // Early exit
197  return array_filter(
198  $this->select($componentName),
199  $isBaseComponent
200  );
201  }
202 
203  $components = [];
204  foreach ($this->children as $childGroup) {
205 
206  foreach ($childGroup as $child) {
207 
208  if (!$child instanceof Component) {
209  // If one child is not a component, they all are so we skip
210  // the entire group.
211  continue 2;
212  }
213  if ($isBaseComponent($child)) {
214  $components[] = $child;
215  }
216 
217  }
218 
219  }
220  return $components;
221 
222  }
select($name)
Returns an array with elements that match the specified name.
Definition: Component.php:231
children()
Returns a flat list of all the properties and components in this component.
Definition: Component.php:187
+ Here is the call graph for this function:

◆ getByUID()

Sabre\VObject\Component\VCalendar::getByUID (   $uid)

Returns all components with a specific UID value.

Returns
array

Definition at line 546 of file VCalendar.php.

References Sabre\VObject\Component\getComponents().

546  {
547 
548  return array_filter($this->getComponents(), function($item) use ($uid) {
549 
550  if (!$itemUid = $item->select('UID')) {
551  return false;
552  }
553  $itemUid = current($itemUid)->getValue();
554  return $uid === $itemUid;
555 
556  });
557 
558  }
getComponents()
This method only returns a list of sub-components.
Definition: Component.php:203
+ Here is the call graph for this function:

◆ getDefaults()

Sabre\VObject\Component\VCalendar::getDefaults ( )
protected

This method should return a list of default property values.

Returns
array

Definition at line 386 of file VCalendar.php.

References Sabre\VObject\Version\VERSION.

386  {
387 
388  return [
389  'VERSION' => '2.0',
390  'PRODID' => '-//Sabre//Sabre VObject ' . VObject\Version::VERSION . '//EN',
391  'CALSCALE' => 'GREGORIAN',
392  ];
393 
394  }
const VERSION
Full version number.
Definition: Version.php:17

◆ getDocumentType()

static Sabre\VObject\Component\VCalendar::getDocumentType ( )

Returns the current document type.

Returns
int

Definition at line 161 of file VCalendar.php.

161  {
162 
163  return self::ICALENDAR20;
164 
165  }

◆ getValidationRules()

Sabre\VObject\Component\VCalendar::getValidationRules ( )

Definition at line 411 of file VCalendar.php.

411  {
412 
413  return [
414  'PRODID' => 1,
415  'VERSION' => 1,
416 
417  'CALSCALE' => '?',
418  'METHOD' => '?',
419  ];
420 
421  }

◆ validate()

Sabre\VObject\Component\VCalendar::validate (   $options = 0)

Validates the node for correctness.

The following options are supported: Node::REPAIR - May attempt to automatically repair the problem. Node::PROFILE_CARDDAV - Validate the vCard for CardDAV purposes. Node::PROFILE_CALDAV - Validate the iCalendar for CalDAV purposes.

This method returns an array with detected problems. Every element has the following properties:

  • level - problem level.
  • message - A human-readable string describing the issue.
  • node - A reference to the problematic node.

The level means: 1 - The issue was repaired (only happens if REPAIR was turned on). 2 - A warning. 3 - An error.

Parameters
int$options
Returns
array

Definition at line 447 of file VCalendar.php.

References PHPMailer\PHPMailer\$options, $warnings, Sabre\VObject\Component\children(), and Sabre\VObject\Node\count().

447  {
448 
449  $warnings = parent::validate($options);
450 
451  if ($ver = $this->VERSION) {
452  if ((string)$ver !== '2.0') {
453  $warnings[] = [
454  'level' => 3,
455  'message' => 'Only iCalendar version 2.0 as defined in rfc5545 is supported.',
456  'node' => $this,
457  ];
458  }
459 
460  }
461 
462  $uidList = [];
463  $componentsFound = 0;
464  $componentTypes = [];
465 
466  foreach ($this->children() as $child) {
467  if ($child instanceof Component) {
468  $componentsFound++;
469 
470  if (!in_array($child->name, ['VEVENT', 'VTODO', 'VJOURNAL'])) {
471  continue;
472  }
473  $componentTypes[] = $child->name;
474 
475  $uid = (string)$child->UID;
476  $isMaster = isset($child->{'RECURRENCE-ID'}) ? 0 : 1;
477  if (isset($uidList[$uid])) {
478  $uidList[$uid]['count']++;
479  if ($isMaster && $uidList[$uid]['hasMaster']) {
480  $warnings[] = [
481  'level' => 3,
482  'message' => 'More than one master object was found for the object with UID ' . $uid,
483  'node' => $this,
484  ];
485  }
486  $uidList[$uid]['hasMaster'] += $isMaster;
487  } else {
488  $uidList[$uid] = [
489  'count' => 1,
490  'hasMaster' => $isMaster,
491  ];
492  }
493 
494  }
495  }
496 
497  if ($componentsFound === 0) {
498  $warnings[] = [
499  'level' => 3,
500  'message' => 'An iCalendar object must have at least 1 component.',
501  'node' => $this,
502  ];
503  }
504 
505  if ($options & self::PROFILE_CALDAV) {
506  if (count($uidList) > 1) {
507  $warnings[] = [
508  'level' => 3,
509  'message' => 'A calendar object on a CalDAV server may only have components with the same UID.',
510  'node' => $this,
511  ];
512  }
513  if (count($componentTypes) === 0) {
514  $warnings[] = [
515  'level' => 3,
516  'message' => 'A calendar object on a CalDAV server must have at least 1 component (VTODO, VEVENT, VJOURNAL).',
517  'node' => $this,
518  ];
519  }
520  if (count(array_unique($componentTypes)) > 1) {
521  $warnings[] = [
522  'level' => 3,
523  'message' => 'A calendar object on a CalDAV server may only have 1 type of component (VEVENT, VTODO or VJOURNAL).',
524  'node' => $this,
525  ];
526  }
527 
528  if (isset($this->METHOD)) {
529  $warnings[] = [
530  'level' => 3,
531  'message' => 'A calendar object on a CalDAV server MUST NOT have a METHOD property.',
532  'node' => $this,
533  ];
534  }
535  }
536 
537  return $warnings;
538 
539  }
count()
Returns the number of elements.
Definition: Node.php:177
children()
Returns a flat list of all the properties and components in this component.
Definition: Component.php:187
+ Here is the call graph for this function:

Field Documentation

◆ $componentMap

Sabre\VObject\Component\VCalendar::$componentMap
static
Initial value:
= [
'VCALENDAR' => 'Sabre\\VObject\\Component\\VCalendar'

Definition at line 39 of file VCalendar.php.

Referenced by Sabre\VObject\Parser\MimeDir\parseDocument().

◆ $defaultName

Sabre\VObject\Component\VCalendar::$defaultName = 'VCALENDAR'
static

Definition at line 32 of file VCalendar.php.

◆ $propertyMap

Sabre\VObject\Component\VCalendar::$propertyMap
static
Initial value:
= [
'CALSCALE' => 'Sabre\\VObject\\Property\\FlatText'

Definition at line 79 of file VCalendar.php.

◆ $valueMap

Sabre\VObject\Component\VCalendar::$valueMap
static
Initial value:
= [
'BINARY' => 'Sabre\\VObject\\Property\\Binary'

Definition at line 56 of file VCalendar.php.


The documentation for this class was generated from the following file: