source: subversion/branches/devel-addressbook/program/include/rcube_addressbook.php @ 4268

Last change on this file since 4268 was 4268, checked in by thomasb, 2 years ago

Fix group creation; add texts for new address fields

  • Property svn:keywords set to Id
File size: 9.0 KB
Line 
1<?php
2
3/*
4 +-----------------------------------------------------------------------+
5 | program/include/rcube_addressbook.php                                 |
6 |                                                                       |
7 | This file is part of the Roundcube Webmail client                     |
8 | Copyright (C) 2006-2010, Roundcube Dev. - Switzerland                 |
9 | Licensed under the GNU GPL                                            |
10 |                                                                       |
11 | PURPOSE:                                                              |
12 |   Interface to the local address book database                        |
13 |                                                                       |
14 +-----------------------------------------------------------------------+
15 | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16 +-----------------------------------------------------------------------+
17
18 $Id$
19
20*/
21
22
23/**
24 * Abstract skeleton of an address book/repository
25 *
26 * @package Addressbook
27 */
28abstract class rcube_addressbook
29{
30    /** public properties (mandatory) */
31    public $primary_key;
32    public $groups = false;
33    public $readonly = true;
34    public $ready = false;
35    public $list_page = 1;
36    public $page_size = 10;
37    public $coltypes = array('name' => array('limit'=>1), 'firstname' => array('limit'=>1), 'surname' => array('limit'=>1), 'email' => array('limit'=>1));
38
39    /**
40     * Save a search string for future listings
41     *
42     * @param mixed Search params to use in listing method, obtained by get_search_set()
43     */
44    abstract function set_search_set($filter);
45
46    /**
47     * Getter for saved search properties
48     *
49     * @return mixed Search properties used by this class
50     */
51    abstract function get_search_set();
52
53    /**
54     * Reset saved results and search parameters
55     */
56    abstract function reset();
57
58    /**
59     * List the current set of contact records
60     *
61     * @param  array  List of cols to show
62     * @param  int    Only return this number of records, use negative values for tail
63     * @return array  Indexed list of contact records, each a hash array
64     */
65    abstract function list_records($cols=null, $subset=0);
66
67    /**
68     * Search records
69     *
70     * @param array   List of fields to search in
71     * @param string  Search value
72     * @param boolean True if results are requested, False if count only
73     * @return Indexed list of contact records and 'count' value
74     */
75    abstract function search($fields, $value, $strict=false, $select=true);
76
77    /**
78     * Count number of available contacts in database
79     *
80     * @return rcube_result_set Result set with values for 'count' and 'first'
81     */
82    abstract function count();
83
84    /**
85     * Return the last result set
86     *
87     * @return rcube_result_set Current result set or NULL if nothing selected yet
88     */
89    abstract function get_result();
90
91    /**
92     * Get a specific contact record
93     *
94     * @param mixed record identifier(s)
95     * @param boolean True to return record as associative array, otherwise a result set is returned
96     *
97     * @return mixed Result object with all record fields or False if not found
98     */
99    abstract function get_record($id, $assoc=false);
100
101    /**
102     * Close connection to source
103     * Called on script shutdown
104     */
105    function close() { }
106
107    /**
108     * Set internal list page
109     *
110     * @param  number  Page number to list
111     * @access public
112     */
113    function set_page($page)
114    {
115        $this->list_page = (int)$page;
116    }
117
118    /**
119     * Set internal page size
120     *
121     * @param  number  Number of messages to display on one page
122     * @access public
123     */
124    function set_pagesize($size)
125    {
126        $this->page_size = (int)$size;
127    }
128
129    /**
130     * Create a new contact record
131     *
132     * @param array Assoziative array with save data
133     *  Keys:   Field name with optional section in the form FIELD:SECTION
134     *  Values: Field value. Can be either a string or an array of strings for multiple values
135     * @param boolean True to check for duplicates first
136     * @return mixed The created record ID on success, False on error
137     */
138    function insert($save_data, $check=false)
139    {
140        /* empty for read-only address books */
141    }
142
143    /**
144     * Create new contact records for every item in the record set
145     *
146     * @param object rcube_result_set Recordset to insert
147     * @param boolean True to check for duplicates first
148     * @return array List of created record IDs
149     */
150    function insertMultiple($recset, $check=false)
151    {
152        $ids = array();
153        if (is_object($recset) && is_a($recset, rcube_result_set)) {
154            while ($row = $recset->next()) {
155                if ($insert = $this->insert($row, $check))
156                    $ids[] = $insert;
157            }
158        }
159        return $ids;
160    }
161
162    /**
163     * Update a specific contact record
164     *
165     * @param mixed Record identifier
166     * @param array Assoziative array with save data
167     *  Keys:   Field name with optional section in the form FIELD:SECTION
168     *  Values: Field value. Can be either a string or an array of strings for multiple values
169     * @return boolean True on success, False on error
170     */
171    function update($id, $save_cols)
172    {
173        /* empty for read-only address books */
174    }
175
176    /**
177     * Mark one or more contact records as deleted
178     *
179     * @param array  Record identifiers
180     */
181    function delete($ids)
182    {
183        /* empty for read-only address books */
184    }
185
186    /**
187     * Remove all records from the database
188     */
189    function delete_all()
190    {
191        /* empty for read-only address books */
192    }
193
194    /**
195     * Setter for the current group
196     * (empty, has to be re-implemented by extending class)
197     */
198    function set_group($gid) { }
199
200    /**
201     * List all active contact groups of this source
202     *
203     * @return array  Indexed list of contact groups, each a hash array
204     */
205    function list_groups()
206    {
207        /* empty for address books don't supporting groups */
208        return array();
209    }
210
211    /**
212     * Create a contact group with the given name
213     *
214     * @param string The group name
215     * @return mixed False on error, array with record props in success
216     */
217    function create_group($name)
218    {
219        /* empty for address books don't supporting groups */
220        return false;
221    }
222
223    /**
224     * Delete the given group and all linked group members
225     *
226     * @param string Group identifier
227     * @return boolean True on success, false if no data was changed
228     */
229    function delete_group($gid)
230    {
231        /* empty for address books don't supporting groups */
232        return false;
233    }
234
235    /**
236     * Rename a specific contact group
237     *
238     * @param string Group identifier
239     * @param string New name to set for this group
240     * @return boolean New name on success, false if no data was changed
241     */
242    function rename_group($gid, $newname)
243    {
244        /* empty for address books don't supporting groups */
245        return false;
246    }
247
248    /**
249     * Add the given contact records the a certain group
250     *
251     * @param string  Group identifier
252     * @param array   List of contact identifiers to be added
253     * @return int    Number of contacts added
254     */
255    function add_to_group($group_id, $ids)
256    {
257        /* empty for address books don't supporting groups */
258        return 0;
259    }
260
261    /**
262     * Remove the given contact records from a certain group
263     *
264     * @param string  Group identifier
265     * @param array   List of contact identifiers to be removed
266     * @return int    Number of deleted group members
267     */
268    function remove_from_group($group_id, $ids)
269    {
270        /* empty for address books don't supporting groups */
271        return 0;
272    }
273
274    /**
275     * Get group assignments of a specific contact record
276     *
277     * @param mixed Record identifier
278     *
279     * @return array List of assigned groups as ID=>Name pairs
280     * @since 0.5-beta
281     */
282    function get_record_groups($id)
283    {
284        /* empty for address books don't supporting groups */
285        return array();
286    }
287
288
289    /**
290     * Utility function to return all values of a certain data column
291     * either as flat list or grouped by subtype
292     *
293     * @param string Col name
294     * @param array  Record data array as used for saving
295     * @param boolean True to return one array with all values, False for hash array with values grouped by type
296     * @return array List of column values
297     */
298    function get_col_values($col, $data, $flat = false)
299    {
300        $out = array();
301        foreach ($data as $c => $values) {
302            if (strpos($c, $col) === 0) {
303                if ($flat) {
304                    $out = array_merge($out, (array)$values);
305                }
306                else {
307                    list($f, $type) = explode(':', $c);
308                    $out[$type] = array_merge((array)$out[$type], (array)$values);
309                }
310            }
311        }
312     
313        return $out;
314    }
315   
316}
317
Note: See TracBrowser for help on using the repository browser.