Kronolith_FreeBusy::toJson PHP Метод

toJson() публичный статический Метод

Converts free/busy data to a simple object suitable to be transferred as json.
public static toJson ( Horde_Icalendar_Vfreebusy $fb ) : object
$fb Horde_Icalendar_Vfreebusy A Free/busy component.
Результат object A simple object representation.
    public static function toJson(Horde_Icalendar_Vfreebusy $fb)
    {
        $json = new stdClass();
        $start = $fb->getStart();
        if ($start) {
            $start = new Horde_Date($start);
            $json->s = $start->dateString();
        }
        $end = $fb->getEnd();
        if ($end) {
            $end = new Horde_Date($end);
            $json->e = $end->dateString();
        }
        $b = $fb->getBusyPeriods();
        if (empty($b)) {
            $b = new StdClass();
        }
        $new = new StdClass();
        foreach ($b as $from => $to) {
            $from = new Horde_Date($from);
            $to = new Horde_Date($to);
            $new->{$from->toJson()} = $to->toJson();
        }
        $json->b = $new;
        return $json;
    }

Usage Example

Пример #1
0
 /**
  * Obtain the freebusy information for this resource.
  *
  * @return mixed string|Horde_Icalendar_Vfreebusy  The Freebusy object or
  *                                                 the iCalendar text.
  */
 public function getFreeBusy($startstamp = null, $endstamp = null, $asObject = false, $json = false)
 {
     $vfb = Kronolith_FreeBusy::generate($this->get('calendar'), $startstamp, $endstamp, true);
     $vfb->removeAttribute('ORGANIZER');
     $vfb->setAttribute('ORGANIZER', $this->get('name'));
     if ($json) {
         return Kronolith_FreeBusy::toJson($vfb);
     } elseif (!$asObject) {
         return $vfb->exportvCalendar();
     }
     return $vfb;
 }