/** * Constructor. * * @param array $params Configuration parameters: * <pre> * 'db' - (Horde_Db_Adapter) [REQUIRED] The DB instance. * 'table' - (string) The name of the alarm table in 'database'. * DEFAULT: 'horde_alarms' * </pre> * * @throws Horde_Alarm_Exception */ public function __construct(array $params = array()) { if (!isset($params['db'])) { throw new Horde_Alarm_Exception('Missing db parameter.'); } $this->_db = $params['db']; unset($params['db']); $params = array_merge(array('table' => 'horde_alarms'), $params); parent::__construct($params); }
/** * Retrieves active alarms from all applications and stores them in the * backend. * * The applications will only be called once in the configured time span, * by default 5 minutes. * * @param string $user Retrieve alarms for this user, or for all users * if null. * @param boolean $preload Preload alarms that go off within the next * ttl time span? */ public function load($user = null, $preload = true) { global $registry, $session; if ($this->_ttl && $session->exists('horde', 'alarm_loaded') && time() - $session->get('horde', 'alarm_loaded') < $this->_ttl) { return; } /* Cache alarm handler application method existence. */ $cache = $session->get('horde', 'factory_alarm'); if (is_null($cache)) { $save = array(); $changed = $registry->getAuth() !== false; try { $apps = $registry->listApps(null, false, Horde_Perms::READ); } catch (Horde_Exception $e) { $apps = array(); } } else { $apps = $cache; $changed = false; } foreach ($apps as $app) { if ($changed) { if (!$registry->hasFeature('alarmHandler')) { continue; } $save[] = $app; } /* Preload alarms that happen in the next ttl seconds. */ $time = $preload ? time() + $this->_ttl : time(); try { foreach ($registry->callAppMethod($app, 'listAlarms', array('args' => array($time, $user), 'noperms' => true)) as $alarm) { $this->_alarm->set($alarm, true); } } catch (Horde_Exception $e) { } } if ($changed) { $session->set('horde', 'factory_alarm', $save); } $session->set('horde', 'alarm_loaded', time()); }