]> git.donarmstrong.com Git - roundcube.git/blob - plugins/example_addressbook/example_addressbook_backend.php
Imported Upstream version 0.6+dfsg
[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   private $name;
19
20   public function __construct($name)
21   {
22     $this->ready = true;
23     $this->name = $name;
24   }
25
26   public function get_name()
27   {
28     return $this->name;
29   }
30
31   public function set_search_set($filter)
32   {
33     $this->filter = $filter;
34   }
35
36   public function get_search_set()
37   {
38     return $this->filter;
39   }
40
41   public function reset()
42   {
43     $this->result = null;
44     $this->filter = null;
45   }
46
47   function list_groups($search = null)
48   {
49     return array(
50       array('ID' => 'testgroup1', 'name' => "Testgroup"),
51       array('ID' => 'testgroup2', 'name' => "Sample Group"),
52     );
53   }
54
55   public function list_records($cols=null, $subset=0)
56   {
57     $this->result = $this->count();
58     $this->result->add(array('ID' => '111', 'name' => "Example Contact", 'firstname' => "Example", 'surname' => "Contact", 'email' => "example@roundcube.net"));
59
60     return $this->result;
61   }
62
63   public function search($fields, $value, $strict=false, $select=true, $nocount=false, $required=array())
64   {
65     // no search implemented, just list all records
66     return $this->list_records();
67   }
68
69   public function count()
70   {
71     return new rcube_result_set(1, ($this->list_page-1) * $this->page_size);
72   }
73
74   public function get_result()
75   {
76     return $this->result;
77   }
78
79   public function get_record($id, $assoc=false)
80   {
81     $this->list_records();
82     $first = $this->result->first();
83     $sql_arr = $first['ID'] == $id ? $first : null;
84
85     return $assoc && $sql_arr ? $sql_arr : $this->result;
86   }
87
88
89   function create_group($name)
90   {
91     $result = false;
92
93     return $result;
94   }
95
96   function delete_group($gid)
97   {
98     return false;
99   }
100
101   function rename_group($gid, $newname)
102   {
103     return $newname;
104   }
105
106   function add_to_group($group_id, $ids)
107   {
108     return false;
109   }
110
111   function remove_from_group($group_id, $ids)
112   {
113      return false;
114   }
115
116 }