1: <?php
2: /**
3: * The Alarm Decorator notifies the alarm system to push its notifications on
4: * the stack.
5: *
6: * Copyright 2001-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
10: *
11: * @author Jan Schneider <jan@horde.org>
12: * @category Horde
13: * @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
14: * @package Notification
15: */
16: class Horde_Notification_Handler_Decorator_Alarm
17: extends Horde_Notification_Handler_Decorator_Base
18: {
19: /**
20: * A Horde_Alarm instance.
21: *
22: * @var Horde_Core_Factory_Alarm
23: */
24: protected $_alarm;
25:
26: /**
27: * The current user.
28: *
29: * @var string
30: */
31: protected $_user;
32:
33: /**
34: * Initialize the notification system, set up any needed session
35: * variables, etc.
36: *
37: * @param object $alarm An alarm factory that implements create().
38: * @param string $user The current username.
39: */
40: public function __construct($alarm, $user)
41: {
42: $this->_alarm = $alarm;
43: $this->_user = $user;
44: }
45:
46: /**
47: * Listeners are handling their messages.
48: *
49: * @param Horde_Notification_Handler $handler The base handler object.
50: * @param Horde_Notification_Listener $listener The Listener object that
51: * is handling its messages.
52: *
53: * @throws Horde_Notification_Exception
54: */
55: public function notify(Horde_Notification_Handler $handler,
56: Horde_Notification_Listener $listener)
57: {
58: if ($listener instanceof Horde_Notification_Listener_Status) {
59: try {
60: // TODO: Use $handler
61: $this->_alarm->create()->notify($this->_user);
62: } catch (Horde_Alarm_Exception $e) {
63: throw new Horde_Notification_Exception($e);
64: }
65: }
66: }
67:
68: }
69: