This repository has been archived by the owner on Jan 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Calendar.php
70 lines (58 loc) · 1.89 KB
/
Calendar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
namespace ical;
class Calendar
{
static public function createFromChunk(\ical\parser\Chunk $chunk) {
$calendar = new \ical\Calendar;
$calendar->parseProperties($chunk);
return $calendar;
}
/* Calendar properties */
protected $version = null;
protected $prodid = null;
protected $calscale = null;
protected $method = null;
protected $extended = array();
/**
* @var array \ical\Event
*/
protected $events = array();
public function addEvent(\ical\Event $event) {
$this->events[] = $event;
}
/**
* Parses row values from a chunk
* @param ical\parser\Chunk $chunk
* @return void
* @throws UnexpectedValueException
*/
public function parseProperties(\ical\parser\Chunk $chunk) {
if ($chunk->type !== \ical\parser\Chunk::TYPE_CALENDAR) {
throw new \UnexpectedValueException("Invalid chunk type:" . $chunk->type . ", expected:" . \ical\parser\Chunk::TYPE_CALENDAR);
}
foreach ($chunk->getLines() as $line) {
switch ($line->name) {
case 'VERSION':
$this->version = $line->value;
break;
case 'PRODID':
$this->prodid = $line->value;
break;
case 'CALSCALE':
$this->calscale = $line->value;
break;
case 'METHOD':
$this->method = $line->value;
break;
case 'X-WR-TIMEZONE':
\ical\Event::setDefaultTimezone(new \DateTimeZone($line->value));
break;
default:
if ('X-' === substr($line->name, 0, 2)) {
$this->extended[$line->name] = $line->value;
}
break;
}
}
}
}