Overview

Packages

  • Alarm

Classes

  • Horde_Alarm
  • Horde_Alarm_Exception
  • Horde_Alarm_Handler
  • Horde_Alarm_Handler_Desktop
  • Horde_Alarm_Handler_Mail
  • Horde_Alarm_Handler_Notify
  • Horde_Alarm_Null
  • Horde_Alarm_Object
  • Horde_Alarm_Sql
  • Horde_Alarm_Translation
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * @package Alarm
  4:  *
  5:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
  6:  *
  7:  * See the enclosed file COPYING for license information (LGPL). If you
  8:  * did not receive this file, see http://www.horde.org/licenses/lgpl21.
  9:  */
 10: 
 11: /**
 12:  * The Horde_Alarm_Handler_Notification class is a Horde_Alarm handler that
 13:  * notifies of active alarms over the Horde_Notification system.
 14:  *
 15:  * @author  Jan Schneider <jan@horde.org>
 16:  * @package Alarm
 17:  */
 18: class Horde_Alarm_Handler_Notify extends Horde_Alarm_Handler
 19: {
 20:     /**
 21:      * A notification handler injector.
 22:      *
 23:      * @var object
 24:      */
 25:     protected $_notification;
 26: 
 27:     /**
 28:      * Whether a sound already had been played during the page request.
 29:      *
 30:      * @var boolean
 31:      */
 32:     protected $_soundPlayed = false;
 33: 
 34:     /**
 35:      * Constructor.
 36:      *
 37:      * @param array $params  Any parameters that the handler might need.
 38:      *                       Required parameter:
 39:      *   - notification: (object) A factory that implements create() and
 40:      *                   returns a Notification object.
 41:      *
 42:      * @throws Horde_Alarm_Exception
 43:      */
 44:     public function __construct(array $params = null)
 45:     {
 46:         if (!isset($params['notification'])) {
 47:             throw new Horde_Alarm_Exception('Parameter \'notification\' missing.');
 48:         }
 49:         if (!method_exists($params['notification'], 'create')) {
 50:             throw new Horde_Alarm_Exception('Parameter \'notification\' does not have a method create().');
 51:         }
 52:         $this->_notification = $params['notification'];
 53:     }
 54: 
 55:     /**
 56:      * Notifies about an alarm through Horde_Notification.
 57:      *
 58:      * @param array $alarm  An alarm hash.
 59:      */
 60:     public function notify(array $alarm)
 61:     {
 62:         $notification = $this->_notification->create();
 63:         $notification->push($alarm['title'], 'horde.alarm', array('alarm' => $alarm));
 64:         if (!empty($alarm['params']['notify']['sound']) &&
 65:             !isset($this->_soundPlayed[$alarm['params']['notify']['sound']])) {
 66:             $notification->attach('audio');
 67:             $notification->push($alarm['params']['notify']['sound'], 'audio');
 68:             $this->_soundPlayed[$alarm['params']['notify']['sound']] = true;
 69:         }
 70:     }
 71: 
 72:     /**
 73:      * Returns a human readable description of the handler.
 74:      *
 75:      * @return string
 76:      */
 77:     public function getDescription()
 78:     {
 79:         return Horde_Alarm_Translation::t("Inline");
 80:     }
 81: 
 82:     /**
 83:      * Returns a hash of user-configurable parameters for the handler.
 84:      *
 85:      * The parameters are hashes with parameter names as keys and parameter
 86:      * information as values. The parameter information is a hash with the
 87:      * following keys:
 88:      * - type: the parameter type as a preference type.
 89:      * - desc: a parameter description.
 90:      * - required: whether this parameter is required.
 91:      *
 92:      * @return array
 93:      */
 94:     public function getParameters()
 95:     {
 96:         return array(
 97:             'sound' => array(
 98:                 'type' => 'sound',
 99:                 'desc' => Horde_Alarm_Translation::t("Play a sound?"),
100:                 'required' => false));
101:     }
102: }
103: 
API documentation generated by ApiGen