source: branches/2.3/contactcenter/inc/class.bo_catalog_group_catalog.inc.php @ 5190

Revision 5190, 7.9 KB checked in by rafaelraymundo, 12 years ago (diff)

Ticket #2328 - Não mostra usuários na pesquisa por nome aos catálogos externos.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
Line 
1<?php
2  /***************************************************************************\
3  * eGroupWare - Contacts Center                                              *
4  * http://www.egroupware.org                                                 *
5  * Written by:                                                               *
6  *  - Raphael Derosso Pereira <raphaelpereira@users.sourceforge.net>         *
7  *  sponsored by Thyamad - http://www.thyamad.com
8  * ------------------------------------------------------------------------- *
9  *  This program is free software; you can redistribute it and/or modify it  *
10  *  under the terms of the GNU General Public License as published by the    *
11  *  Free Software Foundation; either version 2 of the License, or (at your   *
12  *  option) any later version.                                               *
13  \***************************************************************************/
14
15
16        /* This is a special class that handles requests to a catalog that is actually
17         * a catalog group. So this class actually performs all the requests in its
18         * catalog childs.
19         */
20
21        include_once('class.abo_catalog.inc.php');
22       
23        class bo_catalog_group_catalog extends abo_catalog
24        {
25                var $external;
26                var $fields = array(
27                        'id_contact'    => true,
28                        'status'        => true,
29                        'photo'         => true,
30                        'alias'         => true,
31                        'prefix'        => true,
32                        'given_names'   => true,
33                        'family_names'  => true,
34                        'names_ordered' => true,
35                        'suffix'        => true,
36                        'birthdate'     => true,
37                        'sex'           => true,
38                        'pgp_key'       => true,
39                        'notes'         => true,
40                       
41                        /* Array fields */
42                        'companies'     => true,
43                        'relations'     => true,
44                        'addresses'     => true,
45                        'connections'   => true
46                );
47       
48                /*!
49               
50                 @function bo_people_catalog
51                 @abstract Constructor
52                 @author Raphael Derosso Pereira
53                 
54                */
55                function bo_catalog_group_catalog(& $bo_contactcenter, & $catalog, $external = 0 )
56                {
57                        $this->bo_contactcenter = & $bo_contactcenter;
58                        $this->catalog = & $catalog;
59                        $this->external = $external;
60                }
61                       
62
63                /*!
64
65                 @function find
66                 @abstract Returns all the IDs of the entries found in all child
67                        catalogues that corresponds to the specified rules.
68                 @author Raphael Derosso Pereira
69
70                 @param SEE class bo_contactcenter for usage
71               
72                */
73                function find($what, $rules, $other, $area=false, $recursive=false)
74                {
75                        if ($ldap_info = $this->catalog['ldap'])
76                        {
77                                $meta_catalog =& CreateObject('contactcenter.bo_global_ldap_catalog',$ldap_info['id_source'], $ldap_info['context'], $this->external);
78                                if ($meta_catalog->src_info)
79                                {
80                                    $recursive = $meta_catalog->src_info['recursive'];
81                                }
82                                return $meta_catalog->find($what, $rules, $other, $area, $recursive);
83                        }
84                       
85                        $results = array();
86                       
87                        reset($this->catalog);
88                        while(list(, $new_catalog) = each($this->catalog['sub_branch']))
89                        {
90                                //print_r($new_catalog);
91                                //echo 'Setting catalog: <b>'.$new_catalog['name'].'</b><br>';
92                                $new_catalog = $this->bo_contactcenter->set_catalog($new_catalog);
93                               
94                                //if($new_catalog) echo 'Setado corretamente!<br><br>'; else echo 'Erro ao setar<br><br>';
95                               
96                                if ($new_catalog['type'] === 'empty')
97                                {
98                                        continue;
99                                }
100                               
101                                $temp_res = $this->bo_contactcenter->catalog->find($what, $rules, $other, false, $recursive);
102                                if (is_array($temp_res) and count($temp_res))
103                                {
104                                        foreach ($temp_res as $id => $value)
105                                        {
106                                                $result[$id] = $value;
107                                        }
108                                }
109                        }
110
111                        //$this->bo_contactcenter->set_catalog($this->catalog);
112                        return $result;
113                }
114               
115                /*!
116               
117                 @function get_single_entry
118                 @abstract Returns all information requested about one contact
119                 @author Raphael Derosso Pereira
120                     
121                 @param integer $id_contact The contact ID
122                 @param array $fields The array returned by get_fields whith true
123                        on the fields to be taken.
124                       
125                */
126                function get_single_entry ( $id_contact, $fields )
127                {       
128                        if (!is_array($fields))
129                        {
130                                if (is_object($GLOBALS['phpgw']->log))
131                                {
132                                        $GLOBALS['phpgw']->log->message(array(
133                                                'text' => 'F-BadcontactcenterParam, wrong get_single_entry parameters type.',
134                                                'line' => __LINE__,
135                                                'file' => __FILE__));
136                                       
137                                        $GLOBALS['phpgw']->log->commit();
138                                }
139                                else
140                                {
141                                        exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>');
142                                }
143                        }
144                       
145                        $contact_array = $this->get_multiple_entries(array($id_contact), $fields);
146                       
147                        if (!count($contact_array))
148                        {
149                                return false;
150                        }
151
152                        if($contact_array[0])
153                                $contact_data = $contact_array[0];
154                        else
155                                $contact_data = $contact_array[$id_contact];
156                       
157                        if (!is_array($contact_data))
158                        {
159                                return false;
160                        }
161                       
162                        return $contact_data;
163                }
164       
165                /*!
166                 
167                 @function get_multiple_entries
168                 @abstract Returns multiple Contacts data into one array
169                 @author Raphael Derosso Pereira
170
171                 @param array $id_contacts The Contacts IDs
172                 @param array $fields The Contacts fields to be retrieved
173                 @param array $other_data Other informations. The format is:
174                        $other_data = array(
175                                'offset'    => <offset>,
176                                'limit'     => <max_num_returns>,
177                                'sort'      => <sort>,
178                                'order_by'  => <order by>
179                        );
180               
181                */
182                function get_multiple_entries ( $id_contacts, $fields, $other_data = false )
183                {
184                        if (!is_array($id_contacts) or !is_array($fields) or ($other_data != false and !is_array($other_data)))
185                        {
186                                if (is_object($GLOBALS['phpgw']->log))
187                                {
188                                        $GLOBALS['phpgw']->log->message(array(
189                                                'text' => 'F-BadcontactcenterParam, wrong get_multiple_entry parameter type.',
190                                                'line' => __LINE__,
191                                                'file' => __FILE__));
192                                       
193                                        $GLOBALS['phpgw']->log->commit();
194                                }
195                                else {
196                                        exit('Argument Error on: <br>File:'.__FILE__.'<br>Line:'.__LINE__.'<br>');
197                                }
198                        }
199                       
200                        $contacts = array();
201       
202                        if ($other_data)
203                        {
204                                //TODO
205                        }
206       
207                        /* First check if this is a LDAP Catalog Group. In this case, just leave the
208                         * subtree search for the LDAP server
209                         */
210                        if ($ldap_info = $this->catalog['ldap'])
211                        {
212                                $meta_catalog = CreateObject('contactcenter.bo_global_ldap_catalog', $ldap_info['id_source'], $ldap_info['context'], $this->external);
213                                return $meta_catalog->get_multiple_entries($id_contacts, $fields, $other_data);
214                        }
215                       
216                        /* Search for the catalog of the first entry and try to get all ids from that
217                         * catalog. Repeat to the ones not found until there's none missing or no more
218                         * catalogs.
219                         */
220
221                        $contacts = array();
222                        reset($this->catalog);
223                        while (list($level,$branch) = each($this->catalog['sub_branch']))
224                        {
225                                $this->bo_contactcenter->set_catalog($branch);
226                                $contacts += $this->bo_contactcenter->catalog->get_multiple_entries($id_contacts, $fields, $other_data);
227                               
228                                reset($contacts);
229                                while (list($id) = each($contacts))
230                                {
231                                        if ($id_contacts[$id])
232                                        {
233                                                unset($id_contacts[$id]);
234                                        }
235                                }
236
237                                if (!count($id_contacts))
238                                {
239                                        break;
240                                }
241                        }
242
243                        $this->bo_contactcenter->set_catalog($this->catalog);
244                       
245                        return $contacts;
246                }
247       
248                function get_all_entries_ids ()
249                {
250                        // TODO!
251                        return null;
252                }
253               
254                /*********************************************************************\
255                 *                Methods to get general fields                      *
256                \*********************************************************************/
257               
258                /*********************************************************************\
259                 *                   Methods to Include Data                         *
260                \*********************************************************************/
261
262                /*********************************************************************\
263                 *                   Methods to Alter Data                           *
264                \*********************************************************************/
265
266                /*********************************************************************\
267                 *                   Methods to Remove Data                          *
268                \*********************************************************************/
269
270        }
271?>
Note: See TracBrowser for help on using the repository browser.