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