File indexing completed on 2025-03-02 05:29:35

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Mobile
0017  * @subpackage Zend_Mobile_Push
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  */
0021 
0022 /** Zend_Mobile_Push_Message_Mpns **/
0023 // require_once 'Zend/Mobile/Push/Message/Mpns.php';
0024 
0025 /**
0026  * Mpns Toast Message
0027  *
0028  * @category   Zend
0029  * @package    Zend_Mobile
0030  * @subpackage Zend_Mobile_Push
0031  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0032  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0033  */
0034 class Zend_Mobile_Push_Message_Mpns_Toast extends Zend_Mobile_Push_Message_Mpns
0035 {
0036     /**
0037      * Mpns delays
0038      *
0039      * @var int
0040      */
0041     const DELAY_IMMEDIATE = 2;
0042     const DELAY_450S = 12;
0043     const DELAY_900S = 22;
0044 
0045     /**
0046      * Title
0047      *
0048      * @var string
0049      */
0050     protected $_title;
0051 
0052     /**
0053      * Message
0054      *
0055      * @var string
0056      */
0057     protected $_msg;
0058 
0059     /**
0060      * Params
0061      *
0062      * @var string
0063      */
0064     protected $_params;
0065 
0066     /**
0067      * Get Title
0068      *
0069      * @return string
0070      */
0071     public function getTitle()
0072     {
0073         return $this->_title;
0074     }
0075 
0076     /**
0077      * Set Title
0078      *
0079      * @param string $title
0080      * @return Zend_Mobile_Push_Message_Mpns_Toast
0081      * @throws Zend_Mobile_Push_Message_Exception
0082      */
0083     public function setTitle($title)
0084     {
0085         if (!is_string($title)) {
0086             throw new Zend_Mobile_Push_Message_Exception('$title must be a string');
0087         }
0088         $this->_title = $title;
0089         return $this;
0090     }
0091 
0092     /**
0093      * Get Message
0094      *
0095      * @return string
0096      */
0097     public function getMessage()
0098     {
0099         return $this->_msg;
0100     }
0101 
0102     /**
0103      * Set Message
0104      *
0105      * @param string $msg
0106      * @return Zend_Mobile_Push_Message_Mpns_Toast
0107      * @throws Zend_Mobile_Push_Message_Exception
0108      */
0109     public function setMessage($msg)
0110     {
0111         if (!is_string($msg)) {
0112             throw new Zend_Mobile_Push_Message_Exception('$msg must be a string');
0113         }
0114         $this->_msg = $msg;
0115         return $this;
0116     }
0117 
0118     /**
0119      * Get Params
0120      *
0121      * @return string
0122      */
0123     public function getParams()
0124     {
0125         return $this->_params;
0126     }
0127 
0128     /**
0129      * Set Params
0130      *
0131      * @param string $params
0132      * @return Zend_Mobile_Push_Message_Mpns_Toast
0133      * @throws Zend_Mobile_Push_Message_Exception
0134      */
0135     public function setParams($params)
0136     {
0137         if (!is_string($params)) {
0138             throw new Zend_Mobile_Push_Message_Exception('$params must be a string');
0139         }
0140         $this->_params = $params;
0141         return $this;
0142     }
0143 
0144     /**
0145      * Get Delay
0146      *
0147      * @return int
0148      */
0149     public function getDelay()
0150     {
0151         if (!$this->_delay) {
0152             return self::DELAY_IMMEDIATE;
0153         }
0154         return $this->_delay;
0155     }
0156 
0157     /**
0158      * Set Delay
0159      *
0160      * @param int $delay
0161      * @return Zend_Mobile_Push_Message_Mpns_Toast
0162      * @throws Zend_Mobile_Push_Message_Exception
0163      */
0164     public function setDelay($delay)
0165     {
0166         if (!in_array($delay, array(
0167             self::DELAY_IMMEDIATE,
0168             self::DELAY_450S,
0169             self::DELAY_900S
0170         ))) {
0171             throw new Zend_Mobile_Push_Message_Exception('$delay must be one of the DELAY_* constants');
0172         }
0173         $this->_delay = $delay;
0174         return $this;
0175     }
0176 
0177     /**
0178      * Get Notification Type
0179      *
0180      * @return string
0181      */
0182     public static function getNotificationType()
0183     {
0184         return 'toast';
0185     }
0186 
0187     /**
0188      * Get XML Payload
0189      *
0190      * @return string
0191      */
0192     public function getXmlPayload()
0193     {
0194         $ret = '<?xml version="1.0" encoding="utf-8"?>'
0195             . '<wp:Notification xmlns:wp="WPNotification">'
0196             . '<wp:Toast>'
0197             . '<wp:Text1>' . htmlspecialchars($this->_title) . '</wp:Text1>'
0198             . '<wp:Text2>' . htmlspecialchars($this->_msg) . '</wp:Text2>';
0199         if (!empty($this->_params)) {
0200             $ret .= '<wp:Param>' . htmlspecialchars($this->_params) . '</wp:Param>';
0201         }
0202         $ret .= '</wp:Toast>'
0203             . '</wp:Notification>';
0204         return $ret;
0205     }
0206 
0207     /**
0208      * Validate proper mpns message
0209      *
0210      * @return boolean
0211      */
0212     public function validate()
0213     {
0214         if (!isset($this->_token) || strlen($this->_token) === 0) {
0215             return false;
0216         }
0217         if (empty($this->_title)) {
0218             return false;
0219         }
0220         if (empty($this->_msg)) {
0221             return false;
0222         }
0223         return parent::validate();
0224     }
0225 }