Skip to content

Commit

Permalink
Change this method to take a parameter array.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Nov 20, 2015
1 parent 2cc3963 commit 3fd7c73
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
5 changes: 4 additions & 1 deletion kronolith/lib/Ajax/Application/Handler.php
Expand Up @@ -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.
Expand Down
31 changes: 22 additions & 9 deletions kronolith/lib/Event.php
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions kronolith/lib/Kronolith.php
Expand Up @@ -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(
Expand Down Expand Up @@ -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++;
}
Expand Down

0 comments on commit 3fd7c73

Please sign in to comment.