From 3fd7c73cf317576a866ad796a8c6c3c55b93c9c6 Mon Sep 17 00:00:00 2001 From: Michael J Rubinsky Date: Fri, 20 Nov 2015 09:24:50 -0500 Subject: [PATCH] Change this method to take a parameter array. --- kronolith/lib/Ajax/Application/Handler.php | 5 +++- kronolith/lib/Event.php | 31 +++++++++++++++------- kronolith/lib/Kronolith.php | 4 +-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/kronolith/lib/Ajax/Application/Handler.php b/kronolith/lib/Ajax/Application/Handler.php index 317d359016e..dd95db73ca2 100644 --- a/kronolith/lib/Ajax/Application/Handler.php +++ b/kronolith/lib/Ajax/Application/Handler.php @@ -151,7 +151,10 @@ public function getEvent() try { $event = $kronolith_driver->getEvent($this->vars->id, $this->vars->date); $event->setTimezone(true); - $result->event = $event->toJson(null, true, $GLOBALS['prefs']->getValue('twentyFour') ? 'H:i' : 'h:i A'); + $result->event = $event->toJson(array( + 'full' => true, + 'time_format' => $GLOBALS['prefs']->getValue('twentyFour') ? 'H:i' : 'h:i A') + ); // If recurring, we need to format the dates of this instance, since // Kronolith_Driver#getEvent will return the start/end dates of the // original event in the series. diff --git a/kronolith/lib/Event.php b/kronolith/lib/Event.php index 884d109746a..9fb996479f9 100644 --- a/kronolith/lib/Event.php +++ b/kronolith/lib/Event.php @@ -2237,15 +2237,28 @@ public function toAlarm($time, $user = null, $prefs = null) * - 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. + * @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' * * @return stdClass A simple object. */ - public function toJson($allDay = null, $full = false, $time_format = 'H:i') + public function toJson(array $options = array()) + //public function toJson($allDay = null, $full = false, $time_format = 'H:i') { + $options = array_merge(array( + 'all_day' => null, + 'full' => false, + 'time_format' => 'H:i'), + $options + ); + $json = new stdClass; $json->uid = $this->uid; $json->t = $this->getTitle(); @@ -2255,7 +2268,7 @@ public function toJson($allDay = null, $full = false, $time_format = 'H:i') $json->fi = $this->first; $json->la = $this->last; $json->x = (int)$this->status; - $json->al = is_null($allDay) ? $this->isAllDay() : $allDay; + $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(); @@ -2295,13 +2308,13 @@ public function toJson($allDay = null, $full = false, $time_format = 'H:i') if ($this->_resources) { $json->rs = $this->_resources; } - if ($full) { + if ($options['full']) { $json->id = $this->id; $json->ty = $this->calendarType; $json->sd = $this->start->strftime('%x'); - $json->st = $this->start->format($time_format); + $json->st = $this->start->format($options['time_format']); $json->ed = $this->end->strftime('%x'); - $json->et = $this->end->format($time_format); + $json->et = $this->end->format($options['time_format']); $json->tz = $this->timezone; $json->a = $this->alarm; $json->pv = $this->private; diff --git a/kronolith/lib/Kronolith.php b/kronolith/lib/Kronolith.php index 205a1499223..aa583432092 100644 --- a/kronolith/lib/Kronolith.php +++ b/kronolith/lib/Kronolith.php @@ -552,7 +552,7 @@ public static function addEvents(&$results, &$event, $startDate, $endDate, $addEvent->last = false; } - $results[$loopDate->dateString()][$addEvent->id] = $json ? $addEvent->toJson($allDay) : $addEvent; + $results[$loopDate->dateString()][$addEvent->id] = $json ? $addEvent->toJson(array('all_day' => $allDay)) : $addEvent; } $loopDate = new Horde_Date( @@ -597,7 +597,7 @@ public static function addCoverDates(&$results, $event, $eventStart, $addEvent->recurrence->hasCompletion($loopDate->year, $loopDate->month, $loopDate->mday)) { $addEvent->status = Kronolith::STATUS_CANCELLED; } - $results[$loopDate->dateString()][$addEvent->id] = $json ? $addEvent->toJson($allDay) : $addEvent; + $results[$loopDate->dateString()][$addEvent->id] = $json ? $addEvent->toJson(array('all_day' => $allDay)) : $addEvent; } $loopDate->mday++; }