3
* The Turba_Driver:: class provides a common abstracted interface to the
4
* various directory search drivers. It includes functions for searching,
5
* adding, removing, and modifying directory entries.
7
* Copyright 2009-2013 Horde LLC (http://www.horde.org/)
9
* See the enclosed file LICENSE for license information (ASL). If you did
10
* did not receive this file, see http://www.horde.org/licenses/apache.
12
* @author Chuck Hagenbuch <chuck@horde.org>
13
* @author Jon Parise <jon@csh.rit.edu>
14
* @author Michael J. Rubinsky <mrubinsk@horde.org>
16
* @license http://www.horde.org/licenses/apache ASL
19
class Turba_Driver_Share extends Turba_Driver
22
* Horde_Share object for this source.
29
* Underlying driver object for this source.
38
* @param string $name The source name
39
* @param array $params The parameter array describing the source
41
* @return Turba_Driver
43
public function __construct($name = '', array $params = array())
45
parent::__construct($name, $params);
46
$this->_share = $this->_params['config']['params']['share'];
47
$this->_driver = $GLOBALS['injector']->getInstance('Turba_Factory_Driver')->create($this->_params['config']);
48
$this->_driver->setContactOwner($this->_getContactOwner());
49
$this->_driver->setSourceName($name);
53
* Proxy to decorated base driver.
55
* @param string $method Method name.
56
* @param array $args Method arguments.
58
* @return mixed Method result.
60
public function __call($method, $args)
62
return call_user_func_array(array($this->_driver, $method), $args);
66
* Checks if this backend has a certain capability.
68
* @param string $capability The capability to check for.
70
* @return boolean Supported or not.
72
public function hasCapability($capability)
74
return $this->_driver->hasCapability($capability);
78
* Translates the keys of the first hash from the generalized Turba
79
* attributes to the driver-specific fields. The translation is based on
80
* the contents of $this->map.
82
* @param array $hash Hash using Turba keys.
84
* @return array Translated version of $hash.
86
public function toDriverKeys(array $hash)
88
return $this->_driver->toDriverKeys($hash);
92
* Searches the current address book for duplicate entries.
94
* Duplicates are determined by comparing email and name or last name and
97
* @return array A hash with the following format:
99
* array('name' => array('John Doe' => Turba_List, ...), ...)
101
* @throws Turba_Exception
103
public function searchDuplicates()
105
return $this->_driver->searchDuplicates();
109
* Checks if the current user has the requested permissions on this
112
* @param integer $perm The permission to check for.
114
* @return boolean True if the user has permission, otherwise false.
116
public function hasPermission($perm)
118
return $this->_share->hasPermission($GLOBALS['registry']->getAuth(), $perm);
122
* Return the name of this address book.
124
* @string Address book name
126
public function getName()
128
$share_parts = explode(':', $this->_share->getName());
129
return array_pop($share_parts);
133
* Return the owner to use when searching or creating contacts in
136
* @return string TODO
137
* @throws Turba_Exception
139
protected function _getContactOwner()
141
$params = @unserialize($this->_share->get('params'));
142
if (!empty($params['name'])) {
143
return $params['name'];
146
throw new Turba_Exception(_("Unable to find contact owner."));
150
* Runs any actions after setting a new default tasklist.
152
* @param string $share The default share ID.
154
public function setDefaultShare($share)
156
$this->_driver->setDefaultShare($share);
160
* Creates an object key for a new object.
162
* @param array $attributes The attributes (in driver keys) of the
163
* object being added.
165
* @return string A unique ID for the new object.
167
protected function _makeKey(array $attributes)
169
return $this->_driver->_makeKey($attributes);
173
* Creates an object UID for a new object.
175
* @return string A unique ID for the new object.
177
protected function _makeUid()
179
return $this->_driver->_makeUid();
183
* Searches the address book with the given criteria and returns a
184
* filtered list of results. If the criteria parameter is an empty array,
185
* all records will be returned.
187
* @param array $criteria Array containing the search criteria.
188
* @param array $fields List of fields to return.
189
* @param array $blobFields Array of fields containing binary data.
190
* @param boolean $count_only Only return the count of matching entries,
191
* not the entries themselves.
193
* @return array Hash containing the search results.
194
* @throws Turba_Exception
196
protected function _search(array $criteria, array $fields, array $blobFields = array(), $count_only = false)
198
return $this->_driver->_search($criteria, $fields, $blobFields, $count_only);
202
* Reads the given data from the address book and returns the results.
204
* @param string $key The primary key field to use.
205
* @param mixed $ids The ids of the contacts to load.
206
* @param string $owner Only return contacts owned by this user.
207
* @param array $fields List of fields to return.
208
* @param array $blobFields Array of fields containing binary data.
210
* @return array Hash containing the search results.
211
* @throws Turba_Exception
213
protected function _read($key, $ids, $owner, array $fields,
214
array $blobFields = array())
216
return $this->_driver->_read($key, $ids, $owner, $fields, $blobFields);
220
* Adds the specified contact to the addressbook.
222
* @param array $attributes The attribute values of the contact.
223
* @param array $blob_fields TODO
225
* @throws Turba_Exception
227
protected function _add(array $attributes, array $blob_fields = array())
229
return $this->_driver->_add($attributes, $blob_fields);
233
* Returns ability of the backend to add new contacts.
235
* @return boolean Can backend add?
237
protected function _canAdd()
239
return $this->_driver->_canAdd();
243
* Deletes the specified contact from the addressbook.
245
* @param string $object_key TODO
246
* @param string $object_id TODO
248
* @throws Turba_Exception
250
protected function _delete($object_key, $object_id)
252
return $this->_driver->_delete($object_key, $object_id);
256
* Deletes all contacts from a specific address book.
258
* @param string $sourceName The source to remove all contacts from.
260
* @return array An array of UIDs
261
* @throws Turba_Exception
263
protected function _deleteAll($sourceName = null)
265
if (is_null($sourceName)) {
266
$sourceName = $this->getContactOwner();
268
return $this->_driver->_deleteAll($sourceName);
272
* Saves the specified object in the SQL database.
274
* @param Turba_Object $object The object to save
276
* @return string The object id, possibly updated.
277
* @throws Turba_Exception
279
protected function _save(Turba_Object $object)
281
return $this->_driver->_save($object);
285
* Remove all data for a specific user.
287
* @param string $user The user to remove all data for.
289
public function removeUserData($user)
291
// Make sure we are being called by an admin.
292
if (!$GLOBALS['registry']->isAdmin()) {
293
throw new Horde_Exception_PermissionDenied(_("Permission denied"));
297
->getInstance('Turba_Shares')
298
->removeShare($this->_share);
299
unset($this->_share);