[turba] More API methods
Mikael Geijer
mikael at nufort.net
Fri Oct 3 02:23:32 PDT 2003
Coming here. New so far is update_vcard and delete.
/Mikael
--
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=
=- Mikael Geijer, nufort HB (nufort.net), Oebb AB (oebb.net)
=- mobile: +46 70 7455239 office +46 70 7455239
=- email: mikael at nufort.net
=- snail: Kyrklunden 8, 122 32 Enskede, Sweden
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-==-=-=-=-=-=-=-=-=-=-=-=-=-=-=
-------------- next part --------------
15,18d14
< $_services['update_vcard'] = array(
< 'args' => array('source', 'vcard_data','key'),
< 'type' => 'boolean');
<
37,40d32
< $_services['delete'] = array(
< 'args' => array('key', 'addressbook'),
< 'type' => 'boolean');
<
76a69
>
175,233d167
< function _turba_update_vcard($source, $vcard_data, $key)
< {
< require_once dirname(__FILE__) . '/base.php';
< require_once HORDE_BASE . '/lib/Data.php';
< require_once TURBA_BASE . '/lib/Source.php';
< require_once TURBA_BASE . '/lib/Object.php';
< global $cfgSources;
<
< $entry = sprintf('Source %s Key %s',
< $source, $key);
< Horde::logMessage($entry, __FILE__, __LINE__, PEAR_LOG_DEBUG);
<
< if (empty($source) || !isset($cfgSources[$source])) {
< return PEAR::raiseError(_("Invalid address book."), 'horde.error', null, null, $source);
< }
<
< if ($cfgSources[$source]['readonly']
< && (!isset($cfgSources[$source]['admin'])
< || !in_array(Auth::getAuth(), $cfgSources[$source]['admin']))) {
< return PEAR::raiseError(_("Address book is read-only."), 'horde.error', null, null, $source);
< }
<
< $vcard = &Horde_Data::singleton('vcard');
< if (!$data = $vcard->importData($vcard_data)) {
< return PEAR::raiseError(_("There was an error importing the vCard data."));
< }
<
< $driver = &Turba_Source::singleton($source, $cfgSources[$source]);
<
< // Check if entry is in addressbook, if not raise a warning (this is somewhat of a performance load)
< $result = $driver->search(array('__key' => $key));
< //$result = $driver->getObject($key);
< if (is_a($result, 'PEAR_Error') || $result->count() == 0) {
< return PEAR::raiseError(_("Address not in addressbook."), 'horde.warning', null, null, $addressbook);
< }
<
< $objects = array();
< foreach ($data as $object) {
< if ($object['type'] == 'VCARD') {
< $hash = $vcard->toHash($object);
<
< $hash['__owner'] = Auth::getAuth();
<
< // We need to set the key for the object to replace
< $hash['__key'] = $key;
<
< $repobject = new Turba_Object($driver, $hash);
<
< $result = $driver->setObject($repobject);
< if (is_a($result, 'PEAR_Error')) {
< // There was an error..
< return PEAR::raiseError(_("There was an error updating the vCard data."));
< }
< }
< }
<
< return true;
< }
<
385,419d318
< function _turba_delete($key = '', $addressbook = '')
< {
< require_once dirname(__FILE__) . '/base.php';
< require_once TURBA_BASE . '/lib/Source.php';
< global $cfgSources;
<
< if (empty($addressbook) || !isset($cfgSources[$addressbook])) {
< return PEAR::raiseError(_("Invalid address book."), 'horde.error', null, null, $addressbook);
< }
<
< if (empty($key)) {
< return PEAR::raiseError(_("Invalid key."), 'horde.error', null, null, $addressbook);
< }
<
< if ($cfgSources[$addressbook]['readonly']
< && (!isset($cfgSources[$addressbook]['admin'])
< || !in_array(Auth::getAuth(), $cfgSources[$addressbook]['admin']))) {
< return PEAR::raiseError(_("Address book is read-only."), 'horde.error', null, null, $addressbook);
< }
<
< $driver = &Turba_Source::singleton($addressbook, $cfgSources[$addressbook]);
<
< // Check if entry is in addressbook, if not raise a warning (this could be discussed)
< $res = $driver->search(array('__key' => $key));
< if (is_a($res, 'PEAR_Error') || $res->count() == 0) {
< return PEAR::raiseError(_("Address not in addressbook."), 'horde.warning', null, null, $addressbook);
< }
<
< if (! $driver->removeObject($key)) {
< return PEAR::raiseError(_("There was an error deleting this entry."), 'horde.message', null, null, $addressbook);
< }
<
< return true;
< }
<
More information about the turba
mailing list