1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11: class Kronolith_Event_Horde extends Kronolith_Event
12: {
13: 14: 15: 16: 17:
18: public $calendarType = 'external';
19:
20: 21: 22: 23: 24:
25: protected $_api;
26:
27: 28: 29: 30: 31:
32: protected $_link;
33:
34: 35: 36: 37: 38:
39: protected $_editLink;
40:
41: 42: 43: 44: 45:
46: protected $_deleteLink;
47:
48: 49: 50: 51: 52:
53: protected $_ajaxLink;
54:
55: 56: 57: 58: 59:
60: protected $_params;
61:
62: 63: 64: 65: 66:
67: protected $_owner;
68:
69: 70: 71: 72: 73:
74: protected $_permissions;
75:
76: 77: 78: 79: 80:
81: protected $_variableLength;
82:
83: 84: 85: 86: 87: 88: 89: 90:
91: public function __construct($driver, $eventObject = null)
92: {
93: $this->_api = $driver->api;
94: parent::__construct($driver, $eventObject);
95: }
96:
97: 98: 99: 100: 101: 102:
103: public function fromDriver($event)
104: {
105: $eventStart = new Horde_Date($event['start']);
106: $eventEnd = new Horde_Date($event['end']);
107: $this->id = '_' . $this->_api . $event['id'];
108: $this->icon = !empty($event['icon']) ? $event['icon'] : null;
109: $this->title = $event['title'];
110: $this->description = isset($event['description']) ? $event['description'] : '';
111: if (isset($event['location'])) {
112: $this->location = $event['location'];
113: }
114: $this->start = $eventStart;
115: $this->end = $eventEnd;
116: if (isset($event['status'])) {
117: switch ($event['status']) {
118: case 'confirmed':
119: $this->status = Kronolith::STATUS_CONFIRMED;
120: break;
121: case 'tentative':
122: $this->status = Kronolith::STATUS_TENTATIVE;
123: break;
124: default:
125: $this->status = Kronolith::STATUS_FREE;
126: }
127: } else {
128: $this->status = Kronolith::STATUS_FREE;
129: }
130: if (isset($event['private'])) {
131: $this->private = $event['private'];
132: }
133: $this->_params = $event['params'];
134: $this->_link = !empty($event['link']) ? $event['link'] : null;
135: $this->url = !empty($event['url']) ? (string)$event['url'] : null;
136: $this->_editLink = !empty($event['edit_link']) ? $event['edit_link'] : null;
137: $this->_deleteLink = !empty($event['delete_link']) ? $event['delete_link'] : null;
138: $this->_ajaxLink = !empty($event['ajax_link']) ? $event['ajax_link'] : null;
139: $this->_backgroundColor = Kronolith::backgroundColor($event);
140: $this->_foregroundColor = Kronolith::foregroundColor($event);
141:
142: if (isset($event['recurrence'])) {
143: $recurrence = new Horde_Date_Recurrence($eventStart);
144:
145: $recurrence->setRecurType($event['recurrence']['type']);
146: if (isset($event['recurrence']['end'])) {
147: $recurrence->setRecurEnd(new Horde_Date($event['recurrence']['end']));
148: }
149: if (isset($event['recurrence']['interval'])) {
150: $recurrence->setRecurInterval($event['recurrence']['interval']);
151: }
152: if (isset($event['recurrence']['count'])) {
153: $recurrence->setRecurCount($event['recurrence']['count']);
154: }
155: if (isset($event['recurrence']['days'])) {
156: $recurrence->setRecurOnDay($event['recurrence']['days']);
157: }
158: if (isset($event['recurrence']['exceptions'])) {
159: foreach ($event['recurrence']['exceptions'] as $exception) {
160: $recurrence->addException($exception);
161: }
162: }
163: $this->recurrence = $recurrence;
164: }
165:
166: if (isset($event['owner'])) {
167: $this->_owner = $event['owner'];
168: }
169: if (isset($event['permissions'])) {
170: $this->_permissions = $event['permissions'];
171: }
172: if (isset($event['variable_length'])) {
173: $this->_variableLength = $event['variable_length'];
174: }
175:
176: $this->initialized = true;
177: $this->stored = true;
178: }
179:
180: 181: 182:
183: public function toTimeobject()
184: {
185: $timeobject = array(
186: 'id' => substr($this->id, strlen($this->_api) + 1),
187: 'icon' => $this->icon,
188: 'title' => $this->title,
189: 'description' => $this->description,
190: 'location' => $this->location,
191: 'start' => $this->start->format('Y-m-d\TH:i:s'),
192: 'end' => $this->end->format('Y-m-d\TH:i:s'),
193: 'params' => $this->_params,
194: 'link' => $this->_link,
195: 'ajax_link' => $this->_ajaxLink,
196: 'permissions' => $this->_permissions,
197: 'variable_length' => $this->_variableLength);
198:
199: if ($this->recurs()) {
200: $timeobject['recurrence'] = array('type' => $this->recurrence->getRecurType());
201: if ($end = $this->recurrence->getRecurEnd()) {
202: $timeobject['recurrence']['end'] = $end->format('Y-m-d\TH:i:s');
203: }
204: if ($interval = $this->recurrence->getRecurInterval()) {
205: $timeobject['recurrence']['interval'] = $interval;
206: }
207: if ($count = $this->recurrence->getRecurCount()) {
208: $timeobject['recurrence']['count'] = $count;
209: }
210: if ($days = $this->recurrence->getRecurOnDays()) {
211: $timeobject['recurrence']['days'] = $days;
212: }
213: if ($count = $this->recurrence->getRecurCount()) {
214: $timeobject['recurrence']['count'] = $count;
215: }
216: if ($exceptions = $this->recurrence->getExceptions()) {
217: $timeobject['recurrence']['exceptions'] = $exceptions;
218: }
219: }
220:
221: return $timeobject;
222: }
223:
224: 225: 226: 227: 228: 229: 230: 231:
232: public function hasPermission($permission, $user = null)
233: {
234: if ($user === null) {
235: $user = $GLOBALS['registry']->getAuth();
236: }
237:
238: if (isset($this->_owner) && $this->_owner == $user) {
239: return true;
240: }
241:
242: if (isset($this->_permissions)) {
243: return (bool)($this->_permissions & $permission);
244: }
245:
246: switch ($permission) {
247: case Horde_Perms::SHOW:
248: case Horde_Perms::READ:
249: return true;
250:
251: default:
252: return false;
253: }
254: }
255:
256: 257: 258: 259: 260: 261: 262:
263: public function getTitle($user = null)
264: {
265: return !empty($this->title) ? $this->title : _("[Unnamed event]");
266: }
267:
268: 269: 270: 271: 272:
273: public function getViewUrl($params = array(), $full = false, $encoded = true)
274: {
275: if (empty($this->_link)) {
276: return null;
277: }
278: $url = clone $this->_link;
279: return $url->setRaw(!$encoded);
280: }
281:
282: 283: 284: 285: 286:
287: public function getEditUrl($params = array(), $full = false)
288: {
289: if (empty($this->_editLink)) {
290: return null;
291: }
292: $url = clone $this->_editLink;
293: if (isset($params['url'])) {
294: $url->add('url', $params['url']);
295: }
296: return $url->setRaw($full);
297: }
298:
299: 300: 301: 302: 303:
304: public function getDeleteUrl($params = array(), $full = false)
305: {
306: if (empty($this->_deleteLink)) {
307: return null;
308: }
309: $url = clone $this->_deleteLink;
310: if (isset($params['url'])) {
311: $url->add('url', $params['url']);
312: }
313: return $url->setRaw($full);
314: }
315:
316: 317: 318: 319: 320: 321: 322: 323: 324: 325: 326:
327: public function toJson($allDay = null, $full = false, $time_format = 'H:i')
328: {
329: $json = parent::toJson($allDay, $full, $time_format);
330: if ($this->_ajaxLink) {
331: $json->aj = $this->_ajaxLink;
332: } elseif ($link = (string)$this->getViewUrl(array(), true, false)) {
333: $json->ln = $link;
334: }
335: if (isset($this->_variableLength)) {
336: $json->vl = $this->_variableLength;
337: }
338: return $json;
339: }
340:
341: 342: 343:
344: public function getTooltip()
345: {
346: return Horde_String::wrap($this->description);
347: }
348:
349: }
350: