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

Last change on this file since 4243 was 4243, checked in by thomasb, 3 years ago

Allow address sources to limit/extend the contact coltypes

  • Property svn:keywords set to Id
File size: 7.5 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     * Update a specific contact record
145     *
146     * @param mixed Record identifier
147     * @param array Assoziative array with save data
148     *  Keys:   Field name with optional section in the form FIELD:SECTION
149     *  Values: Field value. Can be either a string or an array of strings for multiple values
150     * @return boolean True on success, False on error
151     */
152    function update($id, $save_cols)
153    {
154        /* empty for read-only address books */
155    }
156
157    /**
158     * Mark one or more contact records as deleted
159     *
160     * @param array  Record identifiers
161     */
162    function delete($ids)
163    {
164        /* empty for read-only address books */
165    }
166
167    /**
168     * Remove all records from the database
169     */
170    function delete_all()
171    {
172        /* empty for read-only address books */
173    }
174
175    /**
176     * Setter for the current group
177     * (empty, has to be re-implemented by extending class)
178     */
179    function set_group($gid) { }
180
181    /**
182     * List all active contact groups of this source
183     *
184     * @return array  Indexed list of contact groups, each a hash array
185     */
186    function list_groups()
187    {
188        /* empty for address books don't supporting groups */
189        return array();
190    }
191
192    /**
193     * Create a contact group with the given name
194     *
195     * @param string The group name
196     * @return mixed False on error, array with record props in success
197     */
198    function create_group($name)
199    {
200        /* empty for address books don't supporting groups */
201        return false;
202    }
203
204    /**
205     * Delete the given group and all linked group members
206     *
207     * @param string Group identifier
208     * @return boolean True on success, false if no data was changed
209     */
210    function delete_group($gid)
211    {
212        /* empty for address books don't supporting groups */
213        return false;
214    }
215
216    /**
217     * Rename a specific contact group
218     *
219     * @param string Group identifier
220     * @param string New name to set for this group
221     * @return boolean New name on success, false if no data was changed
222     */
223    function rename_group($gid, $newname)
224    {
225        /* empty for address books don't supporting groups */
226        return false;
227    }
228
229    /**
230     * Add the given contact records the a certain group
231     *
232     * @param string  Group identifier
233     * @param array   List of contact identifiers to be added
234     * @return int    Number of contacts added
235     */
236    function add_to_group($group_id, $ids)
237    {
238        /* empty for address books don't supporting groups */
239        return 0;
240    }
241
242    /**
243     * Remove the given contact records from a certain group
244     *
245     * @param string  Group identifier
246     * @param array   List of contact identifiers to be removed
247     * @return int    Number of deleted group members
248     */
249    function remove_from_group($group_id, $ids)
250    {
251        /* empty for address books don't supporting groups */
252        return 0;
253    }
254
255    /**
256     * Get group assignments of a specific contact record
257     *
258     * @param mixed Record identifier
259     *
260     * @return array List of assigned groups as ID=>Name pairs
261     * @since 0.5-beta
262     */
263    function get_record_groups($id)
264    {
265        /* empty for address books don't supporting groups */
266        return array();
267    }
268}
269
Note: See TracBrowser for help on using the repository browser.