public static getForUser ( string $user, array $opts = [] ) : Horde_Icalendar_Vfreebusy | object | ||
$user | string | The user to look for. |
$opts | array | Options: - json: (boolean) Whether to return the free/busy data as a simple object suitable to be transferred as json. DEFAULT: false - start: (integer) The start of the time period to retrieve. DEFAULT: now - end: (integer) The end of the time period to retrieve. DEFAULT: now + freebusy_days pref |
return | Horde_Icalendar_Vfreebusy | object | Free/busy component. |
public static function getForUser($user, $opts = array())
{
global $injector, $registry;
$opts = array_merge(array('json' => false, 'start' => null, 'end' => null), $opts);
$prefs = $injector->getInstance('Horde_Core_Factory_Prefs')->create('kronolith', array('cache' => false, 'user' => $user));
$registry->setTimeZone();
$cals = @unserialize($prefs->getValue('fb_cals'));
// If the free/busy calendars preference is empty, default to the
// user's default_share preference, and if that's empty, to their
// username.
if (!$cals) {
$cal = $prefs->getValue('default_share');
if (!$cal) {
$cal = $user;
}
$cals = array('internal_' . $cal);
}
try {
$fb = self::generate($cals, $opts['start'], $opts['end'], true, $user);
} catch (Kronolith_Exception $e) {
throw new Kronolith_Exception(sprintf(_("The free/busy data for %s cannot be retrieved."), $user));
}
return $opts['json'] ? self::toJson($fb) : $fb;
}
*/ require_once __DIR__ . '/lib/Application.php'; Horde_Registry::appInit('kronolith', array('authentication' => 'none', 'session_control' => 'none')); // Determine the username to show free/busy time for. $cal = Horde_Util::getFormData('c'); $user = Horde_Util::getFormData('u'); if (!empty($cal)) { if (is_array($cal)) { $cal = implode('|', $cal); } } elseif ($pathInfo = Horde_Util::getPathInfo()) { $user = basename($pathInfo); } $cache = $injector->getInstance('Horde_Cache'); $key = 'kronolith.fb.' . ($user ? 'u.' . $user : '******' . $cal); $fb = $cache->get($key, 360); if (!$fb) { try { if ($user) { $fb = Kronolith_FreeBusy::getForUser($user)->exportvCalendar(); } else { $fb = Kronolith_FreeBusy::generate(explode('|', $cal), null, null, false, $user); } } catch (Exception $e) { Horde::log($e, 'ERR'); exit; } $cache->set($key, $fb); } $browser->downloadHeaders(($user ? $user : $cal) . '.vfb', 'text/calendar; charset=' . 'UTF-8', true, strlen($fb)); echo $fb;