alecpl
2010-09-25 e019f2d0f2dc2fbfa345ab5d7ae85e67bfdd76b8
commit | author | age
cc97ea 1 <?php
T 2
3 /*
4  +-----------------------------------------------------------------------+
5  | program/include/rcube_addressbook.php                                 |
6  |                                                                       |
e019f2 7  | This file is part of the Roundcube Webmail client                     |
A 8  | Copyright (C) 2006-2009, Roundcube Dev. - Switzerland                 |
cc97ea 9  | Licensed under the GNU GPL                                            |
T 10  |                                                                       |
11  | PURPOSE:                                                              |
12  |   Interface to the local address book database                        |
13  |                                                                       |
14  +-----------------------------------------------------------------------+
15  | Author: Thomas Bruederli <roundcube@gmail.com>                        |
16  +-----------------------------------------------------------------------+
17
1d786c 18  $Id$
cc97ea 19
T 20 */
21
22
23 /**
24  * Abstract skeleton of an address book/repository
25  *
26  * @package Addressbook
27  */
28 abstract class rcube_addressbook
29 {
30     /** public properties */
31     var $primary_key;
a61bbb 32     var $groups = false;
cc97ea 33     var $readonly = true;
T 34     var $ready = false;
35     var $list_page = 1;
36     var $page_size = 10;
37
38     /**
39      * Save a search string for future listings
40      *
41      * @param mixed Search params to use in listing method, obtained by get_search_set()
42      */
43     abstract function set_search_set($filter);
44
45     /**
46      * Getter for saved search properties
47      *
48      * @return mixed Search properties used by this class
49      */
50     abstract function get_search_set();
51
52     /**
53      * Reset saved results and search parameters
54      */
55     abstract function reset();
56
57     /**
58      * List the current set of contact records
59      *
60      * @param  array  List of cols to show
61      * @param  int    Only return this number of records, use negative values for tail
62      * @return array  Indexed list of contact records, each a hash array
63      */
64     abstract function list_records($cols=null, $subset=0);
a61bbb 65
T 66     /**
67      * List all active contact groups of this source
68      *
69      * @return array  Indexed list of contact groups, each a hash array
70      */
71     function list_groups() { }
cc97ea 72
T 73     /**
74      * Search records
75      *
76      * @param array   List of fields to search in
77      * @param string  Search value
78      * @param boolean True if results are requested, False if count only
79      * @return Indexed list of contact records and 'count' value
80      */
81     abstract function search($fields, $value, $strict=false, $select=true);
82
83     /**
84      * Count number of available contacts in database
85      *
86      * @return object rcube_result_set Result set with values for 'count' and 'first'
87      */
88     abstract function count();
89
90     /**
91      * Return the last result set
92      *
93      * @return object rcube_result_set Current result set or NULL if nothing selected yet
94      */
95     abstract function get_result();
96
97     /**
98      * Get a specific contact record
99      *
100      * @param mixed record identifier(s)
101      * @param boolean True to return record as associative array, otherwise a result set is returned
102      * @return mixed Result object with all record fields or False if not found
103      */
104     abstract function get_record($id, $assoc=false);
105
106     /**
107      * Close connection to source
108      * Called on script shutdown
109      */
110     function close() { }
111
112     /**
113      * Set internal list page
114      *
115      * @param  number  Page number to list
116      * @access public
117      */
118     function set_page($page)
119     {
2eb794 120         $this->list_page = (int)$page;
cc97ea 121     }
T 122
123     /**
124      * Set internal page size
125      *
126      * @param  number  Number of messages to display on one page
127      * @access public
128      */
129     function set_pagesize($size)
130     {
2eb794 131         $this->page_size = (int)$size;
cc97ea 132     }
T 133
134     /**
a61bbb 135      * Setter for the current group
T 136      * (empty, has to be re-implemented by extending class)
137      */
138     function set_group($gid) { }
139
140     /**
cc97ea 141      * Create a new contact record
T 142      *
143      * @param array Assoziative array with save data
144      * @param boolean True to check for duplicates first
145      * @return The created record ID on success, False on error
146      */
147     function insert($save_data, $check=false)
148     {
2eb794 149         /* empty for read-only address books */
cc97ea 150     }
T 151
152     /**
153      * Update a specific contact record
154      *
155      * @param mixed Record identifier
156      * @param array Assoziative array with save data
157      * @return True on success, False on error
158      */
159     function update($id, $save_cols)
160     {
2eb794 161         /* empty for read-only address books */
cc97ea 162     }
T 163
164     /**
165      * Mark one or more contact records as deleted
166      *
167      * @param array  Record identifiers
168      */
169     function delete($ids)
170     {
2eb794 171         /* empty for read-only address books */
cc97ea 172     }
T 173
174     /**
175      * Remove all records from the database
176      */
177     function delete_all()
178     {
2eb794 179         /* empty for read-only address books */
cc97ea 180     }
T 181
04adaa 182     /**
T 183      * Create a contact group with the given name
184      *
185      * @param string The group name
186      * @return False on error, array with record props in success
187      */
188     function create_group($name)
189     {
2eb794 190         /* empty for address books don't supporting groups */
A 191         return false;
04adaa 192     }
T 193     
194     /**
195      * Delete the given group and all linked group members
196      *
197      * @param string Group identifier
198      * @return boolean True on success, false if no data was changed
199      */
200     function delete_group($gid)
201     {
2eb794 202         /* empty for address books don't supporting groups */
A 203         return false;
04adaa 204     }
T 205     
206     /**
207      * Rename a specific contact group
208      *
209      * @param string Group identifier
210      * @param string New name to set for this group
211      * @return boolean New name on success, false if no data was changed
212      */
213     function rename_group($gid, $newname)
214     {
2eb794 215         /* empty for address books don't supporting groups */
A 216         return false;
04adaa 217     }
T 218     
219     /**
220      * Add the given contact records the a certain group
221      *
222      * @param string  Group identifier
223      * @param array   List of contact identifiers to be added
224      * @return int    Number of contacts added 
225      */
226     function add_to_group($group_id, $ids)
227     {
2eb794 228         /* empty for address books don't supporting groups */
A 229         return 0;
04adaa 230     }
T 231     
232     /**
233      * Remove the given contact records from a certain group
234      *
235      * @param string  Group identifier
236      * @param array   List of contact identifiers to be removed
237      * @return int    Number of deleted group members
238      */
239     function remove_from_group($group_id, $ids)
240     {
2eb794 241         /* empty for address books don't supporting groups */
A 242         return 0;
04adaa 243     }
cc97ea 244 }