Ignore:
Timestamp:
04/24/12 17:07:07 (12 years ago)
Author:
niltonneto
Message:

Ticket #2507 - Modificada implementação para alinhamento com projeto de camada REST.

Location:
sandbox/webservice/api/rest
Files:
2 added
1 copied

Legend:

Unmodified
Added
Removed
  • sandbox/webservice/api/rest/catalog/Catalog.php

    r5956 r6019  
    11<?php 
    22 
    3 include_once("Expresso.php"); 
    43 
    54class Catalog extends Expresso {         
    6         var $searchCharactersNumber; 
     5        var $minArgumentSearch; 
    76        var $userId; 
    87 
     
    109                parent::__construct($id); 
    1110                $prefs = $GLOBALS['phpgw']->preferences->read(); 
    12                 $this-> searchCharactersNumber = $prefs['expressoMail']['search_characters_number']; 
     11                $this-> setMinArgumentSearch($prefs['expressoMail']['search_characters_number']); 
    1312        } 
    1413         
    15         private function getUserId(){ 
     14        protected function setMinArgumentSearch($minArgumentSearch){ 
     15                $this->minArgumentSearch = $minArgumentSearch; 
     16        } 
     17         
     18        protected function getMinArgumentSearch(){ 
     19                return $this-> minArgumentSearch; 
     20        } 
     21         
     22        protected function getUserId(){ 
    1623                $userProfile = $this->getUserProfile(); 
    1724                return $userProfile['contactID']; 
    18         } 
    19          
    20         public function getUserContacts($params){ 
    21                 if($this->isLoggedIn($params)) { 
    22                         $search = ""; 
    23                         if($params) { 
    24                                 $search = trim($params['search']); 
    25                                 if($search != "") { 
    26                                         $search = mb_convert_encoding($search,"ISO_8859-1", "UTF8"); 
    27                                 } 
    28                                  
    29                                 if($params['contactID'] > 0 && $params['contactType'] == 1){ 
    30                                         $query_contact = 'A.id_contact='.$params['contactID'].' and'; 
    31                                 } 
    32                                 elseif($params['contactType'] == 2){ 
    33                                         if($this-> searchCharactersNumber <= strlen($search)) 
    34                                                 return $this->getGlobalContacts($search, $params['contactID']); 
    35                                         else{ 
    36                                                 $this-> error = Errors::get(Errors::CATALOG_MIN_ARGUMENT_SEARCH); 
    37                                                 $this-> error = str_replace("%1",$this-> searchCharactersNumber,$this->error); 
    38                                                 return $this->getResponse(); 
    39                                         } 
    40                                 } 
    41                         } 
    42                          
    43                         $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, '. 
    44                                 'phpgw_cc_contact_conns B, phpgw_cc_connections C where A.id_contact = B.id_contact and B.id_connection = C.id_connection '. 
    45                                 ' and '.$query_contact.' A.id_owner='.$this -> getUserId().' group by '. 
    46                                 ' 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)'; 
    47                          
    48                         if (!$this->getDb()->query($query)) 
    49                                 return false; 
    50                          
    51                         $contacts = array(); 
    52                         while($this->getDb()->next_record()) { 
    53                                 $row = $this->getDb()->row(); 
    54                                 $id = $row['id_contact']; 
    55                                 $contactType = ($row['id_typeof_contact_connection'] == 2 ? 'contactPhones' : 'contactMails');                           
    56                                  
    57                                 if($contacts[$id] != null){ 
    58                                         $contacts[$id][$contactType][] = $row['connection_value']; 
    59                                 }        
    60                                 else{ 
    61                                         $contacts[$id] = array( 
    62                                                 'contactID'             => $row['id_contact'], 
    63                                                 $contactType    => array($row['connection_value']),                                              
    64                                                 'contactAlias' => ($row['alias'] != null ?  mb_convert_encoding($row['alias'],"UTF8", "ISO_8859-1") : ""), 
    65                                                 'contactFirstName'      => ($row['given_names'] != null ?  mb_convert_encoding($row['given_names'],"UTF8", "ISO_8859-1") : ""), 
    66                                                 'contactLastName'       => ($row['family_names'] != null ?  mb_convert_encoding($row['family_names'],"UTF8", "ISO_8859-1") : ""), 
    67                                                 'contactFullName'       => ($row['names_ordered'] != null ? mb_convert_encoding($row['names_ordered'],"UTF8", "ISO_8859-1") : ""), 
    68                                                 'contactBirthDate'      => ($row['birthdate'] != null ? $row['birthdate'] : ""), 
    69                                                 'contactNotes'          => ($row['notes'] != null ?  mb_convert_encoding($row['notes'],"UTF8", "ISO_8859-1") : ""), 
    70                                                 'contactHasImagePicture' => ($row['photo'] != null ? 1 : 0), 
    71                                         ); 
    72                                         if($search != null &&  
    73                                                         stristr($contacts[$id]['contactAlias'], $search) == null && 
    74                                                         stristr($contacts[$id]['contactFirstName'], $search) == null && 
    75                                                         stristr($contacts[$id]['contactLastName'], $search) == null && 
    76                                                         stristr($contacts[$id]['contactFullName'], $search) == null && 
    77                                                         stristr($contacts[$id]['contactBirthDate'], $search) == null && 
    78                                                         stristr($contacts[$id]['contactNotes'], $search) == null){ 
    79                                                 unset($contacts[$id]); 
    80                                         } 
    81                                 }                                
    82                         } 
    83                         $this->result = array ('contacts' => array_values($contacts)); 
    84                 } 
    85                 return $this->getResponse(); 
    86         }        
    87          
    88         public function getImagePicture($params){                
    89                 if($this->isLoggedIn($params) && $params['contactID'] != null) { 
    90                         $contact = array(); 
    91                         // User Contact  
    92                         if($params['contactType'] == 1){ 
    93                                 $query = 'select A.id_contact, A.photo from phpgw_cc_contact A where A.id_contact='.$params['contactID'].' and A.id_owner='.$this -> getUserId();                
    94                                 if (!$this->getDb()->query($query)) 
    95                                         return false; 
    96                                 if($this->getDb()->next_record()) { 
    97                                         $row = $this->getDb()->row(); 
    98                                         if($row['photo'] != null) { 
    99                                                 $contact[] = array( 
    100                                                         'contactID'             => $row['id_contact'], 
    101                                                         'contactImagePicture'   => ($row['photo'] != null ? base64_encode($row['photo']) : "") 
    102                                                 ); 
    103                                         } 
    104                                 } 
    105                         } 
    106                         // Global Catalog                        
    107                         elseif($params['contactType'] == 2){ 
    108                                 $photo = $this->getUserLdapPhoto(urldecode($params['contactID'])); 
    109                                 $contact[] = array( 
    110                                                 'contactID'             => $params['contactID'], 
    111                                                 'contactImagePicture'   => ($photo != null ? base64_encode($photo[0]) : "") 
    112                                 ); 
    113                                  
    114                         }                        
    115                         $this->result = array ('contacts' => $contact); 
    116                 } 
    117                 return $this->getResponse(); 
    118         }        
     25        }                
    11926 
    120         private function getUserLdapAttrs($mail) 
     27        protected function getUserLdapAttrs($mail) 
    12128        { 
    12229                $filter="(&(phpgwAccountType=u)(mail=".$mail."))"; 
     
    14653        } 
    14754         
    148         private function getUserLdapPhoto($contactID) {          
     55        protected function getUserLdapPhoto($contactID) {                
    14956                $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn']; 
    15057                $justthese = array("dn", 'jpegPhoto','givenName', 'sn'); 
     
    16875        }        
    16976         
    170         private function getGlobalContacts($search, $uidNumber){ 
     77        protected function getGlobalContacts($search, $uidNumber){ 
    17178                $contacts = array(); 
    17279                $params = array ("search_for" => $search); 
     
    18895                        } 
    18996                } 
    190                 $this->result = array ('contacts' => $contacts); 
    191                  
     97                $result = array ('contacts' => $contacts); 
     98                $this->setResult($result); 
    19299                return $this->getResponse(); 
    193100        } 
Note: See TracChangeset for help on using the changeset viewer.