aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/sabre/vobject/lib/FreeBusyGenerator.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/sabre/vobject/lib/FreeBusyGenerator.php')
-rw-r--r--vendor/sabre/vobject/lib/FreeBusyGenerator.php220
1 files changed, 88 insertions, 132 deletions
diff --git a/vendor/sabre/vobject/lib/FreeBusyGenerator.php b/vendor/sabre/vobject/lib/FreeBusyGenerator.php
index e30b136c4..adb214c08 100644
--- a/vendor/sabre/vobject/lib/FreeBusyGenerator.php
+++ b/vendor/sabre/vobject/lib/FreeBusyGenerator.php
@@ -23,8 +23,8 @@ use Sabre\VObject\Recur\NoInstancesException;
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
-class FreeBusyGenerator {
-
+class FreeBusyGenerator
+{
/**
* Input objects.
*
@@ -71,7 +71,7 @@ class FreeBusyGenerator {
/**
* A VAVAILABILITY document.
*
- * If this is set, it's information will be included when calculating
+ * If this is set, its information will be included when calculating
* freebusy time.
*
* @var Document
@@ -86,11 +86,11 @@ class FreeBusyGenerator {
*
* @param DateTimeInterface $start
* @param DateTimeInterface $end
- * @param mixed $objects
- * @param DateTimeZone $timeZone
+ * @param mixed $objects
+ * @param DateTimeZone $timeZone
*/
- function __construct(DateTimeInterface $start = null, DateTimeInterface $end = null, $objects = null, DateTimeZone $timeZone = null) {
-
+ public function __construct(DateTimeInterface $start = null, DateTimeInterface $end = null, $objects = null, DateTimeZone $timeZone = null)
+ {
$this->setTimeRange($start, $end);
if ($objects) {
@@ -100,7 +100,6 @@ class FreeBusyGenerator {
$timeZone = new DateTimeZone('UTC');
}
$this->setTimeZone($timeZone);
-
}
/**
@@ -112,24 +111,20 @@ class FreeBusyGenerator {
* The VFREEBUSY object will be automatically added though.
*
* @param Document $vcalendar
- * @return void
*/
- function setBaseObject(Document $vcalendar) {
-
+ public function setBaseObject(Document $vcalendar)
+ {
$this->baseObject = $vcalendar;
-
}
/**
* Sets a VAVAILABILITY document.
*
* @param Document $vcalendar
- * @return void
*/
- function setVAvailability(Document $vcalendar) {
-
+ public function setVAvailability(Document $vcalendar)
+ {
$this->vavailability = $vcalendar;
-
}
/**
@@ -140,18 +135,15 @@ class FreeBusyGenerator {
* It's also possible to specify multiple objects as an array.
*
* @param mixed $objects
- *
- * @return void
*/
- function setObjects($objects) {
-
+ public function setObjects($objects)
+ {
if (!is_array($objects)) {
$objects = [$objects];
}
$this->objects = [];
foreach ($objects as $object) {
-
if (is_string($object) || is_resource($object)) {
$this->objects[] = Reader::read($object);
} elseif ($object instanceof Component) {
@@ -159,9 +151,7 @@ class FreeBusyGenerator {
} else {
throw new \InvalidArgumentException('You can only pass strings or \\Sabre\\VObject\\Component arguments to setObjects');
}
-
}
-
}
/**
@@ -171,11 +161,9 @@ class FreeBusyGenerator {
*
* @param DateTimeInterface $start
* @param DateTimeInterface $end
- *
- * @return void
*/
- function setTimeRange(DateTimeInterface $start = null, DateTimeInterface $end = null) {
-
+ public function setTimeRange(DateTimeInterface $start = null, DateTimeInterface $end = null)
+ {
if (!$start) {
$start = new DateTimeImmutable(Settings::$minDate);
}
@@ -184,20 +172,16 @@ class FreeBusyGenerator {
}
$this->start = $start;
$this->end = $end;
-
}
/**
* Sets the reference timezone for floating times.
*
* @param DateTimeZone $timeZone
- *
- * @return void
*/
- function setTimeZone(DateTimeZone $timeZone) {
-
+ public function setTimeZone(DateTimeZone $timeZone)
+ {
$this->timeZone = $timeZone;
-
}
/**
@@ -206,23 +190,19 @@ class FreeBusyGenerator {
*
* @return Component
*/
- function getResult() {
-
+ public function getResult()
+ {
$fbData = new FreeBusyData(
$this->start->getTimeStamp(),
$this->end->getTimeStamp()
);
if ($this->vavailability) {
-
$this->calculateAvailability($fbData, $this->vavailability);
-
}
$this->calculateBusy($fbData, $this->objects);
return $this->generateFreeBusyCalendar($fbData);
-
-
}
/**
@@ -230,29 +210,30 @@ class FreeBusyGenerator {
* available times.
*
* @param FreeBusyData $fbData
- * @param VCalendar $vavailability
- * @return void
+ * @param VCalendar $vavailability
*/
- protected function calculateAvailability(FreeBusyData $fbData, VCalendar $vavailability) {
-
+ protected function calculateAvailability(FreeBusyData $fbData, VCalendar $vavailability)
+ {
$vavailComps = iterator_to_array($vavailability->VAVAILABILITY);
usort(
$vavailComps,
- function($a, $b) {
-
+ function ($a, $b) {
// We need to order the components by priority. Priority 1
// comes first, up until priority 9. Priority 0 comes after
// priority 9. No priority implies priority 0.
//
// Yes, I'm serious.
- $priorityA = isset($a->PRIORITY) ? (int)$a->PRIORITY->getValue() : 0;
- $priorityB = isset($b->PRIORITY) ? (int)$b->PRIORITY->getValue() : 0;
+ $priorityA = isset($a->PRIORITY) ? (int) $a->PRIORITY->getValue() : 0;
+ $priorityB = isset($b->PRIORITY) ? (int) $b->PRIORITY->getValue() : 0;
- if ($priorityA === 0) $priorityA = 10;
- if ($priorityB === 0) $priorityB = 10;
+ if (0 === $priorityA) {
+ $priorityA = 10;
+ }
+ if (0 === $priorityB) {
+ $priorityB = 10;
+ }
return $priorityA - $priorityB;
-
}
);
@@ -267,7 +248,6 @@ class FreeBusyGenerator {
$new = [];
foreach ($old as $vavail) {
-
list($compStart, $compEnd) = $vavail->getEffectiveStartEnd();
// We don't care about datetimes that are earlier or later than the
@@ -288,24 +268,19 @@ class FreeBusyGenerator {
// Going through our existing list of components to see if there's
// a higher priority component that already fully covers this one.
foreach ($new as $higherVavail) {
-
list($higherStart, $higherEnd) = $higherVavail->getEffectiveStartEnd();
if (
(is_null($higherStart) || $higherStart < $compStart) &&
(is_null($higherEnd) || $higherEnd > $compEnd)
) {
-
// Component is fully covered by a higher priority
// component. We can skip this component.
continue 2;
-
}
-
}
// We're keeping it!
$new[] = $vavail;
-
}
// Lastly, we need to traverse the remaining components and fill in the
@@ -314,7 +289,6 @@ class FreeBusyGenerator {
// We traverse the components in reverse, because we want the higher
// priority components to override the lower ones.
foreach (array_reverse($new) as $vavail) {
-
$busyType = isset($vavail->BUSYTYPE) ? strtoupper($vavail->BUSYTYPE) : 'BUSY-UNAVAILABLE';
list($vavailStart, $vavailEnd) = $vavail->getEffectiveStartEnd();
@@ -336,57 +310,53 @@ class FreeBusyGenerator {
);
// Looping over the AVAILABLE components.
- if (isset($vavail->AVAILABLE)) foreach ($vavail->AVAILABLE as $available) {
-
- list($availStart, $availEnd) = $available->getEffectiveStartEnd();
- $fbData->add(
+ if (isset($vavail->AVAILABLE)) {
+ foreach ($vavail->AVAILABLE as $available) {
+ list($availStart, $availEnd) = $available->getEffectiveStartEnd();
+ $fbData->add(
$availStart->getTimeStamp(),
$availEnd->getTimeStamp(),
'FREE'
);
- if ($available->RRULE) {
- // Our favourite thing: recurrence!!
+ if ($available->RRULE) {
+ // Our favourite thing: recurrence!!
- $rruleIterator = new Recur\RRuleIterator(
+ $rruleIterator = new Recur\RRuleIterator(
$available->RRULE->getValue(),
$availStart
);
- $rruleIterator->fastForward($vavailStart);
+ $rruleIterator->fastForward($vavailStart);
- $startEndDiff = $availStart->diff($availEnd);
+ $startEndDiff = $availStart->diff($availEnd);
- while ($rruleIterator->valid()) {
+ while ($rruleIterator->valid()) {
+ $recurStart = $rruleIterator->current();
+ $recurEnd = $recurStart->add($startEndDiff);
- $recurStart = $rruleIterator->current();
- $recurEnd = $recurStart->add($startEndDiff);
-
- if ($recurStart > $vavailEnd) {
- // We're beyond the legal timerange.
- break;
- }
+ if ($recurStart > $vavailEnd) {
+ // We're beyond the legal timerange.
+ break;
+ }
- if ($recurEnd > $vavailEnd) {
- // Truncating the end if it exceeds the
- // VAVAILABILITY end.
- $recurEnd = $vavailEnd;
- }
+ if ($recurEnd > $vavailEnd) {
+ // Truncating the end if it exceeds the
+ // VAVAILABILITY end.
+ $recurEnd = $vavailEnd;
+ }
- $fbData->add(
+ $fbData->add(
$recurStart->getTimeStamp(),
$recurEnd->getTimeStamp(),
'FREE'
);
- $rruleIterator->next();
-
+ $rruleIterator->next();
+ }
}
}
-
}
-
}
-
}
/**
@@ -394,28 +364,25 @@ class FreeBusyGenerator {
* times on fbData.
*
* @param FreeBusyData $fbData
- * @param VCalendar[] $objects
+ * @param VCalendar[] $objects
*/
- protected function calculateBusy(FreeBusyData $fbData, array $objects) {
-
+ protected function calculateBusy(FreeBusyData $fbData, array $objects)
+ {
foreach ($objects as $key => $object) {
-
foreach ($object->getBaseComponents() as $component) {
-
switch ($component->name) {
-
- case 'VEVENT' :
+ case 'VEVENT':
$FBTYPE = 'BUSY';
- if (isset($component->TRANSP) && (strtoupper($component->TRANSP) === 'TRANSPARENT')) {
+ if (isset($component->TRANSP) && ('TRANSPARENT' === strtoupper($component->TRANSP))) {
break;
}
if (isset($component->STATUS)) {
$status = strtoupper($component->STATUS);
- if ($status === 'CANCELLED') {
+ if ('CANCELLED' === $status) {
break;
}
- if ($status === 'TENTATIVE') {
+ if ('TENTATIVE' === $status) {
$FBTYPE = 'BUSY-TENTATIVE';
}
}
@@ -424,13 +391,13 @@ class FreeBusyGenerator {
if ($component->RRULE) {
try {
- $iterator = new EventIterator($object, (string)$component->UID, $this->timeZone);
+ $iterator = new EventIterator($object, (string) $component->UID, $this->timeZone);
} catch (NoInstancesException $e) {
// This event is recurring, but it doesn't have a single
// instance. We are skipping this event from the output
// entirely.
unset($this->objects[$key]);
- continue;
+ break;
}
if ($this->start) {
@@ -440,7 +407,6 @@ class FreeBusyGenerator {
$maxRecurrences = Settings::$maxRecurrences;
while ($iterator->valid() && --$maxRecurrences) {
-
$startTime = $iterator->getDTStart();
if ($this->end && $startTime > $this->end) {
break;
@@ -451,11 +417,8 @@ class FreeBusyGenerator {
];
$iterator->next();
-
}
-
} else {
-
$startTime = $component->DTSTART->getDateTime($this->timeZone);
if ($this->end && $startTime > $this->end) {
break;
@@ -464,7 +427,7 @@ class FreeBusyGenerator {
if (isset($component->DTEND)) {
$endTime = $component->DTEND->getDateTime($this->timeZone);
} elseif (isset($component->DURATION)) {
- $duration = DateTimeParser::parseDuration((string)$component->DURATION);
+ $duration = DateTimeParser::parseDuration((string) $component->DURATION);
$endTime = clone $startTime;
$endTime = $endTime->add($duration);
} elseif (!$component->DTSTART->hasTime()) {
@@ -476,13 +439,15 @@ class FreeBusyGenerator {
}
$times[] = [$startTime, $endTime];
-
}
foreach ($times as $time) {
-
- if ($this->end && $time[0] > $this->end) break;
- if ($this->start && $time[1] < $this->start) break;
+ if ($this->end && $time[0] > $this->end) {
+ break;
+ }
+ if ($this->start && $time[1] < $this->start) {
+ break;
+ }
$fbData->add(
$time[0]->getTimeStamp(),
@@ -492,21 +457,21 @@ class FreeBusyGenerator {
}
break;
- case 'VFREEBUSY' :
+ case 'VFREEBUSY':
foreach ($component->FREEBUSY as $freebusy) {
-
$fbType = isset($freebusy['FBTYPE']) ? strtoupper($freebusy['FBTYPE']) : 'BUSY';
// Skipping intervals marked as 'free'
- if ($fbType === 'FREE')
+ if ('FREE' === $fbType) {
continue;
+ }
$values = explode(',', $freebusy);
foreach ($values as $value) {
list($startTime, $endTime) = explode('/', $value);
$startTime = DateTimeParser::parseDateTime($startTime);
- if (substr($endTime, 0, 1) === 'P' || substr($endTime, 0, 2) === '-P') {
+ if ('P' === substr($endTime, 0, 1) || '-P' === substr($endTime, 0, 2)) {
$duration = DateTimeParser::parseDuration($endTime);
$endTime = clone $startTime;
$endTime = $endTime->add($duration);
@@ -514,27 +479,23 @@ class FreeBusyGenerator {
$endTime = DateTimeParser::parseDateTime($endTime);
}
- if ($this->start && $this->start > $endTime) continue;
- if ($this->end && $this->end < $startTime) continue;
+ if ($this->start && $this->start > $endTime) {
+ continue;
+ }
+ if ($this->end && $this->end < $startTime) {
+ continue;
+ }
$fbData->add(
$startTime->getTimeStamp(),
$endTime->getTimeStamp(),
$fbType
);
-
}
-
-
}
break;
-
}
-
-
}
-
}
-
}
/**
@@ -543,8 +504,8 @@ class FreeBusyGenerator {
*
* @return VCalendar
*/
- protected function generateFreeBusyCalendar(FreeBusyData $fbData) {
-
+ protected function generateFreeBusyCalendar(FreeBusyData $fbData)
+ {
if ($this->baseObject) {
$calendar = $this->baseObject;
} else {
@@ -571,34 +532,29 @@ class FreeBusyGenerator {
$vfreebusy->add($dtstamp);
foreach ($fbData->getData() as $busyTime) {
-
$busyType = strtoupper($busyTime['type']);
// Ignoring all the FREE parts, because those are already assumed.
- if ($busyType === 'FREE') {
+ if ('FREE' === $busyType) {
continue;
}
- $busyTime[0] = new \DateTimeImmutable('@' . $busyTime['start'], $tz);
- $busyTime[1] = new \DateTimeImmutable('@' . $busyTime['end'], $tz);
+ $busyTime[0] = new \DateTimeImmutable('@'.$busyTime['start'], $tz);
+ $busyTime[1] = new \DateTimeImmutable('@'.$busyTime['end'], $tz);
$prop = $calendar->createProperty(
'FREEBUSY',
- $busyTime[0]->format('Ymd\\THis\\Z') . '/' . $busyTime[1]->format('Ymd\\THis\\Z')
+ $busyTime[0]->format('Ymd\\THis\\Z').'/'.$busyTime[1]->format('Ymd\\THis\\Z')
);
// Only setting FBTYPE if it's not BUSY, because BUSY is the
// default anyway.
- if ($busyType !== 'BUSY') {
+ if ('BUSY' !== $busyType) {
$prop['FBTYPE'] = $busyType;
}
$vfreebusy->add($prop);
-
}
return $calendar;
-
-
}
-
}