1: <?php
2: /**
3: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (LGPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
7: */
8:
9: /**
10: * A Horde_Alarm handler that notifies of active alarms over the
11: * Horde_Notification system.
12: *
13: * @author Jan Schneider <jan@horde.org>
14: * @category Horde
15: * @license http://www.horde.org/licenses/lgpl21 LGPL
16: * @package Core
17: */
18: class Horde_Core_Alarm_Handler_Notify extends Horde_Alarm_Handler
19: {
20: /**
21: * Whether a sound already had been played during the page request.
22: *
23: * @var boolean
24: */
25: protected $_soundPlayed = false;
26:
27: /**
28: * Notifies about an alarm through Horde_Notification.
29: *
30: * @param array $alarm An alarm hash.
31: */
32: public function notify(array $alarm)
33: {
34: global $notification;
35:
36: $notification->push($alarm['title'], 'horde.alarm', array(
37: 'alarm' => $alarm
38: ));
39: if (!empty($alarm['params']['notify']['sound']) &&
40: !isset($this->_soundPlayed[$alarm['params']['notify']['sound']])) {
41: $notification->attach('audio');
42: $notification->push($alarm['params']['notify']['sound'], 'audio');
43: $this->_soundPlayed[$alarm['params']['notify']['sound']] = true;
44: }
45: }
46:
47: /**
48: * Returns a human readable description of the handler.
49: *
50: * @return string
51: */
52: public function getDescription()
53: {
54: return Horde_Core_Translation::t("Inline");
55: }
56:
57: /**
58: * Returns a hash of user-configurable parameters for the handler.
59: *
60: * The parameters are hashes with parameter names as keys and parameter
61: * information as values. The parameter information is a hash with the
62: * following keys:
63: * - desc: a parameter description.
64: * - required: whether this parameter is required.
65: * - type: the parameter type as a preference type.
66: *
67: * @return array
68: */
69: public function getParameters()
70: {
71: return array(
72: 'sound' => array(
73: 'type' => 'sound',
74: 'desc' => Horde_Core_Translation::t("Play a sound?"),
75: 'required' => false
76: )
77: );
78: }
79: }
80: