|
1 <?php |
|
2 |
|
3 /** |
|
4 * Zend Framework |
|
5 * |
|
6 * LICENSE |
|
7 * |
|
8 * This source file is subject to the new BSD license that is bundled |
|
9 * with this package in the file LICENSE.txt. |
|
10 * It is also available through the world-wide-web at this URL: |
|
11 * http://framework.zend.com/license/new-bsd |
|
12 * If you did not receive a copy of the license and are unable to |
|
13 * obtain it through the world-wide-web, please send an email |
|
14 * to license@zend.com so we can send you a copy immediately. |
|
15 * |
|
16 * @category Zend |
|
17 * @package Zend_Service |
|
18 * @subpackage DeveloperGarden |
|
19 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
20 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
21 * @version $Id: SendSmsAbstract.php 20418 2010-01-19 11:43:30Z bate $ |
|
22 */ |
|
23 |
|
24 /** |
|
25 * @see Zend_Service_DeveloperGarden_Request_RequestAbstract |
|
26 */ |
|
27 require_once 'Zend/Service/DeveloperGarden/Request/RequestAbstract.php'; |
|
28 |
|
29 /** |
|
30 * @category Zend |
|
31 * @package Zend_Service |
|
32 * @subpackage DeveloperGarden |
|
33 * @copyright Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com) |
|
34 * @author Marco Kaiser |
|
35 * @license http://framework.zend.com/license/new-bsd New BSD License |
|
36 */ |
|
37 abstract class Zend_Service_DeveloperGarden_Request_SendSms_SendSmsAbstract |
|
38 extends Zend_Service_DeveloperGarden_Request_RequestAbstract |
|
39 { |
|
40 /** |
|
41 * the number or numbers to receive this sms |
|
42 * |
|
43 * @var string |
|
44 */ |
|
45 public $number = null; |
|
46 |
|
47 /** |
|
48 * the message of this sms |
|
49 * |
|
50 * @var string |
|
51 */ |
|
52 public $message = null; |
|
53 |
|
54 /** |
|
55 * name of the sender |
|
56 * |
|
57 * @var string |
|
58 */ |
|
59 public $originator = null; |
|
60 |
|
61 /** |
|
62 * account |
|
63 * |
|
64 * @var integer |
|
65 */ |
|
66 public $account = null; |
|
67 |
|
68 /** |
|
69 * array of special chars that are used for counting |
|
70 * message length |
|
71 * |
|
72 * @var array |
|
73 */ |
|
74 private $_specialChars = array( |
|
75 '|', |
|
76 '^', |
|
77 '{', |
|
78 '}', |
|
79 '[', |
|
80 ']', |
|
81 '~', |
|
82 '\\', |
|
83 "\n", |
|
84 // '€', removed because its counted in utf8 correctly |
|
85 ); |
|
86 |
|
87 /** |
|
88 * what SMS type is it |
|
89 * |
|
90 * 1 = SMS |
|
91 * 2 = FlashSMS |
|
92 * |
|
93 * @var integer |
|
94 */ |
|
95 protected $_smsType = 1; |
|
96 |
|
97 /** |
|
98 * the counter for increasing message count |
|
99 * if more than this 160 chars we send a 2nd or counting |
|
100 * sms message |
|
101 * |
|
102 * @var integer |
|
103 */ |
|
104 protected $_smsLength = 153; |
|
105 |
|
106 /** |
|
107 * maximum length of an sms message |
|
108 * |
|
109 * @var integer |
|
110 */ |
|
111 protected $_maxLength = 765; |
|
112 |
|
113 /** |
|
114 * the maximum numbers to send an sms |
|
115 * |
|
116 * @var integer |
|
117 */ |
|
118 protected $_maxNumbers = 10; |
|
119 |
|
120 /** |
|
121 * returns the assigned numbers |
|
122 * |
|
123 * @return string $number |
|
124 */ |
|
125 public function getNumber() |
|
126 { |
|
127 return $this->number; |
|
128 } |
|
129 |
|
130 /** |
|
131 * set a new number(s) |
|
132 * |
|
133 * @param string $number |
|
134 * @throws Zend_Service_DeveloperGarden_Request_Exception |
|
135 * |
|
136 * @return Zend_Service_DeveloperGarden_Request_SendSms_SendSmsAbstract |
|
137 */ |
|
138 public function setNumber($number) |
|
139 { |
|
140 $this->number = $number; |
|
141 if ($this->getNumberCount() > $this->_maxNumbers) { |
|
142 require_once 'Zend/Service/DeveloperGarden/Request/Exception.php'; |
|
143 throw new Zend_Service_DeveloperGarden_Request_Exception('The message is too long.'); |
|
144 } |
|
145 return $this; |
|
146 } |
|
147 |
|
148 /** |
|
149 * returns the current message |
|
150 * |
|
151 * @return string $message |
|
152 */ |
|
153 public function getMessage() |
|
154 { |
|
155 return $this->message; |
|
156 } |
|
157 |
|
158 /** |
|
159 * sets a new message |
|
160 * |
|
161 * @param string $message |
|
162 * @throws Zend_Service_DeveloperGarden_Request_Exception |
|
163 * |
|
164 * @return Zend_Service_DeveloperGarden_Request_SendSms_SendSmsAbstract |
|
165 */ |
|
166 public function setMessage($message) |
|
167 { |
|
168 $this->message = $message; |
|
169 if ($this->getMessageLength() > $this->_maxLength) { |
|
170 require_once 'Zend/Service/DeveloperGarden/Request/Exception.php'; |
|
171 throw new Zend_Service_DeveloperGarden_Request_Exception('The message is too long.'); |
|
172 } |
|
173 return $this; |
|
174 } |
|
175 |
|
176 /** |
|
177 * returns the originator |
|
178 * |
|
179 * @return the $originator |
|
180 */ |
|
181 public function getOriginator() |
|
182 { |
|
183 return $this->originator; |
|
184 } |
|
185 |
|
186 /** |
|
187 * the originator name |
|
188 * |
|
189 * @param string $originator |
|
190 * @return Zend_Service_DeveloperGarden_Request_SendSms_SendSmsAbstract |
|
191 */ |
|
192 public function setOriginator($originator) |
|
193 { |
|
194 $this->originator = $originator; |
|
195 return $this; |
|
196 } |
|
197 |
|
198 /** |
|
199 * the account |
|
200 * @return integer $account |
|
201 */ |
|
202 public function getAccount() |
|
203 { |
|
204 return $this->account; |
|
205 } |
|
206 |
|
207 /** |
|
208 * sets a new accounts |
|
209 * |
|
210 * @param $account the $account to set |
|
211 * @return Zend_Service_DeveloperGarden_Request_SendSms_SendSmsAbstract |
|
212 */ |
|
213 public function setAccount($account) |
|
214 { |
|
215 $this->account = $account; |
|
216 return $this; |
|
217 } |
|
218 |
|
219 /** |
|
220 * returns the calculated message length |
|
221 * |
|
222 * @return integer |
|
223 */ |
|
224 public function getMessageLength() |
|
225 { |
|
226 $message = $this->getMessage(); |
|
227 $length = strlen($message); |
|
228 |
|
229 foreach ($this->_specialChars as $char) { |
|
230 $c = (substr_count($message, $char) * 2) - 1; |
|
231 if ($c > 0) { |
|
232 $length += $c; |
|
233 } |
|
234 } |
|
235 |
|
236 return $length; |
|
237 } |
|
238 |
|
239 /** |
|
240 * returns the count of sms messages that would be send |
|
241 * |
|
242 * @return integer |
|
243 */ |
|
244 public function getMessageCount() |
|
245 { |
|
246 $smsLength = $this->getMessageLength(); |
|
247 $retValue = 1; |
|
248 if ($smsLength > 160) { |
|
249 $retValue = ceil($smsLength / $this->_smsLength); |
|
250 } |
|
251 return $retValue; |
|
252 } |
|
253 |
|
254 /** |
|
255 * returns the count of numbers in this sms |
|
256 * |
|
257 * @return integer |
|
258 */ |
|
259 public function getNumberCount() |
|
260 { |
|
261 $number = $this->getNumber(); |
|
262 $retValue = 0; |
|
263 if (!empty($number)) { |
|
264 $retValue = count(explode(',', $number)); |
|
265 } |
|
266 return $retValue; |
|
267 } |
|
268 |
|
269 /** |
|
270 * returns the sms type |
|
271 * currently we have |
|
272 * 1 = Sms |
|
273 * 2 = FlashSms |
|
274 * |
|
275 * @return integer |
|
276 */ |
|
277 public function getSmsType() |
|
278 { |
|
279 return $this->_smsType; |
|
280 } |
|
281 } |