/**
* Converts free/busy data to a simple object suitable to be transferred
* as json.
*
* @param Horde_Icalendar_Vfreebusy $fb A Free/busy component.
*
* @return 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;
}