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

FreeBusyData is a helper class that manages freebusy information. More...

+ Collaboration diagram for Sabre\VObject\FreeBusyData:

Public Member Functions

 __construct ($start, $end)
 
 add ($start, $end, $type)
 Adds free or busytime to the data. More...
 
 getData ()
 

Protected Attributes

 $start
 
 $end
 
 $data
 

Detailed Description

FreeBusyData is a helper class that manages freebusy information.

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

Definition at line 12 of file FreeBusyData.php.

Constructor & Destructor Documentation

◆ __construct()

Sabre\VObject\FreeBusyData::__construct (   $start,
  $end 
)

Definition at line 35 of file FreeBusyData.php.

35 {
36
37 $this->start = $start;
38 $this->end = $end;
39 $this->data = [];
40
41 $this->data[] = [
42 'start' => $this->start,
43 'end' => $this->end,
44 'type' => 'FREE',
45 ];
46
47 }
$this data['403_header']

References Sabre\VObject\FreeBusyData\$end, Sabre\VObject\FreeBusyData\$start, and data.

Member Function Documentation

◆ add()

Sabre\VObject\FreeBusyData::add (   $start,
  $end,
  $type 
)

Adds free or busytime to the data.

Parameters
int$start
int$end
string$typeFREE, BUSY, BUSY-UNAVAILABLE or BUSY-TENTATIVE
Returns
void

Definition at line 57 of file FreeBusyData.php.

57 {
58
59 if ($start > $this->end || $end < $this->start) {
60
61 // This new data is outside our timerange.
62 return;
63
64 }
65
66 if ($start < $this->start) {
67 // The item starts before our requested time range
69 }
70 if ($end > $this->end) {
71 // The item ends after our requested time range
73 }
74
75 // Finding out where we need to insert the new item.
76 $currentIndex = 0;
77 while ($start > $this->data[$currentIndex]['end']) {
78 $currentIndex++;
79 }
80
81 // The standard insertion point will be one _after_ the first
82 // overlapping item.
83 $insertStartIndex = $currentIndex + 1;
84
85 $newItem = [
86 'start' => $start,
87 'end' => $end,
88 'type' => $type,
89 ];
90
91 $preceedingItem = $this->data[$insertStartIndex - 1];
92 if ($this->data[$insertStartIndex - 1]['start'] === $start) {
93 // The old item starts at the exact same point as the new item.
94 $insertStartIndex--;
95 }
96
97 // Now we know where to insert the item, we need to know where it
98 // starts overlapping with items on the tail end. We need to start
99 // looking one item before the insertStartIndex, because it's possible
100 // that the new item 'sits inside' the previous old item.
101 if ($insertStartIndex > 0) {
102 $currentIndex = $insertStartIndex - 1;
103 } else {
104 $currentIndex = 0;
105 }
106
107 while ($end > $this->data[$currentIndex]['end']) {
108
109 $currentIndex++;
110
111 }
112
113 // What we are about to insert into the array
114 $newItems = [
115 $newItem
116 ];
117
118 // This is the amount of items that are completely overwritten by the
119 // new item.
120 $itemsToDelete = $currentIndex - $insertStartIndex;
121 if ($this->data[$currentIndex]['end'] <= $end) $itemsToDelete++;
122
123 // If itemsToDelete was -1, it means that the newly inserted item is
124 // actually sitting inside an existing one. This means we need to split
125 // the item at the current position in two and insert the new item in
126 // between.
127 if ($itemsToDelete === -1) {
128 $itemsToDelete = 0;
129 if ($newItem['end'] < $preceedingItem['end']) {
130 $newItems[] = [
131 'start' => $newItem['end'] + 1,
132 'end' => $preceedingItem['end'],
133 'type' => $preceedingItem['type']
134 ];
135 }
136 }
137
138 array_splice(
139 $this->data,
140 $insertStartIndex,
141 $itemsToDelete,
142 $newItems
143 );
144
145 $doMerge = false;
146 $mergeOffset = $insertStartIndex;
147 $mergeItem = $newItem;
148 $mergeDelete = 1;
149
150 if (isset($this->data[$insertStartIndex - 1])) {
151 // Updating the start time of the previous item.
152 $this->data[$insertStartIndex - 1]['end'] = $start;
153
154 // If the previous and the current are of the same type, we can
155 // merge them into one item.
156 if ($this->data[$insertStartIndex - 1]['type'] === $this->data[$insertStartIndex]['type']) {
157 $doMerge = true;
158 $mergeOffset--;
159 $mergeDelete++;
160 $mergeItem['start'] = $this->data[$insertStartIndex - 1]['start'];
161 }
162 }
163 if (isset($this->data[$insertStartIndex + 1])) {
164 // Updating the start time of the next item.
165 $this->data[$insertStartIndex + 1]['start'] = $end;
166
167 // If the next and the current are of the same type, we can
168 // merge them into one item.
169 if ($this->data[$insertStartIndex + 1]['type'] === $this->data[$insertStartIndex]['type']) {
170 $doMerge = true;
171 $mergeDelete++;
172 $mergeItem['end'] = $this->data[$insertStartIndex + 1]['end'];
173 }
174
175 }
176 if ($doMerge) {
177 array_splice(
178 $this->data,
179 $mergeOffset,
180 $mergeDelete,
181 [$mergeItem]
182 );
183 }
184
185 }
$type

References Sabre\VObject\FreeBusyData\$end, Sabre\VObject\FreeBusyData\$start, $type, and data.

Referenced by Sabre\VObject\FreeBusyGenerator\calculateAvailability(), and Sabre\VObject\FreeBusyGenerator\calculateBusy().

+ Here is the caller graph for this function:

◆ getData()

Sabre\VObject\FreeBusyData::getData ( )

Definition at line 187 of file FreeBusyData.php.

187 {
188
189 return $this->data;
190
191 }

References Sabre\VObject\FreeBusyData\$data.

Referenced by Sabre\VObject\FreeBusyGenerator\generateFreeBusyCalendar().

+ Here is the caller graph for this function:

Field Documentation

◆ $data

Sabre\VObject\FreeBusyData::$data
protected

Definition at line 33 of file FreeBusyData.php.

Referenced by Sabre\VObject\FreeBusyData\getData().

◆ $end

Sabre\VObject\FreeBusyData::$end
protected

◆ $start

Sabre\VObject\FreeBusyData::$start
protected

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