1: <?php
2:
3: namespace SMSApi\Api\Action\Phonebook;
4:
5: use SMSApi\Api\Action\AbstractAction;
6: use SMSApi\Proxy\Uri;
7:
8: /**
9: * Class ContactAdd
10: * @package SMSApi\Api\Action\Phonebook
11: */
12: class ContactAdd extends AbstractAction {
13:
14: /**
15: * @var \ArrayObject
16: */
17: private $groups;
18:
19: /**
20: *
21: */
22: function __construct() {
23: $this->groups = new \ArrayObject();
24: }
25:
26: /**
27: * @param $data
28: * @return \SMSApi\Api\Response\ContactResponse
29: */
30: protected function response( $data ) {
31:
32: return new \SMSApi\Api\Response\ContactResponse( $data );
33: }
34:
35: /**
36: * @return Uri
37: */
38: public function uri() {
39:
40: $query = "";
41:
42: $query .= $this->paramsLoginToQuery();
43:
44: $query .= $this->paramsOther();
45:
46: if ( count( $this->groups ) > 0 ) {
47: $query .= "&groups=" . implode( ",", $this->groups->getArrayCopy() );
48: }
49:
50: return new Uri( $this->proxy->getProtocol(), $this->proxy->getHost(), $this->proxy->getPort(), "/api/phonebook.do", $query );
51: }
52:
53: /**
54: * Set contact phone number.
55: *
56: * @param string|int $number
57: * @return $this
58: */
59: public function setNumber( $number ) {
60: $this->params[ "add_contact" ] = $number;
61: return $this;
62: }
63:
64: /**
65: * Set contact first name.
66: *
67: * @param string $firstName
68: * @return $this
69: */
70: public function setFirstName( $firstName ) {
71: $this->params[ "first_name" ] = $firstName;
72: return $this;
73: }
74:
75: /**
76: * Set contact last name.
77: *
78: * @param string $lastName
79: * @return $this
80: */
81: public function setLastName( $lastName ) {
82: $this->params[ "last_name" ] = $lastName;
83: return $this;
84: }
85:
86: /**
87: * Set additional contact description.
88: *
89: * @param string $info
90: * @return $this
91: */
92: public function setInfo( $info ) {
93: $this->params[ "info" ] = $info;
94: return $this;
95: }
96:
97: /**
98: * Set contact email address.
99: *
100: * @param $email
101: * @return $this
102: */
103: public function setEmail( $email ) {
104: $this->params[ "email" ] = $email;
105: return $this;
106: }
107:
108: /**
109: * Set contact birthday date.
110: *
111: * @param string $birthday
112: * @return $this
113: */
114: public function setBirthday( $birthday ) {
115: $this->params[ "birthday" ] = $birthday;
116: return $this;
117: }
118:
119: /**
120: * Set contact city.
121: *
122: * @param string $city
123: * @return $this
124: */
125: public function setCity( $city ) {
126: $this->params[ "city" ] = $city;
127: return $this;
128: }
129:
130: /**
131: * Set contact gender.
132: *
133: * @param string $gender female, male, unknown
134: * @return $this
135: */
136: public function setGender( $gender ) {
137: $this->params[ "gender" ] = $gender;
138: return $this;
139: }
140:
141: /**
142: * Set contact to group.
143: * Others contact groups will be removed.
144: *
145: * @param string $group group name
146: * @return $this
147: */
148: public function setGroup( $group ) {
149: $this->groups->append( $group );
150: return $this;
151: }
152:
153: /**
154: * Set contact to groups.
155: * Others contact groups will be removed.
156: *
157: * @param array $groups array with groups names
158: * @return $this
159: */
160: public function setGroups( array $groups ) {
161: $this->groups->exchangeArray( $groups );
162: return $this;
163: }
164:
165: }
166:
167: