annotate vendor/sabre/vobject/lib/Component/VFreeBusy.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject\Component;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 use Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 * The VFreeBusy component
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 * This component adds functionality to a component, specific for VFREEBUSY
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 * components.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 class VFreeBusy extends VObject\Component {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 * Checks based on the contained FREEBUSY information, if a timeslot is
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 * available.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 * @param DateTime $start
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 * @param Datetime $end
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 * @return bool
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27 public function isFree(\DateTime $start, \Datetime $end) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 foreach($this->select('FREEBUSY') as $freebusy) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 // We are only interested in FBTYPE=BUSY (the default),
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 // FBTYPE=BUSY-TENTATIVE or FBTYPE=BUSY-UNAVAILABLE.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 if (isset($freebusy['FBTYPE']) && strtoupper(substr((string)$freebusy['FBTYPE'],0,4))!=='BUSY') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 continue;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 // The freebusy component can hold more than 1 value, separated by
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 // commas.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 $periods = explode(',', (string)$freebusy);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41 foreach($periods as $period) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 // Every period is formatted as [start]/[end]. The start is an
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 // absolute UTC time, the end may be an absolute UTC time, or
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 // duration (relative) value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 list($busyStart, $busyEnd) = explode('/', $period);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 $busyStart = VObject\DateTimeParser::parse($busyStart);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 $busyEnd = VObject\DateTimeParser::parse($busyEnd);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 if ($busyEnd instanceof \DateInterval) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 $tmp = clone $busyStart;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 $tmp->add($busyEnd);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 $busyEnd = $tmp;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 if($start < $busyEnd && $end > $busyStart) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 return false;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 return true;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 * A simple list of validation rules.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 * This is simply a list of properties, and how many times they either
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 * must or must not appear.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 * Possible values per property:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 * * 0 - Must not appear.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 * * 1 - Must appear exactly once.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 * * + - Must appear at least once.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 * * * - Can appear any number of times.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 * @var array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 public function getValidationRules() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83 return array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 'UID' => 1,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 'DTSTAMP' => 1,
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 'CONTACT' => '?',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 'DTSTART' => '?',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 'DTEND' => '?',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 'ORGANIZER' => '?',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 'URL' => '?',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 'ATTENDEE' => '*',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 'COMMENT' => '*',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95 'FREEBUSY' => '*',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 'REQUEST-STATUS' => '*',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102