1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13: class Kronolith_Event_Kolab extends Kronolith_Event
14: {
15: 16: 17: 18: 19:
20: public $calendarType = 'internal';
21:
22: 23: 24: 25: 26: 27: 28: 29:
30: public function __construct($driver, $eventObject = null)
31: {
32: static $alarm;
33:
34:
35: if (!isset($alarm) && isset($GLOBALS['prefs'])) {
36: $alarm = $GLOBALS['prefs']->getValue('default_alarm');
37: }
38:
39: $this->alarm = $alarm;
40:
41: parent::__construct($driver, $eventObject);
42: }
43:
44: 45: 46: 47: 48: 49:
50: public function fromDriver($event)
51: {
52: $this->id = $event['uid'];
53: $this->uid = $this->id;
54:
55: if (isset($event['summary'])) {
56: $this->title = $event['summary'];
57: }
58: if (isset($event['body'])) {
59: $this->description = $event['body'];
60: }
61: if (isset($event['location'])) {
62: $this->location = $event['location'];
63: }
64:
65: if (isset($event['sensitivity']) &&
66: ($event['sensitivity'] == 'private' || $event['sensitivity'] == 'confidential')) {
67: $this->private = true;
68: }
69:
70: if (isset($event['organizer']['smtp-address'])) {
71: if (Kronolith::isUserEmail($GLOBALS['registry']->getAuth(), $event['organizer']['smtp-address'])) {
72: $this->creator = $GLOBALS['registry']->getAuth();
73: } else {
74: $this->creator = $event['organizer']['smtp-address'];
75: }
76: }
77:
78: if (isset($event['alarm'])) {
79: $this->alarm = $event['alarm'];
80: }
81:
82: $this->start = new Horde_Date($event['start-date']);
83: $this->end = new Horde_Date($event['end-date']);
84: $this->durMin = ($this->end->timestamp() - $this->start->timestamp()) / 60;
85:
86: if (isset($event['show-time-as'])) {
87: switch ($event['show-time-as']) {
88: case 'free':
89: $this->status = Kronolith::STATUS_FREE;
90: break;
91:
92: case 'tentative':
93: $this->status = Kronolith::STATUS_TENTATIVE;
94: break;
95:
96: case 'busy':
97: case 'outofoffice':
98: default:
99: $this->status = Kronolith::STATUS_CONFIRMED;
100: }
101: } else {
102: $this->status = Kronolith::STATUS_CONFIRMED;
103: }
104:
105:
106: if (isset($event['recurrence'])) {
107: if (isset($event['recurrence']['exclusion'])) {
108: $exceptions = array();
109: foreach($event['recurrence']['exclusion'] as $exclusion) {
110: if (!empty($exclusion)) {
111: $exceptions[] = join('', explode('-', $exclusion));
112: }
113: }
114: $event['recurrence']['exceptions'] = $exceptions;
115: }
116: if (isset($event['recurrence']['complete'])) {
117: $completions = array();
118: foreach($event['recurrence']['complete'] as $complete) {
119: if (!empty($complete)) {
120: $completions[] = join('', explode('-', $complete));
121: }
122: }
123: $event['recurrence']['completions'] = $completions;
124: }
125: $this->recurrence = new Horde_Date_Recurrence($this->start);
126: $this->recurrence->fromHash($event['recurrence']);
127: }
128:
129:
130: $attendee_count = 0;
131: if (!empty($event['attendee'])) {
132: foreach($event['attendee'] as $attendee) {
133: $name = $attendee['display-name'];
134: $email = $attendee['smtp-address'];
135:
136: $role = $attendee['role'];
137: switch ($role) {
138: case 'optional':
139: $role = Kronolith::PART_OPTIONAL;
140: break;
141:
142: case 'resource':
143: $role = Kronolith::PART_NONE;
144: break;
145:
146: case 'required':
147: default:
148: $role = Kronolith::PART_REQUIRED;
149: break;
150: }
151:
152: $status = $attendee['status'];
153: switch ($status) {
154: case 'accepted':
155: $status = Kronolith::RESPONSE_ACCEPTED;
156: break;
157:
158: case 'declined':
159: $status = Kronolith::RESPONSE_DECLINED;
160: break;
161:
162: case 'tentative':
163: $status = Kronolith::RESPONSE_TENTATIVE;
164: break;
165:
166: case 'none':
167: default:
168: $status = Kronolith::RESPONSE_NONE;
169: break;
170: }
171:
172:
173: if (empty($email)) {
174: $email = $attendee_count;
175: $attendee_count++;
176: }
177:
178: $this->addAttendee($email, $role, $status, $name);
179: }
180: }
181:
182: $this->initialized = true;
183: $this->stored = true;
184: }
185:
186: 187: 188:
189: public function toKolab()
190: {
191: $event = array();
192: $event['uid'] = $this->uid;
193: $event['summary'] = $this->title;
194: $event['body'] = $this->description;
195: $event['location'] = $this->location;
196: $event['sensitivity'] = $this->private ? 'private' : 'public';
197:
198:
199: if ($this->_id == null) {
200: $organizer = array(
201: 'display-name' => Kronolith::getUserName($this->creator),
202: 'smtp-address' => Kronolith::getUserEmail($this->creator)
203: );
204: $event['organizer'] = $organizer;
205: }
206:
207: if ($this->alarm != 0) {
208: $event['alarm'] = $this->alarm;
209: }
210:
211: $event['start-date'] = $this->start->timestamp();
212: $event['end-date'] = $this->end->timestamp();
213: $event['_is_all_day'] = $this->isAllDay();
214:
215: switch ($this->status) {
216: case Kronolith::STATUS_FREE:
217: case Kronolith::STATUS_CANCELLED:
218: $event['show-time-as'] = 'free';
219: break;
220:
221: case Kronolith::STATUS_TENTATIVE:
222: $event['show-time-as'] = 'tentative';
223: break;
224:
225:
226: case Kronolith::STATUS_CONFIRMED:
227: default:
228: $event['show-time-as'] = 'busy';
229: }
230:
231:
232: if ($this->recurs()) {
233: $event['recurrence'] = $this->recurrence->toHash();
234: if (!empty($event['recurrence']['exceptions'])) {
235: $exclusions = array();
236: foreach($event['recurrence']['exceptions'] as $exclusion) {
237: if (!empty($exclusion)) {
238: $exclusions[] = vsprintf(
239: '%04d-%02d-%02d', sscanf($exclusion, '%04d%02d%02d')
240: );
241: }
242: }
243: $event['recurrence']['exclusion'] = $exclusions;
244: }
245: if (!empty($event['recurrence']['completions'])) {
246: $completions = array();
247: foreach($event['recurrence']['completions'] as $complete) {
248: if (!empty($complete)) {
249: $completions[] = vsprintf(
250: '%04d-%02d-%02d', sscanf($complete, '%04d%02d%02d')
251: );
252: }
253: }
254: $event['recurrence']['complete'] = $completions;
255: }
256: }
257:
258:
259: $event['attendee'] = array();
260: foreach ($this->attendees as $email => $attendee) {
261: $new_attendee = array();
262: $new_attendee['display-name'] = $attendee['name'];
263:
264:
265: if (is_int($email)) {
266: $new_attendee['smtp-address'] = '';
267: } else {
268: $new_attendee['smtp-address'] = $email;
269: }
270:
271: switch ($attendee['attendance']) {
272: case Kronolith::PART_OPTIONAL:
273: $new_attendee['role'] = 'optional';
274: break;
275:
276: case Kronolith::PART_NONE:
277: $new_attendee['role'] = 'resource';
278: break;
279:
280: case Kronolith::PART_REQUIRED:
281: default:
282: $new_attendee['role'] = 'required';
283: break;
284: }
285:
286: $new_attendee['request-response'] = '0';
287:
288: switch ($attendee['response']) {
289: case Kronolith::RESPONSE_ACCEPTED:
290: $new_attendee['status'] = 'accepted';
291: break;
292:
293: case Kronolith::RESPONSE_DECLINED:
294: $new_attendee['status'] = 'declined';
295: break;
296:
297: case Kronolith::RESPONSE_TENTATIVE:
298: $new_attendee['status'] = 'tentative';
299: break;
300:
301: case Kronolith::RESPONSE_NONE:
302: default:
303: $new_attendee['status'] = 'none';
304: break;
305: }
306:
307: $event['attendee'][] = $new_attendee;
308: }
309:
310: return $event;
311: }
312:
313: }
314: