annotate plugins/libcalendaring/lib/Sabre/VObject/Component/VFreeBusy.php @ 43:771f6803cc4b default tip

somehow lost the correctly updated metadata so e.g. 'mail' package wasn't being imported
author Charlie Root
date Sun, 26 Jan 2025 13:13:49 -0500
parents 888e774ee983
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1 <?php
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
2
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject\Component;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5 use Sabre\VObject;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 * The VFreeBusy component
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 * This component adds functionality to a component, specific for VFREEBUSY
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 * components.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 * @author Evert Pot (http://evertpot.com/)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 class VFreeBusy extends VObject\Component {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 * Checks based on the contained FREEBUSY information, if a timeslot is
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 * available.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 * @param DateTime $start
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 * @param Datetime $end
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25 * @return bool
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 public function isFree(\DateTime $start, \Datetime $end) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29 foreach($this->select('FREEBUSY') as $freebusy) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 // We are only interested in FBTYPE=BUSY (the default),
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 // FBTYPE=BUSY-TENTATIVE or FBTYPE=BUSY-UNAVAILABLE.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33 if (isset($freebusy['FBTYPE']) && strtoupper(substr((string)$freebusy['FBTYPE'],0,4))!=='BUSY') {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 continue;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 // The freebusy component can hold more than 1 value, separated by
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 // commas.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 $periods = explode(',', (string)$freebusy);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41 foreach($periods as $period) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42 // Every period is formatted as [start]/[end]. The start is an
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43 // absolute UTC time, the end may be an absolute UTC time, or
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 // duration (relative) value.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 list($busyStart, $busyEnd) = explode('/', $period);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 $busyStart = VObject\DateTimeParser::parse($busyStart);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 $busyEnd = VObject\DateTimeParser::parse($busyEnd);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 if ($busyEnd instanceof \DateInterval) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50 $tmp = clone $busyStart;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 $tmp->add($busyEnd);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52 $busyEnd = $tmp;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 if($start < $busyEnd && $end > $busyStart) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56 return false;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 return true;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68