1 | <?php |
||
2 | /** |
||
3 | * eGroupWare - Addressbook - importexport |
||
4 | * |
||
5 | * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License |
||
6 | * @package addressbook |
||
7 | * @subpackage importexport |
||
8 | * @link http://www.egroupware.org |
||
9 | * @author Cornelius Weiss <[email protected]> |
||
10 | * @copyright Cornelius Weiss <[email protected]> |
||
11 | * @version $Id$ |
||
12 | */ |
||
13 | |||
14 | use EGroupware\Api; |
||
15 | use EGroupware\Api\Framework; |
||
16 | |||
17 | /** |
||
18 | * class addressbook_egw_record |
||
19 | * compability layer for iface_egw_record needed for importexport |
||
20 | * |
||
21 | * Note that last_event and next_event are not automatically loaded by |
||
22 | * addressbook_bo->read(), so if you need them use: |
||
23 | * addressbook_bo->read_calendar(); |
||
24 | */ |
||
25 | class addressbook_egw_record implements importexport_iface_egw_record |
||
26 | { |
||
27 | |||
28 | private $identifier = ''; |
||
29 | private $contact = array(); |
||
30 | private $bocontacts; |
||
31 | |||
32 | // Used in conversions |
||
33 | static $types = array( |
||
34 | 'select-account' => array('owner','creator','modifier'), |
||
35 | 'date-time' => array('modified','created','last_event','next_event'), |
||
36 | 'date' => array('bday'), |
||
37 | 'select-cat' => array('cat_id'), |
||
38 | 'select' => array('tid') |
||
39 | ); |
||
40 | |||
41 | |||
42 | /** |
||
43 | * constructor |
||
44 | * reads record from backend if identifier is given. |
||
45 | * |
||
46 | * @param string $_identifier |
||
47 | */ |
||
48 | public function __construct( $_identifier='' ){ |
||
49 | $this->identifier = $_identifier; |
||
50 | $this->bocontacts = new Api\Contacts(); |
||
51 | if($_identifier) { |
||
52 | $this->contact = $this->bocontacts->read($this->identifier); |
||
53 | } |
||
54 | } |
||
55 | |||
56 | /** |
||
57 | * magic method to set attributes of record |
||
58 | * |
||
59 | * @param string $_attribute_name |
||
60 | */ |
||
61 | public function __get($_attribute_name) { |
||
62 | return $this->contact[$_attribute_name]; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * magig method to set attributes of record |
||
67 | * |
||
68 | * @param string $_attribute_name |
||
69 | * @param data $data |
||
70 | */ |
||
71 | public function __set($_attribute_name, $data) { |
||
72 | $this->contact[$_attribute_name] = $data; |
||
73 | } |
||
74 | |||
75 | /** |
||
76 | * converts this object to array. |
||
77 | * @abstract We need such a function cause PHP5 |
||
78 | * dosn't allow objects do define it's own casts :-( |
||
79 | * once PHP can deal with object casts we will change to them! |
||
80 | * |
||
81 | * @return array complete record as associative array |
||
82 | */ |
||
83 | public function get_record_array() { |
||
84 | return $this->contact; |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * gets title of record |
||
89 | * |
||
90 | *@return string tiltle |
||
91 | */ |
||
92 | public function get_title() { |
||
93 | return $this->bocontacts->link_title(empty($this->contact) ? $this->identifier : $this->contact); |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * sets complete record from associative array |
||
98 | * |
||
99 | * @todo add some checks |
||
100 | * @return void |
||
101 | */ |
||
102 | public function set_record(array $_record){ |
||
103 | $this->contact = $_record; |
||
104 | } |
||
105 | |||
106 | /** |
||
107 | * gets identifier of this record |
||
108 | * |
||
109 | * @return string identifier of current record |
||
110 | */ |
||
111 | public function get_identifier() { |
||
112 | return $this->identifier ? $this->identifier : $this->id; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Gets the URL icon representitive of the record |
||
117 | * This could be as general as the application icon, or as specific as a contact photo |
||
118 | * |
||
119 | * @return string Full URL of an icon, or appname/icon_name |
||
120 | */ |
||
121 | public function get_icon() { |
||
122 | $ui = new addressbook_ui(); |
||
123 | |||
124 | // Type as default |
||
125 | $label = $icon = null; |
||
126 | $ui->type_icon($this->owner, $this->private, $this->tid, $icon, $label); |
||
127 | |||
128 | // Specific photo |
||
129 | return $this->jpegphoto ? Framework::link('/index.php',$ui->photo_src($this->identifier,$this->jpegphoto)):$icon; |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||
130 | } |
||
131 | /** |
||
132 | * saves record into backend |
||
133 | * |
||
134 | * @return string identifier |
||
135 | */ |
||
136 | public function save ( $_dst_identifier ) { |
||
137 | // Not yet implemeted |
||
138 | $this->identifier = $_dst_identifier; |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * copys current record to record identified by $_dst_identifier |
||
143 | * |
||
144 | * @param string $_dst_identifier |
||
145 | * @return string dst_identifier |
||
146 | */ |
||
147 | public function copy ( $_dst_identifier ) { |
||
148 | unset($_dst_identifier); // not used, but required by function signature |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * moves current record to record identified by $_dst_identifier |
||
153 | * $this will become moved record |
||
154 | * |
||
155 | * @param string $_dst_identifier |
||
156 | * @return string dst_identifier |
||
157 | */ |
||
158 | public function move ( $_dst_identifier ) { |
||
159 | unset($_dst_identifier); // not used, but required by function signature |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * delets current record from backend |
||
164 | * |
||
165 | */ |
||
166 | public function delete () { |
||
167 | |||
168 | } |
||
169 | |||
170 | /** |
||
171 | * destructor |
||
172 | * |
||
173 | */ |
||
174 | public function __destruct() { |
||
175 | unset ($this->bocontacts); |
||
176 | } |
||
177 | } |
||
178 |