      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 ContactList
     10:  * @package SMSApi\Api\Action\Phonebook
     11:  */
     12: class ContactList 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\ContactsResponse
     29:      */
     30:     protected function response( $data ) {
     31:
     32:         return new \SMSApi\Api\Response\ContactsResponse( $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 ( !empty( $this->groups ) ) {
     47:             $query .= "&groups=" . implode( ";", $this->groups->getArrayCopy() );
     48:         }
     49:
     50:         $query .= "&list_contacts=1";
     51:
     52:         return new Uri( $this->proxy->getProtocol(), $this->proxy->getHost(), $this->proxy->getPort(), "/api/phonebook.do", $query );
     53:     }
     54:
     55:     /**
     56:      * @deprecated since v1.1.0
     57:      * @param $number
     58:      * @return $this
     59:      */
     60:     public function setNumber( $number ) {
     61:         $this->params[ "number" ] = $number;
     62:         return $this;
     63:     }
     64:
     65:     /**
     66:      * Set filter contacts by phone number.
     67:      *
     68:      * @param string|number $number phone number
     69:      * @return $this
     70:      */
     71:     public function filterByPhoneNumber( $number ) {
     72:         $this->params[ "number" ] = $number;
     73:         return $this;
     74:     }
     75:
     76:     /**
     77:      * @deprecated since v1.1.0
     78:      * @param $group
     79:      * @return $this
     80:      */
     81:     public function setGroup( $group ) {
     82:         $this->groups->append( $group );
     83:         return $this;
     84:     }
     85:
     86:
     87:     /**
     88:      * Set filter contacts by group name.
     89:      *
     90:      * @param string $group group name
     91:      * @return $this
     92:      */
     93:     public function filterByGroup( $group ) {
     94:         $this->groups->append( $group );
     95:         return $this;
     96:     }
     97:
     98:     /**
     99:      * Set filter contacts by group names.
    100:      *
    101:      * @param string[] $group array of group names
    102:      * @return $this
    103:      */
    104:     public function filterByGroups( array $groups ) {
    105:         $this->groups->exchangeArray( $groups );
    106:         return $this;
    107:     }
    108:
    109:     /**
    110:      * @deprecated since v1.0.0
    111:      * @param array $groups
    112:      * @return $this
    113:      */
    114:     public function setGroups( array $groups ) {
    115:         $this->groups->exchangeArray( $groups );
    116:         return $this;
    117:     }
    118:
    119:     /**
    120:      * @deprecated since v1.0.0
    121:      * @param $text
    122:      * @return $this
    123:      */
    124:     public function setText( $text ) {
    125:         $this->params[ "text_search" ] = $text;
    126:         return $this;
    127:     }
    128:
    129:
    130:     /**
    131:      * The result list will contain contacts with given chars string.
    132:      *
    133:      * @param string $text search string
    134:      * @return $this
    135:      */
    136:     public function search( $text ) {
    137:         $this->params[ "text_search" ] = $text;
    138:         return $this;
    139:     }
    140:
    141:     /**
    142:      * @deprecated since v1.1.0
    143:      * @param $gender
    144:      * @return $this
    145:      */
    146:     public function setGender( $gender ) {
    147:         $this->params[ "gender" ] = $gender;
    148:         return $this;
    149:     }
    150:
    151:     /**
    152:      * Set filter by gender.
    153:      *
    154:      * @param string $gender The value of $gender can be: male, female, unknown
    155:      * @return $this
    156:      */
    157:     public function filterByGender( $gender ) {
    158:         $this->params[ "gender" ] = $gender;
    159:         return $this;
    160:     }
    161:
    162:     /**
    163:      * Set order parameter.
    164:      *
    165:      * @param string $orderBy The value of $orderBy can be: first_name, last_name
    166:      * @return $this
    167:      */
    168:     public function setOrderBy( $orderBy ) {
    169:         $this->params[ "order_by" ] = $orderBy;
    170:
    171:         return $this;
    172:     }
    173:
    174:     /**
    175:      * Set order direction.
    176:      *
    177:      * @param string $orderDir The value of $orderBy can be: desc, asc
    178:      * @return $this
    179:      */
    180:     public function setOrderDir( $orderDir ) {
    181:         $this->params[ "order_dir" ] = $orderDir;
    182:         return $this;
    183:     }
    184:
    185:     /**
    186:      * Set result limit.
    187:      *
    188:      * @param int $limit Max limit is 200 contacts
    189:      * @return $this
    190:      */
    191:     public function setLimit( $limit ) {
    192:         $this->params[ "limit" ] = $limit;
    193:         return $this;
    194:     }
    195:
    196:     /**
    197:      * Set result offset.
    198:      *
    199:      * @param int $offset
    200:      * @return $this
    201:      */
    202:     public function setOffset( $offset ) {
    203:         $this->params[ "offset" ] = $offset;
    204:         return $this;
    205:     }
    206:
    207: }
    208: