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

This class generates birthday calendars. More...

+ Collaboration diagram for Sabre\VObject\BirthdayCalendarGenerator:

Public Member Functions

 __construct ($objects=null)
 Creates the generator. More...
 
 setObjects ($objects)
 Sets the input objects. More...
 
 setFormat ($format)
 Sets the output format for the SUMMARY. More...
 
 getResult ()
 Parses the input data and returns a VCALENDAR. More...
 

Data Fields

const DEFAULT_YEAR = 2000
 Default year. More...
 

Protected Attributes

 $objects = []
 
 $format = '%1$s\'s Birthday'
 

Detailed Description

This class generates birthday calendars.

Author
Dominik Tobschall (http://tobschall.de/) http://sabre.io/license/ Modified BSD License

Definition at line 14 of file BirthdayCalendarGenerator.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\VObject\BirthdayCalendarGenerator::__construct (   $objects = null)

Creates the generator.

Check the setTimeRange and setObjects methods for details about the arguments.

Parameters
mixed$objects

Definition at line 44 of file BirthdayCalendarGenerator.php.

References Sabre\VObject\BirthdayCalendarGenerator\$objects, and Sabre\VObject\BirthdayCalendarGenerator\setObjects().

44  {
45 
46  if ($objects) {
47  $this->setObjects($objects);
48  }
49 
50  }
setObjects($objects)
Sets the input objects.
+ Here is the call graph for this function:

Member Function Documentation

◆ getResult()

Sabre\VObject\BirthdayCalendarGenerator::getResult ( )

Parses the input data and returns a VCALENDAR.

Returns
Component/VCalendar

Definition at line 112 of file BirthdayCalendarGenerator.php.

References $calendar, Sabre\VObject\DateTimeParser\parseVCardDateTime(), and Sabre\VObject\Document\VCARD40.

112  {
113 
114  $calendar = new VCalendar();
115 
116  foreach ($this->objects as $object) {
117 
118  // Skip if there is no BDAY property.
119  if (!$object->select('BDAY')) {
120  continue;
121  }
122 
123  // We've seen clients (ez-vcard) putting "BDAY:" properties
124  // without a value into vCards. If we come across those, we'll
125  // skip them.
126  if (empty($object->BDAY->getValue())) {
127  continue;
128  }
129 
130  // We're always converting to vCard 4.0 so we can rely on the
131  // VCardConverter handling the X-APPLE-OMIT-YEAR property for us.
132  $object = $object->convert(Document::VCARD40);
133 
134  // Skip if the card has no FN property.
135  if (!isset($object->FN)) {
136  continue;
137  }
138 
139  // Skip if the BDAY property is not of the right type.
140  if (!$object->BDAY instanceof Property\VCard\DateAndOrTime) {
141  continue;
142  }
143 
144  // Skip if we can't parse the BDAY value.
145  try {
146  $dateParts = DateTimeParser::parseVCardDateTime($object->BDAY->getValue());
147  } catch (InvalidDataException $e) {
148  continue;
149  }
150 
151  // Set a year if it's not set.
152  $unknownYear = false;
153 
154  if (!$dateParts['year']) {
155  $object->BDAY = self::DEFAULT_YEAR . '-' . $dateParts['month'] . '-' . $dateParts['date'];
156 
157  $unknownYear = true;
158  }
159 
160  // Create event.
161  $event = $calendar->add('VEVENT', [
162  'SUMMARY' => sprintf($this->format, $object->FN->getValue()),
163  'DTSTART' => new \DateTime($object->BDAY->getValue()),
164  'RRULE' => 'FREQ=YEARLY',
165  'TRANSP' => 'TRANSPARENT',
166  ]);
167 
168  // add VALUE=date
169  $event->DTSTART['VALUE'] = 'DATE';
170 
171  // Add X-SABRE-BDAY property.
172  if ($unknownYear) {
173  $event->add('X-SABRE-BDAY', 'BDAY', [
174  'X-SABRE-VCARD-UID' => $object->UID->getValue(),
175  'X-SABRE-VCARD-FN' => $object->FN->getValue(),
176  'X-SABRE-OMIT-YEAR' => self::DEFAULT_YEAR,
177  ]);
178  } else {
179  $event->add('X-SABRE-BDAY', 'BDAY', [
180  'X-SABRE-VCARD-UID' => $object->UID->getValue(),
181  'X-SABRE-VCARD-FN' => $object->FN->getValue(),
182  ]);
183  }
184 
185  }
186 
187  return $calendar;
188 
189  }
const VCARD40
vCard 4.0.
Definition: Document.php:49
static parseVCardDateTime($date)
This method parses a vCard date and or time value.
+ Here is the call graph for this function:

◆ setFormat()

Sabre\VObject\BirthdayCalendarGenerator::setFormat (   $format)

Sets the output format for the SUMMARY.

Parameters
string$format
Returns
void

Definition at line 101 of file BirthdayCalendarGenerator.php.

References Sabre\VObject\BirthdayCalendarGenerator\$format.

101  {
102 
103  $this->format = $format;
104 
105  }

◆ setObjects()

Sabre\VObject\BirthdayCalendarGenerator::setObjects (   $objects)

Sets the input objects.

You must either supply a vCard as a string or as a Component/VCard object. It's also possible to supply an array of strings or objects.

Parameters
mixed$objects
Returns
void

Definition at line 62 of file BirthdayCalendarGenerator.php.

References Sabre\VObject\BirthdayCalendarGenerator\$objects, and Sabre\VObject\Reader\read().

Referenced by Sabre\VObject\BirthdayCalendarGenerator\__construct().

62  {
63 
64  if (!is_array($objects)) {
65  $objects = [$objects];
66  }
67 
68  $this->objects = [];
69  foreach ($objects as $object) {
70 
71  if (is_string($object)) {
72 
73  $vObj = Reader::read($object);
74  if (!$vObj instanceof Component\VCard) {
75  throw new \InvalidArgumentException('String could not be parsed as \\Sabre\\VObject\\Component\\VCard by setObjects');
76  }
77 
78  $this->objects[] = $vObj;
79 
80  } elseif ($object instanceof Component\VCard) {
81 
82  $this->objects[] = $object;
83 
84  } else {
85 
86  throw new \InvalidArgumentException('You can only pass strings or \\Sabre\\VObject\\Component\\VCard arguments to setObjects');
87 
88  }
89 
90  }
91 
92  }
static read($data, $options=0, $charset='UTF-8')
Parses a vCard or iCalendar object, and returns the top component.
Definition: Reader.php:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $format

Sabre\VObject\BirthdayCalendarGenerator::$format = '%1$s\'s Birthday'
protected

◆ $objects

Sabre\VObject\BirthdayCalendarGenerator::$objects = []
protected

◆ DEFAULT_YEAR

const Sabre\VObject\BirthdayCalendarGenerator::DEFAULT_YEAR = 2000

Default year.

Used for dates without a year.

Definition at line 27 of file BirthdayCalendarGenerator.php.


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