Blame view

sources/3rdparty/sabre/vobject/lib/Sabre/VObject/Component/VCalendar.php 7.18 KB
03e52840d   Kload   Init
1
2
3
4
5
6
7
8
9
10
  <?php
  
  namespace Sabre\VObject\Component;
  
  use Sabre\VObject;
  
  /**
   * The VCalendar component
   *
   * This component adds functionality to a component, specific for a VCALENDAR.
6d9380f96   Cédric Dupont   Update sources OC...
11
12
13
   *
   * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
   * @author Evert Pot (http://evertpot.com/)
03e52840d   Kload   Init
14
15
   * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
   */
6d9380f96   Cédric Dupont   Update sources OC...
16
17
18
  class VCalendar extends VObject\Document {
  
      static $defaultName = 'VCALENDAR';
03e52840d   Kload   Init
19
20
  
      /**
6d9380f96   Cédric Dupont   Update sources OC...
21
22
       * Returns a list of all 'base components'. For instance, if an Event has
       * a recurrence rule, and one instance is overridden, the overridden event
03e52840d   Kload   Init
23
24
       * will have the same UID, but will be excluded from this list.
       *
6d9380f96   Cédric Dupont   Update sources OC...
25
       * VTIMEZONE components will always be excluded.
03e52840d   Kload   Init
26
       *
6d9380f96   Cédric Dupont   Update sources OC...
27
28
       * @param string $componentName filter by component name
       * @return array
03e52840d   Kload   Init
29
30
31
32
33
34
35
36
       */
      public function getBaseComponents($componentName = null) {
  
          $components = array();
          foreach($this->children as $component) {
  
              if (!$component instanceof VObject\Component)
                  continue;
6d9380f96   Cédric Dupont   Update sources OC...
37
              if (isset($component->{'RECURRENCE-ID'}))
03e52840d   Kload   Init
38
                  continue;
6d9380f96   Cédric Dupont   Update sources OC...
39
              if ($componentName && $component->name !== strtoupper($componentName))
03e52840d   Kload   Init
40
41
42
43
44
45
46
47
48
49
50
51
52
53
                  continue;
  
              if ($component->name === 'VTIMEZONE')
                  continue;
  
              $components[] = $component;
  
          }
  
          return $components;
  
      }
  
      /**
6d9380f96   Cédric Dupont   Update sources OC...
54
       * If this calendar object, has events with recurrence rules, this method
03e52840d   Kload   Init
55
56
       * can be used to expand the event into multiple sub-events.
       *
6d9380f96   Cédric Dupont   Update sources OC...
57
58
       * Each event will be stripped from it's recurrence information, and only
       * the instances of the event in the specified timerange will be left
03e52840d   Kload   Init
59
60
       * alone.
       *
6d9380f96   Cédric Dupont   Update sources OC...
61
       * In addition, this method will cause timezone information to be stripped,
03e52840d   Kload   Init
62
63
64
65
       * and normalized to UTC.
       *
       * This method will alter the VCalendar. This cannot be reversed.
       *
6d9380f96   Cédric Dupont   Update sources OC...
66
67
       * This functionality is specifically used by the CalDAV standard. It is
       * possible for clients to request expand events, if they are rather simple
03e52840d   Kload   Init
68
69
70
       * clients and do not have the possibility to calculate recurrences.
       *
       * @param DateTime $start
6d9380f96   Cédric Dupont   Update sources OC...
71
       * @param DateTime $end
03e52840d   Kload   Init
72
73
74
75
76
77
78
79
80
81
82
       * @return void
       */
      public function expand(\DateTime $start, \DateTime $end) {
  
          $newEvents = array();
  
          foreach($this->select('VEVENT') as $key=>$vevent) {
  
              if (isset($vevent->{'RECURRENCE-ID'})) {
                  unset($this->children[$key]);
                  continue;
6d9380f96   Cédric Dupont   Update sources OC...
83
              }
03e52840d   Kload   Init
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  
  
              if (!$vevent->rrule) {
                  unset($this->children[$key]);
                  if ($vevent->isInTimeRange($start, $end)) {
                      $newEvents[] = $vevent;
                  }
                  continue;
              }
  
              $uid = (string)$vevent->uid;
              if (!$uid) {
                  throw new \LogicException('Event did not have a UID!');
              }
  
              $it = new VObject\RecurrenceIterator($this, $vevent->uid);
              $it->fastForward($start);
  
              while($it->valid() && $it->getDTStart() < $end) {
  
                  if ($it->getDTEnd() > $start) {
  
                      $newEvents[] = $it->getEventObject();
  
                  }
                  $it->next();
  
              }
              unset($this->children[$key]);
  
          }
  
          foreach($newEvents as $newEvent) {
  
              foreach($newEvent->children as $child) {
                  if ($child instanceof VObject\Property\DateTime &&
                      $child->getDateType() == VObject\Property\DateTime::LOCALTZ) {
                          $child->setDateTime($child->getDateTime(),VObject\Property\DateTime::UTC);
                      }
              }
  
              $this->add($newEvent);
  
          }
  
          // Removing all VTIMEZONE components
          unset($this->VTIMEZONE);
6d9380f96   Cédric Dupont   Update sources OC...
131
      }
03e52840d   Kload   Init
132
133
134
135
136
137
138
139
140
  
      /**
       * Validates the node for correctness.
       * An array is returned with warnings.
       *
       * Every item in the array has the following properties:
       *    * level - (number between 1 and 3 with severity information)
       *    * message - (human readable message)
       *    * node - (reference to the offending node)
6d9380f96   Cédric Dupont   Update sources OC...
141
142
       *
       * @return array
03e52840d   Kload   Init
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
       */
      /*
      public function validate() {
  
          $warnings = array();
  
          $version = $this->select('VERSION');
          if (count($version)!==1) {
              $warnings[] = array(
                  'level' => 1,
                  'message' => 'The VERSION property must appear in the VCALENDAR component exactly 1 time',
                  'node' => $this,
              );
          } else {
              if ((string)$this->VERSION !== '2.0') {
                  $warnings[] = array(
                      'level' => 1,
                      'message' => 'Only iCalendar version 2.0 as defined in rfc5545 is supported.',
                      'node' => $this,
                  );
              }
6d9380f96   Cédric Dupont   Update sources OC...
164
          }
03e52840d   Kload   Init
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
          $version = $this->select('PRODID');
          if (count($version)!==1) {
              $warnings[] = array(
                  'level' => 2,
                  'message' => 'The PRODID property must appear in the VCALENDAR component exactly 1 time',
                  'node' => $this,
              );
          }
          if (count($this->CALSCALE) > 1) {
              $warnings[] = array(
                  'level' => 2,
                  'message' => 'The CALSCALE property must not be specified more than once.',
                  'node' => $this,
              );
          }
          if (count($this->METHOD) > 1) {
              $warnings[] = array(
                  'level' => 2,
                  'message' => 'The METHOD property must not be specified more than once.',
                  'node' => $this,
              );
          }
  
          $allowedComponents = array(
              'VEVENT',
              'VTODO',
              'VJOURNAL',
              'VFREEBUSY',
              'VTIMEZONE',
          );
          $allowedProperties = array(
              'PRODID',
              'VERSION',
              'CALSCALE',
              'METHOD',
          );
          $componentsFound = 0;
          foreach($this->children as $child) {
              if($child instanceof Component) {
                  $componentsFound++;
                  if (!in_array($child->name, $allowedComponents)) {
                      $warnings[] = array(
                          'level' => 1,
                          'message' => 'The ' . $child->name . " component is not allowed in the VCALENDAR component",
                          'node' => $this,
                      );
                  }
              }
              if ($child instanceof Property) {
                  if (!in_array($child->name, $allowedProperties)) {
                      $warnings[] = array(
                          'level' => 2,
                          'message' => 'The ' . $child->name . " property is not allowed in the VCALENDAR component",
                          'node' => $this,
                      );
                  }
              }
          }
  
          if ($componentsFound===0) {
              $warnings[] = array(
                  'level' => 1,
                  'message' => 'An iCalendar object must have at least 1 component.',
                  'node' => $this,
              );
          }
  
          return array_merge(
              $warnings,
              parent::validate()
          );
  
      }
       */
  
  }