/vendor/magento/zendframework1/library/Zend/Mobile/Push/Message/Mpns/Tile.php

https://gitlab.com/yousafsyed/easternglamor · PHP · 365 lines · 154 code · 30 blank · 181 comment · 16 complexity · 66c58f874385e082848a0a55a6640dc1 MD5 · raw file

  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Mobile
  17. * @subpackage Zend_Mobile_Push
  18. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. */
  21. /** Zend_Mobile_Push_Message_Mpns **/
  22. #require_once 'Zend/Mobile/Push/Message/Mpns.php';
  23. /**
  24. * Mpns Tile Message
  25. *
  26. * @category Zend
  27. * @package Zend_Mobile
  28. * @subpackage Zend_Mobile_Push
  29. * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Mobile_Push_Message_Mpns_Tile extends Zend_Mobile_Push_Message_Mpns
  33. {
  34. /**
  35. * Mpns delays
  36. *
  37. * @var int
  38. */
  39. const DELAY_IMMEDIATE = 1;
  40. const DELAY_450S = 11;
  41. const DELAY_900S = 21;
  42. /**
  43. * Background Image
  44. *
  45. * @var string
  46. */
  47. protected $_backgroundImage;
  48. /**
  49. * Count
  50. *
  51. * @var int
  52. */
  53. protected $_count = 0;
  54. /**
  55. * Title
  56. *
  57. * @var string
  58. */
  59. protected $_title;
  60. /**
  61. * Back Background Image
  62. *
  63. * @var string
  64. */
  65. protected $_backBackgroundImage;
  66. /**
  67. * Back Title
  68. *
  69. * @var string
  70. */
  71. protected $_backTitle;
  72. /**
  73. * Back Content
  74. *
  75. * @var string
  76. */
  77. protected $_backContent;
  78. /**
  79. * Tile ID
  80. *
  81. * @var string
  82. */
  83. protected $_tileId;
  84. /**
  85. * Get Background Image
  86. *
  87. * @return string
  88. */
  89. public function getBackgroundImage()
  90. {
  91. return $this->_backgroundImage;
  92. }
  93. /**
  94. * Set Background Image
  95. *
  96. * @param string $bgImg
  97. * @return Zend_Mobile_Push_Message_Mpns_Tile
  98. * @throws Zend_Mobile_Push_Message_Exception
  99. */
  100. public function setBackgroundImage($bgImg)
  101. {
  102. if (!is_string($bgImg)) {
  103. throw new Zend_Mobile_Push_Message_Exception('$bgImg must be a string');
  104. }
  105. $this->_backgroundImage = $bgImg;
  106. return $this;
  107. }
  108. /**
  109. * Get Count
  110. *
  111. * @return int
  112. */
  113. public function getCount()
  114. {
  115. return $this->_count;
  116. }
  117. /**
  118. * Set Count
  119. *
  120. * @param int $count
  121. * @return Zend_Mobile_Push_Message_Mpns_Tile
  122. * @throws Zend_Mobile_Push_Message_Exception
  123. */
  124. public function setCount($count)
  125. {
  126. if (!is_numeric($count)) {
  127. throw new Zend_Mobile_Push_Message_Exception('$count is not numeric');
  128. }
  129. $this->_count = (int) $count;
  130. return $this;
  131. }
  132. /**
  133. * Get Title
  134. *
  135. * @return string
  136. */
  137. public function getTitle()
  138. {
  139. return $this->_title;
  140. }
  141. /**
  142. * Set Title
  143. *
  144. * @param string $title
  145. * @return Zend_Mobile_Push_Message_Mpns_Tile
  146. * @throws Zend_Mobile_Push_Message_Exception
  147. */
  148. public function setTitle($title)
  149. {
  150. if (!is_string($title)) {
  151. throw new Zend_Mobile_Push_Message_Exception('$title must be a string');
  152. }
  153. $this->_title = $title;
  154. return $this;
  155. }
  156. /**
  157. * Get Back Background Image
  158. *
  159. * @return string
  160. */
  161. public function getBackBackgroundImage()
  162. {
  163. return $this->_backBackgroundImage;
  164. }
  165. /**
  166. * Set Back Background Image
  167. *
  168. * @param string $bgImg
  169. * @return Zend_Mobile_Push_Message_Mpns_Tile
  170. * @throws Zend_Mobile_Push_Message_Exception
  171. */
  172. public function setBackBackgroundImage($bgImg)
  173. {
  174. if (!is_string($bgImg)) {
  175. throw new Zend_Mobile_Push_Message_Exception('$bgImg must be a string');
  176. }
  177. $this->_backBackgroundImage = $bgImg;
  178. return $this;
  179. }
  180. /**
  181. * Get Back Title
  182. *
  183. * @return string
  184. */
  185. public function getBackTitle()
  186. {
  187. return $this->_backTitle;
  188. }
  189. /**
  190. * Set Back Title
  191. *
  192. * @param string $title
  193. * @return Zend_Mobile_Push_Message_Mpns_Tile
  194. * @throws Zend_Mobile_Push_Message_Exception
  195. */
  196. public function setBackTitle($title)
  197. {
  198. if (!is_string($title)) {
  199. throw new Zend_Mobile_Push_Message_Exception('$title must be a string');
  200. }
  201. $this->_backTitle = $title;
  202. return $this;
  203. }
  204. /**
  205. * Get Back Content
  206. *
  207. * @return string
  208. */
  209. public function getBackContent()
  210. {
  211. return $this->_backContent;
  212. }
  213. /**
  214. * Set Back Content
  215. *
  216. * @param string $content
  217. * @return Zend_Mobile_Push_Message_Mpns_Tile
  218. * @throws Zend_Mobile_Push_Message_Exception
  219. */
  220. public function setBackContent($content)
  221. {
  222. if (!is_string($content)) {
  223. throw new Zend_Mobile_Push_Message_Exception('$content must be a string');
  224. }
  225. $this->_backContent = $content;
  226. }
  227. /**
  228. * Get Tile Id
  229. *
  230. * @return string
  231. */
  232. public function getTileId()
  233. {
  234. return $this->_tileId;
  235. }
  236. /**
  237. * Set Tile Id
  238. *
  239. * @param string $tileId
  240. * @return Zend_Mobile_Push_Message_Mpns_Tile
  241. * @throws Zend_Mobile_Push_Message_Exception
  242. */
  243. public function setTileId($tileId)
  244. {
  245. if (!is_string($tileId)) {
  246. throw new Zend_Mobile_Push_Message_Exception('$tileId is not a string');
  247. }
  248. $this->_tileId = $tileId;
  249. return $this;
  250. }
  251. /**
  252. * Get Delay
  253. *
  254. * @return int
  255. */
  256. public function getDelay()
  257. {
  258. if (!$this->_delay) {
  259. return self::DELAY_IMMEDIATE;
  260. }
  261. return $this->_delay;
  262. }
  263. /**
  264. * Set Delay
  265. *
  266. * @param int $delay
  267. * @return Zend_Mobile_Push_Message_Mpns_Tile
  268. * @throws Zend_Mobile_Push_Message_Exception
  269. */
  270. public function setDelay($delay)
  271. {
  272. if (!in_array($delay, array(
  273. self::DELAY_IMMEDIATE,
  274. self::DELAY_450S,
  275. self::DELAY_900S
  276. ))) {
  277. throw new Zend_Mobile_Push_Message_Exception('$delay must be one of the DELAY_* constants');
  278. }
  279. $this->_delay = $delay;
  280. return $this;
  281. }
  282. /**
  283. * Get Notification Type
  284. *
  285. * @return string
  286. */
  287. public static function getNotificationType()
  288. {
  289. return 'token';
  290. }
  291. /**
  292. * Get XML Payload
  293. *
  294. * @return string
  295. */
  296. public function getXmlPayload()
  297. {
  298. $ret = '<?xml version="1.0" encoding="utf-8"?>'
  299. . '<wp:Notification xmlns:wp="WPNotification">'
  300. . '<wp:Tile' . (($this->_tileId) ? ' Id="' . htmlspecialchars($this->_tileId) . '"' : '') . '>'
  301. . '<wp:BackgroundImage>' . htmlspecialchars($this->_backgroundImage) . '</wp:BackgroundImage>'
  302. . '<wp:Count>' . (int) $this->_count . '</wp:Count>'
  303. . '<wp:Title>' . htmlspecialchars($this->_title) . '</wp:Title>';
  304. if ($this->_backBackgroundImage) {
  305. $ret .= '<wp:BackBackgroundImage>' . htmlspecialchars($this->_backBackgroundImage) . '</wp:BackBackgroundImage>';
  306. }
  307. if ($this->_backTitle) {
  308. $ret .= '<wp:BackTitle>' . htmlspecialchars($this->_backTitle) . '</wp:BackTitle>';
  309. }
  310. if ($this->_backContent) {
  311. $ret .= '<wp:BackContent>' . htmlspecialchars($this->_backContent) . '</wp:BackContent>';
  312. }
  313. $ret .= '</wp:Tile>'
  314. . '</wp:Notification>';
  315. return $ret;
  316. }
  317. /**
  318. * Validate proper mpns message
  319. *
  320. * @return boolean
  321. */
  322. public function validate()
  323. {
  324. if (!isset($this->_token) || strlen($this->_token) === 0) {
  325. return false;
  326. }
  327. if (empty($this->_backgroundImage)) {
  328. return false;
  329. }
  330. if (empty($this->_title)) {
  331. return false;
  332. }
  333. return parent::validate();
  334. }
  335. }