source: sandbox/webservice/api/rest/catalog/Catalog.php @ 6019

Revision 6019, 3.1 KB checked in by niltonneto, 12 years ago (diff)

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

  • Property svn:executable set to *
Line 
1<?php
2
3
4class Catalog extends Expresso {       
5        var $minArgumentSearch;
6        var $userId;
7
8        public function __construct($id){
9                parent::__construct($id);
10                $prefs = $GLOBALS['phpgw']->preferences->read();
11                $this-> setMinArgumentSearch($prefs['expressoMail']['search_characters_number']);
12        }
13       
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(){
23                $userProfile = $this->getUserProfile();
24                return $userProfile['contactID'];
25        }               
26
27        protected function getUserLdapAttrs($mail)
28        {
29                $filter="(&(phpgwAccountType=u)(mail=".$mail."))";
30                $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
31                $justthese = array("dn", 'jpegPhoto','givenName', 'sn');
32                $this->getLdapCatalog()->ldapConnect(true);
33                $ds = $this->getLdapCatalog()->ds;
34                if ($ds){
35                        $sr = @ldap_search($ds, $ldap_context, $filter, $justthese);   
36                        if ($sr) {
37                                $entry = ldap_first_entry($ds, $sr);
38                                if($entry) {                                                                   
39                                        $givenName = @ldap_get_values_len($ds, $entry, "givenname");
40                                        $sn = @ldap_get_values_len($ds, $entry, "sn");
41                                        $contactHasImagePicture = (@ldap_get_values_len($ds, $entry, "jpegphoto") ? 1 : 0);
42                                        $dn = ldap_get_dn($ds, $entry);
43                                        return array(
44                                                "contactID" => urlencode($dn),
45                                                "contactFirstName" => $givenName[0],
46                                                "contactLastName"       => $sn[0],
47                                                "contactHasImagePicture" => $contactHasImagePicture
48                                        );
49                                }
50                        }
51                }
52                return false;
53        }
54       
55        protected function getUserLdapPhoto($contactID) {               
56                $ldap_context = $_SESSION['phpgw_info']['expressomail']['ldap_server']['dn'];
57                $justthese = array("dn", 'jpegPhoto','givenName', 'sn');
58                $this->getLdapCatalog()->ldapConnect(true);
59                $ds = $this->getLdapCatalog()->ds;             
60               
61                if ($ds){
62                        $resource = @ldap_read($ds, $contactID, "phpgwaccounttype=u");
63                        $n_entries = @ldap_count_entries($ds, $resource);
64
65                        if ( $n_entries == 1) {                 
66                                $first_entry = ldap_first_entry($ds, $resource);
67                                $obj = ldap_get_attributes($ds, $first_entry);
68                               
69                                if($obj['jpegPhoto']){
70                                        return ldap_get_values_len( $ds, $first_entry, "jpegPhoto");
71                                }
72                        }                                                               
73                }
74                return false;
75        }       
76       
77        protected function getGlobalContacts($search, $uidNumber){
78                $contacts = array();
79                $params = array ("search_for" => $search);
80                $result = $this->getLdapCatalog()->quicksearch($params);
81
82                foreach($result as $i => $row) {
83                        if(is_int($i)) {
84                                $contacts[$i] = array(
85                                        'contactMails'  => array($result[$i]['mail']),
86                                        'contactPhones' => array($result[$i]['phone']),
87                                        'contactAlias' => "",                                   
88                                        'contactFullName'       => ($result[$i]['cn'] != null ? mb_convert_encoding($row['cn'],"UTF8", "ISO_8859-1") : ""),
89                                        'contactBirthDate'      => "",
90                                        'contactNotes'          => ""
91                                );
92                                // Buscar atributos faltantes.
93                                if(is_array($this->getUserLdapAttrs($result[$i]['mail'])))
94                                        $contacts[$i] = array_merge($this->getUserLdapAttrs($result[$i]['mail']), $contacts[$i]);                               
95                        }
96                }
97                $result = array ('contacts' => $contacts);
98                $this->setResult($result);
99                return $this->getResponse();
100        }
101}
Note: See TracBrowser for help on using the repository browser.