]> git.donarmstrong.com Git - roundcube.git/blob - plugins/example_addressbook/example_addressbook_backend.php
Imported Upstream version 0.3
[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   
15   private $filter;
16   private $result;
17   
18   public function __construct()
19   {
20     $this->ready = true;
21   }
22   
23   public function set_search_set($filter)
24   {
25     $this->filter = $filter;
26   }
27   
28   public function get_search_set()
29   {
30     return $this->filter;
31   }
32
33   public function reset()
34   {
35     $this->result = null;
36     $this->filter = null;
37   }
38
39   public function list_records($cols=null, $subset=0)
40   {
41     $this->result = $this->count();
42     $this->result->add(array('ID' => '111', 'name' => "Example Contact", 'firstname' => "Example", 'surname' => "Contact", 'email' => "example@roundcube.net"));
43     
44     return $this->result;
45   }
46
47   public function search($fields, $value, $strict=false, $select=true)
48   {
49     // no search implemented, just list all records
50     return $this->list_records();
51   }
52
53   public function count()
54   {
55     return new rcube_result_set(1, ($this->list_page-1) * $this->page_size);
56   }
57
58   public function get_result()
59   {
60     return $this->result;
61   }
62
63   public function get_record($id, $assoc=false)
64   {
65     $this->list_records();
66     $first = $this->result->first();
67     $sql_arr = $first['ID'] == $id ? $first : null;
68     
69     return $assoc && $sql_arr ? $sql_arr : $this->result;
70   }
71   
72 }