source: branches/2.4/prototype/rest/catalog/ContactsResource.php @ 7442

Revision 7442, 3.1 KB checked in by eduardow, 11 years ago (diff)

Ticket #3093 - Integrando API Rest (CELEPAR) - commit para o branches.

Line 
1<?php
2
3class ContactsResource extends CatalogAdapter {
4        public function post($request){
5                // to Receive POST Params (use $this->params)
6                parent::post($request);
7               
8                if($this-> isLoggedIn())
9                {                       
10                       
11                        if($this->getParams()) {
12                                $search = trim($this->getParam('search'));
13                                $search = ($search ? mb_convert_encoding($search,"ISO_8859-1", "UTF8") : "");
14                               
15                                if($this->getParam('contactType') == 1) {
16                                        if($search != "") {
17                                                $query_contact = "(A.alias ilike '%$search%' or A.names_ordered ilike '%$search%' or C.connection_value ilike '%$search%') and";
18                                        }
19                                        elseif($this->getParam('contactID') > 0){
20                                                $query_contact = 'A.id_contact='.$this->getParam('contactID').' and';
21                                        }
22                                }
23                                elseif($this->getParam('contactType') == 2){
24                                        if($this-> getMinArgumentSearch() <= strlen($search))
25                                                return $this->getGlobalContacts($search, $this->getParam('contactID'));
26                                        else{
27                                                Errors::runException("CATALOG_MIN_ARGUMENT_SEARCH", $this-> getMinArgumentSearch());
28                                        }
29                                }
30                        }
31               
32                        $query = 'select B.id_typeof_contact_connection, A.photo, A.id_contact, A.alias, A.given_names, A.family_names, A.names_ordered, A.birthdate, A.notes, C.connection_value from phpgw_cc_contact A, '.
33                                        'phpgw_cc_contact_conns B, phpgw_cc_connections C where A.id_contact = B.id_contact and B.id_connection = C.id_connection '.
34                                        ' and '.$query_contact.' A.id_owner='.$this -> getUserId().' group by '.
35                                        ' B.id_typeof_contact_connection, A.photo, A.id_contact, A.alias, A.given_names, A.family_names,A.names_ordered,A.birthdate, A.notes,C.connection_value order by lower(A.names_ordered)';
36               
37                        if (!$this->getDb()->query($query))
38                                return false;
39               
40                        $contacts = array();
41                        while($this->getDb()->next_record()) {
42                                $row = $this->getDb()->row();
43                                $id = $row['id_contact'];
44                                $contactType = ($row['id_typeof_contact_connection'] == 2 ? 'contactPhones' : 'contactMails');
45               
46                                if($contacts[$id] != null){
47                                        $contacts[$id][$contactType][] = $row['connection_value'];
48                                }
49                                else{
50                                        $contacts[$id] = array(
51                                                        'contactID'             => $row['id_contact'],
52                                                        $contactType    => array($row['connection_value']),
53                                                        'contactAlias' => ($row['alias'] != null ?  mb_convert_encoding($row['alias'],"UTF8", "ISO_8859-1") : ""),
54                                                        'contactFirstName'      => ($row['given_names'] != null ?  mb_convert_encoding($row['given_names'],"UTF8", "ISO_8859-1") : ""),
55                                                        'contactLastName'       => ($row['family_names'] != null ?  mb_convert_encoding($row['family_names'],"UTF8", "ISO_8859-1") : ""),
56                                                        'contactFullName'       => ($row['names_ordered'] != null ? mb_convert_encoding($row['names_ordered'],"UTF8", "ISO_8859-1") : ""),
57                                                        'contactBirthDate'      => ($row['birthdate'] != null ? $row['birthdate'] : ""),
58                                                        'contactNotes'          => ($row['notes'] != null ?  mb_convert_encoding($row['notes'],"UTF8", "ISO_8859-1") : ""),
59                                                        'contactHasImagePicture' => ($row['photo'] != null ? 1 : 0),
60                                        );
61                                }
62                        }
63                        $result = array ('contacts' => array_values($contacts));
64                        $this->setResult($result);
65                }
66                //to Send Response (JSON RPC format)
67                return $this->getResponse();           
68        }       
69
70}
Note: See TracBrowser for help on using the repository browser.