1: <?php
2:
3: namespace SMSApi\Api\Action\Vms;
4:
5: use SMSApi\Api\Action\AbstractAction;
6: use SMSApi\Api\Response\StatusResponse;
7: use SMSApi\Proxy\Uri;
8:
9: /**
10: * Class Send
11: * @package SMSApi\Api\Action\Vms
12: *
13: * @method StatusResponse execute()
14: */
15: class Send extends AbstractAction
16: {
17: const LECTOR_AGNIESZKA = "agnieszka";
18: const LECTOR_EWA = "ewa";
19: const LECTOR_JACEK = "jacek";
20: const LECTOR_JAN = "jan";
21: const LECTOR_MAJA = "maja";
22:
23: /**
24: * @var
25: */
26: private $tts;
27:
28: /**
29: * @var
30: */
31: private $file;
32:
33: /**
34: * @param $data
35: * @return StatusResponse
36: */
37: protected function response($data)
38: {
39: return new StatusResponse($data);
40: }
41:
42: /**
43: * @return Uri
44: * @throws \SMSApi\Exception\ActionException
45: */
46: public function uri() {
47:
48: $query = "";
49:
50: $query .= $this->paramsLoginToQuery();
51:
52: $query .= $this->paramsBasicToQuery();
53:
54: $query .= $this->paramsOther();
55:
56: if ( empty( $this->file ) && $this->tts != null ) {
57: $query .= "&tts=" . $this->tts;
58: }
59:
60: return new Uri( $this->proxy->getProtocol(), $this->proxy->getHost(), $this->proxy->getPort(), "/api/vms.do", $query );
61: }
62:
63: /**
64: * @return mixed
65: */
66: public function file() {
67: return $this->file;
68: }
69:
70: /**
71: * Set mobile phone number of the recipients.
72: *
73: * @param $to array|string phone number
74: * @return $this
75: */
76: public function setTo( $to ) {
77:
78: if ( !is_array( $to ) ) {
79: $to = array( $to );
80: }
81:
82: $this->to->exchangeArray( $to );
83: return $this;
84: }
85:
86: /**
87: * Set name of the group from the phone book to which message should be sent.
88: *
89: * @param string $group group name
90: * @return $this
91: */
92: public function setGroup( $group ) {
93: $this->group = $group;
94: return $this;
95: }
96:
97: /**
98: * Set scheduled date sending message.
99: *
100: * Setting a past date will result in sending message instantly.
101: *
102: * @param $date
103: * @return $this
104: */
105: public function setDateSent( $date ) {
106: $this->date = $date;
107: return $this;
108: }
109:
110: /**
111: * Set optional custom value sent with SMS and sent back in CALLBACK.
112: *
113: * @param string|array $idx
114: * @return $this
115: */
116: public function setIDx( $idx ) {
117: if ( !is_array( $idx ) ) {
118: $idx = array( $idx );
119: }
120:
121: $this->idx->exchangeArray( $idx );
122: return $this;
123: }
124:
125: /**
126: * Set checking idx is unique.
127: *
128: * Prevents from sending more than one message with the same idx.
129: * When this parameter is set and message with the same idx was
130: * already sent error 53 is returned.
131: *
132: * @param bool $check
133: * @return $this
134: */
135: public function setCheckIDx( $check ) {
136: if ( $check == true ) {
137: $this->params[ "check_idx" ] = "1";
138: } else if ( $check == false ) {
139: $this->params[ "check_idx" ] = "0";
140: }
141:
142: return $this;
143: }
144:
145: /**
146: * Set affiliate code.
147: *
148: * @param string $partner affiliate code
149: * @return $this
150: */
151: public function setPartner( $partner ) {
152: $this->params[ "partner_id" ] = $partner;
153: return $this;
154: }
155:
156: /**
157: * Set local audio filename.
158: *
159: * @param $file
160: * @return $this
161: */
162: public function setFile( $file ) {
163: $this->file = $file;
164: return $this;
165: }
166:
167: /**
168: * Set text to voice synthesizer.
169: *
170: * @param string $tts text to read
171: * @return $this
172: */
173: public function setTts( $tts ) {
174: $this->tts = $tts;
175: return $this;
176: }
177:
178: /**
179: * Set flag to not send messages on cell phone numbers.
180: *
181: * @param $skipGsm
182: * @return $this
183: */
184: public function setSkipGsm( $skipGsm ) {
185:
186: if ( $skipGsm == true ) {
187: $this->params[ "skip_gsm" ] = "1";
188: } else if ( $skipGsm == false && isset( $this->params[ "skip_gsm" ] ) ) {
189: unset( $this->params[ "skip_gsm" ] );
190: }
191:
192: return $this;
193: }
194:
195: /**
196: * Set lector name.
197: *
198: * @param string $lector The value of $lector can be: agnieszka, ewa, jacek, jan or maja
199: * @return $this
200: */
201: public function setTtsLector( $lector ) {
202: $this->params[ "tts_lector" ] = $lector;
203: return $this;
204: }
205:
206: /**
207: * Set called number. Leaving the field blank causes the sending of the default number of callers.
208: *
209: * @param $from
210: * @return $this
211: */
212: public function setFrom( $from ) {
213: $this->params[ "from" ] = $from;
214: return $this;
215: }
216:
217: /**
218: * Set number of connection attempts.
219: *
220: * @param integer $try Number of connection attempts
221: * @return $this
222: * @throws \OutOfRangeException
223: */
224: public function setTry($try)
225: {
226: if($try < 1 || $try > 6) {
227: throw new \OutOfRangeException;
228: }
229:
230: $this->params['try'] = $try;
231: return $this;
232: }
233:
234: /**
235: * Set the time in seconds where the connection have to be repeated
236: * in the case of not answer by receiver or reject this connection.
237: *
238: * @param integer $interval Time in seconds
239: *
240: * @return $this
241: * @throws \OutOfRangeException
242: */
243: public function setInterval($interval)
244: {
245: if($interval < 300 || $interval > 7200) {
246: throw new \OutOfRangeException;
247: }
248:
249: $this->params['interval'] = $interval;
250: return $this;
251: }
252:
253: }