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 Tile 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_Tile extends Zend_Mobile_Push_Message_Mpns
0035 {
0036     /**
0037      * Mpns delays
0038      *
0039      * @var int
0040      */
0041     const DELAY_IMMEDIATE = 1;
0042     const DELAY_450S = 11;
0043     const DELAY_900S = 21;
0044 
0045     /**
0046      * Background Image
0047      *
0048      * @var string
0049      */
0050     protected $_backgroundImage;
0051 
0052     /**
0053      * Count
0054      *
0055      * @var int
0056      */
0057     protected $_count = 0;
0058 
0059     /**
0060      * Title
0061      *
0062      * @var string
0063      */
0064     protected $_title;
0065 
0066     /**
0067      * Back Background Image
0068      *
0069      * @var string
0070      */
0071     protected $_backBackgroundImage;
0072 
0073     /**
0074      * Back Title
0075      *
0076      * @var string
0077      */
0078     protected $_backTitle;
0079 
0080     /**
0081      * Back Content
0082      *
0083      * @var string
0084      */
0085     protected $_backContent;
0086 
0087     /**
0088      * Tile ID
0089      *
0090      * @var string
0091      */
0092     protected $_tileId;
0093 
0094     /**
0095      * Get Background Image
0096      *
0097      * @return string
0098      */
0099     public function getBackgroundImage()
0100     {
0101         return $this->_backgroundImage;
0102     }
0103 
0104     /**
0105      * Set Background Image
0106      *
0107      * @param string $bgImg
0108      * @return Zend_Mobile_Push_Message_Mpns_Tile
0109      * @throws Zend_Mobile_Push_Message_Exception
0110      */
0111     public function setBackgroundImage($bgImg)
0112     {
0113         if (!is_string($bgImg)) {
0114             throw new Zend_Mobile_Push_Message_Exception('$bgImg must be a string');
0115         }
0116         $this->_backgroundImage = $bgImg;
0117         return $this;
0118     }
0119 
0120     /**
0121      * Get Count
0122      *
0123      * @return int
0124      */
0125     public function getCount()
0126     {
0127         return $this->_count;
0128     }
0129 
0130     /**
0131      * Set Count
0132      *
0133      * @param int $count
0134      * @return Zend_Mobile_Push_Message_Mpns_Tile
0135      * @throws Zend_Mobile_Push_Message_Exception
0136      */
0137     public function setCount($count)
0138     {
0139         if (!is_numeric($count)) {
0140             throw new Zend_Mobile_Push_Message_Exception('$count is not numeric');
0141         }
0142         $this->_count = (int) $count;
0143         return $this;
0144     }
0145 
0146     /**
0147      * Get Title
0148      *
0149      * @return string
0150      */
0151     public function getTitle()
0152     {
0153         return $this->_title;
0154     }
0155 
0156     /**
0157      * Set Title
0158      *
0159      * @param string $title
0160      * @return Zend_Mobile_Push_Message_Mpns_Tile
0161      * @throws Zend_Mobile_Push_Message_Exception
0162      */
0163     public function setTitle($title)
0164     {
0165         if (!is_string($title)) {
0166             throw new Zend_Mobile_Push_Message_Exception('$title must be a string');
0167         }
0168         $this->_title = $title;
0169         return $this;
0170     }
0171 
0172     /**
0173      * Get Back Background Image
0174      *
0175      * @return string
0176      */
0177     public function getBackBackgroundImage()
0178     {
0179         return $this->_backBackgroundImage;
0180     }
0181 
0182     /**
0183      * Set Back Background Image
0184      *
0185      * @param string $bgImg
0186      * @return Zend_Mobile_Push_Message_Mpns_Tile
0187      * @throws Zend_Mobile_Push_Message_Exception
0188      */
0189     public function setBackBackgroundImage($bgImg)
0190     {
0191         if (!is_string($bgImg)) {
0192             throw new Zend_Mobile_Push_Message_Exception('$bgImg must be a string');
0193         }
0194         $this->_backBackgroundImage = $bgImg;
0195         return $this;
0196     }
0197 
0198     /**
0199      * Get Back Title
0200      *
0201      * @return string
0202      */
0203     public function getBackTitle()
0204     {
0205         return $this->_backTitle;
0206     }
0207 
0208     /**
0209      * Set Back Title
0210      *
0211      * @param string $title
0212      * @return Zend_Mobile_Push_Message_Mpns_Tile
0213      * @throws Zend_Mobile_Push_Message_Exception
0214      */
0215     public function setBackTitle($title)
0216     {
0217         if (!is_string($title)) {
0218             throw new Zend_Mobile_Push_Message_Exception('$title must be a string');
0219         }
0220         $this->_backTitle = $title;
0221         return $this;
0222     }
0223 
0224     /**
0225      * Get Back Content
0226      *
0227      * @return string
0228      */
0229     public function getBackContent()
0230     {
0231         return $this->_backContent;
0232     }
0233 
0234     /**
0235      * Set Back Content
0236      * 
0237      * @param string $content
0238      * @return Zend_Mobile_Push_Message_Mpns_Tile
0239      * @throws Zend_Mobile_Push_Message_Exception
0240      */
0241     public function setBackContent($content)
0242     {
0243         if (!is_string($content)) {
0244             throw new Zend_Mobile_Push_Message_Exception('$content must be a string');
0245         }
0246         $this->_backContent = $content;
0247     }
0248 
0249     /**
0250      * Get Tile Id
0251      *
0252      * @return string
0253      */
0254     public function getTileId()
0255     {
0256         return $this->_tileId;
0257     }
0258 
0259     /**
0260      * Set Tile Id
0261      *
0262      * @param string $tileId
0263      * @return Zend_Mobile_Push_Message_Mpns_Tile
0264      * @throws Zend_Mobile_Push_Message_Exception
0265      */
0266     public function setTileId($tileId)
0267     {
0268         if (!is_string($tileId)) {
0269             throw new Zend_Mobile_Push_Message_Exception('$tileId is not a string');
0270         }
0271         $this->_tileId = $tileId;
0272         return $this;
0273     }
0274 
0275     /**
0276      * Get Delay
0277      *
0278      * @return int
0279      */
0280     public function getDelay()
0281     {
0282         if (!$this->_delay) {
0283             return self::DELAY_IMMEDIATE;
0284         }
0285         return $this->_delay;
0286     }
0287 
0288     /**
0289      * Set Delay
0290      *
0291      * @param int $delay
0292      * @return Zend_Mobile_Push_Message_Mpns_Tile
0293      * @throws Zend_Mobile_Push_Message_Exception
0294      */
0295     public function setDelay($delay)
0296     {
0297         if (!in_array($delay, array(
0298             self::DELAY_IMMEDIATE,
0299             self::DELAY_450S,
0300             self::DELAY_900S
0301         ))) {
0302             throw new Zend_Mobile_Push_Message_Exception('$delay must be one of the DELAY_* constants');
0303         }
0304         $this->_delay = $delay;
0305         return $this;
0306     }
0307 
0308     /**
0309      * Get Notification Type
0310      *
0311      * @return string
0312      */
0313     public static function getNotificationType()
0314     {
0315         return 'token';
0316     }
0317 
0318     /**
0319      * Get XML Payload
0320      *
0321      * @return string
0322      */
0323     public function getXmlPayload()
0324     {
0325         $ret = '<?xml version="1.0" encoding="utf-8"?>'
0326             . '<wp:Notification xmlns:wp="WPNotification">'
0327             . '<wp:Tile' . (($this->_tileId) ? ' Id="' . htmlspecialchars($this->_tileId) . '"' : '') . '>'
0328             . '<wp:BackgroundImage>' . htmlspecialchars($this->_backgroundImage) . '</wp:BackgroundImage>'
0329             . '<wp:Count>' . (int) $this->_count . '</wp:Count>'
0330             . '<wp:Title>' . htmlspecialchars($this->_title) . '</wp:Title>';
0331 
0332         if ($this->_backBackgroundImage) {
0333             $ret .= '<wp:BackBackgroundImage>' . htmlspecialchars($this->_backBackgroundImage) . '</wp:BackBackgroundImage>';
0334         }
0335         if ($this->_backTitle) {
0336             $ret .= '<wp:BackTitle>' . htmlspecialchars($this->_backTitle) . '</wp:BackTitle>';
0337         }
0338         if ($this->_backContent) {
0339             $ret .= '<wp:BackContent>' . htmlspecialchars($this->_backContent) . '</wp:BackContent>';
0340         }
0341 
0342         $ret .= '</wp:Tile>'
0343             . '</wp:Notification>';
0344         return $ret;
0345     }
0346 
0347     /**
0348      * Validate proper mpns message
0349      *
0350      * @return boolean
0351      */
0352     public function validate()
0353     {
0354         if (!isset($this->_token) || strlen($this->_token) === 0) {
0355             return false;
0356         }
0357         if (empty($this->_backgroundImage)) {
0358             return false;
0359         }
0360         if (empty($this->_title)) {
0361             return false;
0362         }
0363         return parent::validate();
0364     }
0365 }