]>
Commit | Line | Data |
---|---|---|
a5eae6b7 MR |
1 | <?php |
2 | /* $Id$ */ | |
3 | ||
4 | require_once 'caldavresource.class.php'; | |
5 | ||
6 | abstract class IComponent { | |
7 | ||
8 | public $type; | |
9 | private $component; | |
10 | private $url; | |
11 | private $etag; | |
12 | private $dirty; | |
13 | ||
14 | function __construct($etag, $url, VTYPE $type, | |
15 | iCalendar $component, $new) { | |
16 | $this->etag = $etag; | |
17 | $this->url = $url; | |
18 | $this->component = $component; | |
19 | $this->type = $type; | |
20 | $this->dirty = $new; | |
21 | } | |
22 | ||
23 | public function isDirty() { | |
24 | return $this->dirty; | |
25 | } | |
26 | ||
27 | public function setDirty() { | |
28 | $this->dirty = TRUE; | |
29 | } | |
30 | ||
31 | public function getResource() { | |
32 | return $this->component; | |
33 | } | |
34 | ||
35 | public function setResource(iCalendar $component) { | |
36 | $this->component = $component; | |
37 | $this->dirty = TRUE; | |
38 | } | |
39 | ||
40 | public function getBaseComponent() { | |
41 | return $this->getComponent($this->type); | |
42 | } | |
43 | ||
44 | public function getUrl() { | |
45 | return $this->url; | |
46 | } | |
47 | ||
48 | public function getEtag() { | |
49 | return $this->etag; | |
50 | } | |
51 | ||
52 | public function setEtag($etag) { | |
53 | $this->etag = $etag; | |
54 | } | |
55 | ||
56 | public function getComponent($type) { | |
57 | $ref = $this->component; | |
58 | //print_r($ref); | |
59 | ||
60 | if ($this->component === NULL) | |
61 | $ical = NULL; | |
62 | else if ($type instanceof VTYPE && $type->ordinal() == VTYPE::VTIMEZONE) { | |
63 | $ical = $ref->component->GetComponents('VTIMEZONE'); | |
64 | } | |
65 | else { | |
66 | //$theType = sprintf("%s", $this->type); | |
67 | //print "self: $theType\n"; | |
68 | $component = $ref->component->GetComponents($this->type); | |
69 | //print_r($component); | |
70 | if (! $type instanceof VTYPE) | |
71 | $type = new VTYPE($type); | |
72 | //$theType = sprintf("%s", $type); | |
73 | //print "instance: $theType\n"; | |
74 | if (count($component) > 0) | |
75 | $ical = $component[0]; | |
76 | if ($type->ordinal() != $this->type->ordinal() && $ical) { | |
77 | $ical = $ical->GetComponents($type); | |
78 | } | |
79 | } | |
80 | return $ical; | |
81 | } | |
82 | ||
83 | public function isUTCTime() { | |
84 | $event = $this->getBaseComponent(); | |
85 | $start = $event->GetPValue('DTSTART'); | |
86 | $end = $event->GetPValue('DTEND'); | |
87 | ||
88 | if (! ($start && $end)) | |
89 | throw new Exception("Not a valid iCal component"); | |
90 | return ($start[strlen($start) - 1] == 'Z' || | |
91 | $nd[strlen($end) - 1] == 'Z'); | |
92 | } | |
93 | ||
94 | public function getDetails() { | |
95 | $event = $this->getBaseComponent(); | |
96 | $start = strtotime($event->GetPValue('DTSTART')); | |
97 | $start = date("Y-m-d H:m", $start); | |
98 | $end = strtotime($event->GetPValue('DTEND')); | |
99 | $end = date("Y-m-d H:m", $end); | |
100 | $title = $event->GetPValue('SUMMARY'); | |
101 | ||
102 | return "$start-$end: $title"; | |
103 | } | |
104 | ||
105 | public function getTZID() { | |
106 | $res = 'UTC'; | |
107 | ||
108 | if (! $this->isUTCTime()) { | |
109 | $timezone = $this->getTimeZone(); | |
110 | if ($timezone) { | |
111 | $res = $timezone->GetPValue('TZID'); | |
112 | } | |
113 | // timezone not given assume TZID = server's timezone | |
114 | // servers default timezone is UTC | |
115 | } | |
116 | return $res; | |
117 | } | |
118 | ||
119 | function getTimeZone() { | |
120 | $timezone = $this->getComponent(VTYPE::VTIMEZONE); | |
121 | if ($timezone) | |
122 | $timezone = $timezone[0]; | |
123 | return $timezone; | |
124 | } | |
125 | ||
126 | public function __toString() { | |
127 | return $this->type->__toString(); | |
128 | } | |
129 | ||
130 | /** | |
131 | * The following functions should be overloaded in | |
132 | * the child classes if the have specific functionality | |
133 | */ | |
134 | ||
135 | function isActive($start, $end) { | |
136 | return FALSE; | |
137 | } | |
138 | ||
139 | function getActiveDates() { | |
140 | return array(); | |
141 | } | |
142 | ||
143 | function getAlarm() { | |
144 | return NULL; | |
145 | } | |
146 | ||
147 | } |