]> git.donarmstrong.com Git - roundcube.git/blob - plugins/example_addressbook/example_addressbook_backend.php
Imported Upstream version 0.5
[roundcube.git] / plugins / example_addressbook / example_addressbook_backend.php
1 <?php
2
3 /**
4  * Example backend class for a custom address book
5  *
6  * This one just holds a static list of address records
7  *
8  * @author Thomas Bruederli
9  */
10 class example_addressbook_backend extends rcube_addressbook
11 {
12   public $primary_key = 'ID';
13   public $readonly = true;
14   public $groups = true;
15   
16   private $filter;
17   private $result;
18   
19   public function __construct()
20   {
21     $this->ready = true;
22   }
23   
24   public function set_search_set($filter)
25   {
26     $this->filter = $filter;
27   }
28   
29   public function get_search_set()
30   {
31     return $this->filter;
32   }
33
34   public function reset()
35   {
36     $this->result = null;
37     $this->filter = null;
38   }
39
40   function list_groups($search = null)
41   {
42     return array(
43       array('ID' => 'testgroup1', 'name' => "Testgroup"),
44       array('ID' => 'testgroup2', 'name' => "Sample Group"),
45     );
46   }
47   
48   public function list_records($cols=null, $subset=0)
49   {
50     $this->result = $this->count();
51     $this->result->add(array('ID' => '111', 'name' => "Example Contact", 'firstname' => "Example", 'surname' => "Contact", 'email' => "example@roundcube.net"));
52     
53     return $this->result;
54   }
55
56   public function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array())
57   {
58     // no search implemented, just list all records
59     return $this->list_records();
60   }
61
62   public function count()
63   {
64     return new rcube_result_set(1, ($this->list_page-1) * $this->page_size);
65   }
66
67   public function get_result()
68   {
69     return $this->result;
70   }
71
72   public function get_record($id, $assoc=false)
73   {
74     $this->list_records();
75     $first = $this->result->first();
76     $sql_arr = $first['ID'] == $id ? $first : null;
77     
78     return $assoc && $sql_arr ? $sql_arr : $this->result;
79   }
80
81
82   function create_group($name)
83   {
84     $result = false;
85
86     return $result;
87   }
88
89   function delete_group($gid)
90   {
91     return false;
92   }
93
94   function rename_group($gid, $newname)
95   {
96     return $newname;
97   }
98
99   function add_to_group($group_id, $ids)
100   {
101     return false;
102   }
103
104   function remove_from_group($group_id, $ids)
105   {
106      return false;
107   }
108   
109 }