/** * Returns a simple object suitable for json transport representing this * task. * * @param boolean $full Whether to return all task details. * @param string $time_format The date() format to use for time formatting. * * @return object A simple object. */ public function toJson($full = false, $time_format = 'H:i') { $json = new stdClass(); $json->l = $this->tasklist; $json->p = $this->parent_id; $json->i = $this->indent; $json->n = $this->name; if ($this->desc) { //TODO: Get the proper amount of characters, and cut by last //whitespace $json->sd = Horde_String::substr($this->desc, 0, 80); } $json->cp = (bool) $this->completed; if ($this->due && ($due = $this->getNextDue())) { $json->du = $due->toJson(); } if ($this->start && ($start = $this->getNextStart())) { $json->s = $start->toJson(); } $json->pr = (int) $this->priority; if ($this->recurs()) { $json->r = $this->recurrence->getRecurType(); } $json->t = array_values($this->tags); if ($full) { // @todo: do we really need all this? $json->id = $this->id; $json->de = $this->desc; if ($this->due) { $date = new Horde_Date($this->due); $json->dd = $date->strftime('%x'); $json->dt = $date->format($time_format); } $json->as = $this->assignee; if ($this->estimate) { $json->e = $this->estimate; } /* $json->o = $this->owner; if ($this->completed_date) { $date = new Horde_Date($this->completed_date); $json->cd = $date->toJson(); } */ $json->a = (int) $this->alarm; $json->m = $this->methods; //$json->pv = (boolean)$this->private; if ($this->recurs()) { $json->r = $this->recurrence->toJson(); } if ($this->tasklist == '**EXTERNAL**') { $json->vl = (string) $this->view_link; $json->cl = (string) $this->complete_link; $json->pe = $json->pd = false; } else { try { $share = $GLOBALS['nag_shares']->getShare($this->tasklist); } catch (Horde_Share_Exception $e) { Horde::log($e->getMessage(), 'ERR'); throw new Nag_Exception($e); } $json->pe = $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::EDIT); $json->pd = $share->hasPermission($GLOBALS['registry']->getAuth(), Horde_Perms::DELETE); } } return $json; }
/** * Returns a simple object suitable for json transport representing this * event. * * Possible properties are: * - t: title * - d: description * - c: calendar id * - s: start date * - e: end date * - fi: first day of a multi-day event * - la: last day of a multi-day event * - x: status (Kronolith::STATUS_* constant) * - al: all-day? * - bg: background color * - fg: foreground color * - pe: edit permissions? * - pd: delete permissions? * - vl: variable, i.e. editable length? * - a: alarm text or minutes * - r: recurrence type (Horde_Date_Recurrence::RECUR_* constant) * - bid: The baseid for an event representing an exception * - eod: The original date that an exception is replacing * - ic: icon * - ln: link * - aj: ajax link * - id: event id * - ty: calendar type (driver) * - l: location * - u: url * - sd: formatted start date * - st: formatted start time * - ed: formatted end date * - et: formatted end time * - at: attendees * - rs: resources * - tg: tag list, * - mt: meeting (Boolean true if event has attendees, false otherwise). * * @param boolean $allDay If not null, overrides whether the event is * an all-day event. * @param boolean $full Whether to return all event details. * @param string $time_format The date() format to use for time formatting. * * @return stdClass A simple object. */ public function toJson($allDay = null, $full = false, $time_format = 'H:i') { $json = new stdClass(); $json->uid = $this->uid; $json->t = $this->getTitle(); $json->c = $this->calendar; $json->s = $this->start->toJson(); $json->e = $this->end->toJson(); $json->fi = $this->first; $json->la = $this->last; $json->x = (int) $this->status; $json->al = is_null($allDay) ? $this->isAllDay() : $allDay; $json->pe = $this->hasPermission(Horde_Perms::EDIT); $json->pd = $this->hasPermission(Horde_Perms::DELETE); $json->l = $this->getLocation(); $json->mt = !empty($this->attendees); $json->sort = sprintf('%010s%06s', $this->originalStart->timestamp(), 240000 - $this->end->format('His')); if ($this->icon) { $json->ic = $this->icon; } if ($this->alarm) { if ($this->alarm % 10080 == 0) { $alarm_value = $this->alarm / 10080; $json->a = sprintf(ngettext("%d week", "%d weeks", $alarm_value), $alarm_value); } elseif ($this->alarm % 1440 == 0) { $alarm_value = $this->alarm / 1440; $json->a = sprintf(ngettext("%d day", "%d days", $alarm_value), $alarm_value); } elseif ($this->alarm % 60 == 0) { $alarm_value = $this->alarm / 60; $json->a = sprintf(ngettext("%d hour", "%d hours", $alarm_value), $alarm_value); } else { $alarm_value = $this->alarm; $json->a = sprintf(ngettext("%d minute", "%d minutes", $alarm_value), $alarm_value); } } if ($this->recurs()) { $json->r = $this->recurrence->getRecurType(); } elseif ($this->baseid) { $json->bid = $this->baseid; if ($this->exceptionoriginaldate) { $json->eod = sprintf(_("%s at %s"), $this->exceptionoriginaldate->strftime($GLOBALS['prefs']->getValue('date_format')), $this->exceptionoriginaldate->strftime($GLOBALS['prefs']->getValue('twentyFour') ? '%H:%M' : '%I:%M %p')); } } if ($this->_resources) { $json->rs = $this->_resources; } if ($full) { $json->id = $this->id; $json->ty = $this->calendarType; $json->sd = $this->start->strftime('%x'); $json->st = $this->start->format($time_format); $json->ed = $this->end->strftime('%x'); $json->et = $this->end->format($time_format); $json->tz = $this->timezone; $json->a = $this->alarm; $json->pv = $this->private; if ($this->recurs()) { $json->r = $this->recurrence->toJson(); } if (!$this->isPrivate()) { $json->d = $this->description; $json->u = $this->url; $json->uhl = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($this->url, 'linkurls'); $json->tg = array_values($this->tags); $json->gl = $this->geoLocation; if ($this->attendees) { $attendees = array(); foreach ($this->attendees as $email => $info) { $tmp = new Horde_Mail_Rfc822_Address($email); if (!empty($info['name'])) { $tmp->personal = $info['name']; } $attendees[] = array('a' => intval($info['attendance']), 'e' => $tmp->bare_address, 'r' => intval($info['response']), 'l' => strval($tmp)); $json->at = $attendees; } } } if ($this->methods) { $json->m = $this->methods; } } return $json; }
/** * Returns a simple object suitable for json transport representing this * event. * * Possible properties are: * - t: title * - d: description * - c: calendar id * - s: start date * - e: end date * - fi: first day of a multi-day event * - la: last day of a multi-day event * - x: status (Kronolith::STATUS_* constant) * - al: all-day? * - bg: background color * - fg: foreground color * - pe: edit permissions? * - pd: delete permissions? * - vl: variable, i.e. editable length? * - a: alarm text or minutes * - r: recurrence type (Horde_Date_Recurrence::RECUR_* constant) * - bid: The baseid for an event representing an exception * - eod: The original date that an exception is replacing * - ic: icon * - ln: link * - aj: ajax link * - id: event id * - ty: calendar type (driver) * - l: location * - u: url * - sd: formatted start date * - st: formatted start time * - ed: formatted end date * - et: formatted end time * - at: attendees * - rs: resources * - tg: tag list * - mt: meeting (Boolean true if event has attendees, false otherwise). * - cb: created by (string describing when and who created the event). * - mb: modified by (string describing when and who last modified event). * - o: organizer (if known) * - oy: organizer you * - cr: creator's attendance response * - fs: Array of attached files. * * @param array $options An array of options: * * - all_day: (boolean) If not null, overrides whether the event is an * all-day event. * DEFAULT: null (Do not override). * - full: (boolean) Whether to return all event details. * DEFAULT: false (Do not return all details). * - time_format: (string) The date() format to use for time formatting. * DEFAULT: 'H:i' * - history: (boolean) If true, ensures that this event's history is * loaded from the History backend. * DEFAULT: false (Do not ensure history is loaded). * * @return stdClass A simple object. */ public function toJson(array $options = array()) { $options = array_merge(array('all_day' => null, 'full' => false, 'time_format' => 'H:i', 'history' => false), $options); $json = new stdClass(); $json->uid = $this->uid; $json->t = $this->getTitle(); $json->c = $this->calendar; $json->s = $this->start->toJson(); $json->e = $this->end->toJson(); $json->fi = $this->first; $json->la = $this->last; $json->x = (int) $this->status; $json->al = is_null($options['all_day']) ? $this->isAllDay() : $options['all_day']; $json->pe = $this->hasPermission(Horde_Perms::EDIT); $json->pd = $this->hasPermission(Horde_Perms::DELETE); $json->l = $this->getLocation(); $json->mt = (bool) count($this->attendees); $json->sort = sprintf('%010s%06s', $this->originalStart->timestamp(), 240000 - $this->end->format('His')); if ($this->icon) { $json->ic = $this->icon; } if ($this->alarm) { if ($this->alarm % 10080 == 0) { $alarm_value = $this->alarm / 10080; $json->a = sprintf(ngettext("%d week", "%d weeks", $alarm_value), $alarm_value); } elseif ($this->alarm % 1440 == 0) { $alarm_value = $this->alarm / 1440; $json->a = sprintf(ngettext("%d day", "%d days", $alarm_value), $alarm_value); } elseif ($this->alarm % 60 == 0) { $alarm_value = $this->alarm / 60; $json->a = sprintf(ngettext("%d hour", "%d hours", $alarm_value), $alarm_value); } else { $alarm_value = $this->alarm; $json->a = sprintf(ngettext("%d minute", "%d minutes", $alarm_value), $alarm_value); } } if ($this->recurs()) { $json->r = $this->recurrence->getRecurType(); } elseif ($this->baseid) { $json->bid = $this->baseid; if ($this->exceptionoriginaldate) { $json->eod = sprintf(_("%s at %s"), $this->exceptionoriginaldate->strftime($GLOBALS['prefs']->getValue('date_format')), $this->exceptionoriginaldate->strftime($GLOBALS['prefs']->getValue('twentyFour') ? '%H:%M' : '%I:%M %p')); } } if ($this->_resources) { $json->rs = $this->_resources; } if ($options['history']) { $this->loadHistory(); if (!empty($this->created)) { $json->cb = sprintf('%s %s %s', $this->created->strftime($GLOBALS['prefs']->getValue('date_format')), $this->created->strftime($GLOBALS['prefs']->getValue('twentyFour') ? '%H:%M' : '%I:%M %p'), $this->createdby); } else { $json->cb = ''; } if (!empty($this->modified)) { $json->mb = sprintf('%s %s %s', $this->modified->strftime($GLOBALS['prefs']->getValue('date_format')), $this->modified->strftime($GLOBALS['prefs']->getValue('twentyFour') ? '%H:%M' : '%I:%M %p'), $this->modifiedby); } else { $json->mb = ''; } } if ($this->organizer) { $json->o = $this->organizer; $json->oy = Kronolith::isUserEmail($this->creator, $this->organizer); } else { $json->oy = true; } if ($options['full']) { $json->id = $this->id; $json->ty = $this->calendarType; $json->sd = $this->start->strftime('%x'); $json->st = $this->start->format($options['time_format']); $json->ed = $this->end->strftime('%x'); $json->et = $this->end->format($options['time_format']); $json->tz = $this->timezone; $json->a = $this->alarm; $json->pv = $this->private; if ($this->recurs()) { $json->r = $this->recurrence->toJson(); } if (!$this->isPrivate()) { $json->d = $this->description; $json->u = $this->url; $json->uhl = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($this->url, 'linkurls'); $json->tg = array_values($this->tags); $json->gl = $this->geoLocation; if (count($this->attendees)) { $attendees = array(); foreach ($this->attendees as $attendee) { if (Kronolith::isUserEmail($this->creator, $attendee->email)) { $json->cr = intval($attendee->response); } $attendeeJson = $attendee->toJson(); $attendeeJson->o = $json->oy && Kronolith::isUserEmail($this->creator, $attendee->addressObject->bare_address) || !empty($this->organizer) && $this->organizer == $attendee->addressObject->bare_address; $attendees[] = $attendeeJson; } $json->at = $attendees; } } if ($this->methods) { $json->m = $this->methods; } if ($this->vfsInit()) { $files = $this->listFiles(); $json->fs = count($files) ? $files : false; } } return $json; }