Overview

Packages

  • Horde
    • Data
  • None
  • Turba

Classes

  • Turba
  • Turba_Api
  • Turba_Driver
  • Turba_Driver_Facebook
  • Turba_Driver_Favourites
  • Turba_Driver_Group
  • Turba_Driver_Imsp
  • Turba_Driver_Kolab
  • Turba_Driver_Ldap
  • Turba_Driver_Prefs
  • Turba_Driver_Share
  • Turba_Driver_Sql
  • Turba_Driver_Vbook
  • Turba_Exception
  • Turba_Factory_Driver
  • Turba_Form_AddContact
  • Turba_Form_Contact
  • Turba_Form_ContactBase
  • Turba_Form_CreateAddressBook
  • Turba_Form_DeleteAddressBook
  • Turba_Form_EditAddressBook
  • Turba_Form_EditContact
  • Turba_Form_EditContactGroup
  • Turba_List
  • Turba_LoginTasks_SystemTask_Upgrade
  • Turba_Object
  • Turba_Object_Group
  • Turba_Test
  • Turba_View_Browse
  • Turba_View_Contact
  • Turba_View_DeleteContact
  • Turba_View_Duplicates
  • Turba_View_EditContact
  • Turba_View_List
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Turba directory driver implementation for Horde Preferences - very simple,
  4:  * lightweight container.
  5:  *
  6:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
  7:  *
  8:  * See the enclosed file LICENSE for license information (ASL).  If you did
  9:  * did not receive this file, see http://www.horde.org/licenses/apache.
 10:  *
 11:  * @author   Chuck Hagenbuch <chuck@horde.org>
 12:  * @category Horde
 13:  * @license  http://www.horde.org/licenses/apache ASL
 14:  * @package  Turba
 15:  */
 16: class Turba_Driver_Prefs extends Turba_Driver
 17: {
 18:     /**
 19:      * Returns all entries - searching isn't implemented here for now. The
 20:      * parameters are simply ignored.
 21:      *
 22:      * @param array $criteria    Array containing the search criteria.
 23:      * @param array $fields      List of fields to return.
 24:      * @param array $blobFields  Array of fields containing binary data.
 25:      *
 26:      * @return array  Hash containing the search results.
 27:      */
 28:     protected function _search(array $criteria, array $fields, array $blobFields = array(), $count_only = false)
 29:     {
 30:         return $count_only ? count($this->_getAddressBook()) : array_values($this->_getAddressBook());
 31:     }
 32: 
 33:     /**
 34:      * Reads the given data from the preferences and returns the result's
 35:      * fields.
 36:      */
 37:     protected function _read($key, $ids, $owner, array $fields,
 38:                              array $blobFields = array())
 39:     {
 40:         $book = $this->_getAddressBook();
 41: 
 42:         $results = array();
 43:         if (!is_array($ids)) {
 44:             $ids = array($ids);
 45:         }
 46: 
 47:         foreach ($ids as $id) {
 48:             if (isset($book[$id])) {
 49:                 $results[] = $book[$id];
 50:             }
 51:         }
 52: 
 53:         return $results;
 54:     }
 55: 
 56:     /**
 57:      * Adds the specified contact to the addressbook.
 58:      *
 59:      * @param array $attributes  The attribute values of the contact.
 60:      * @param array $blob_fields TODO
 61:      *
 62:      * @throws Turba_Exception
 63:      */
 64:     protected function _add(array $attributes, array $blob_fields = array())
 65:     {
 66:         $book = $this->_getAddressBook();
 67:         $book[$attributes['id']] = $attributes;
 68:         $this->_setAddressbook($book);
 69:     }
 70: 
 71:     /**
 72:      * TODO
 73:      */
 74:     protected function _canAdd()
 75:     {
 76:         return true;
 77:     }
 78: 
 79:     /**
 80:      * Deletes the specified object from the preferences.
 81:      *
 82:      * @param string $object_key TODO
 83:      * @param string $object_id  TODO
 84:      */
 85:     protected function _delete($object_key, $object_id)
 86:     {
 87:         $book = $this->_getAddressBook();
 88:         unset($book[$object_id]);
 89:         $this->_setAddressbook($book);
 90:     }
 91: 
 92:     /**
 93:      * Saves the specified object in the preferences.
 94:      *
 95:      * @param Turba_Object $object TODO
 96:      */
 97:     function _save($object)
 98:     {
 99:         list($object_key, $object_id) = each($this->toDriverKeys(array('__key' => $object->getValue('__key'))));
100:         $attributes = $this->toDriverKeys($object->getAttributes());
101: 
102:         $book = $this->_getAddressBook();
103:         $book[$object_id] = $attributes;
104:         $this->_setAddressBook($book);
105:     }
106: 
107:     /**
108:      * TODO
109:      *
110:      * @return TODO
111:      */
112:     protected function _getAddressBook()
113:     {
114:         global $prefs;
115: 
116:         $val = $prefs->getValue('prefbooks');
117:         if (!empty($val)) {
118:             $prefbooks = unserialize($val);
119:             return $prefbooks[$this->_params['name']];
120:         }
121: 
122:         return array();
123:     }
124: 
125:     /**
126:      * TODO
127:      *
128:      * @param $addressbook TODO
129:      *
130:      * @return TODO
131:      */
132:     protected function _setAddressBook($addressbook)
133:     {
134:         global $prefs;
135: 
136:         $val = $prefs->getValue('prefbooks');
137:         $prefbooks = empty($val)
138:             ? array()
139:             : unserialize($val);
140: 
141:         $prefbooks[$this->_params['name']] = $addressbook;
142:         $prefs->setValue('prefbooks', serialize($prefbooks));
143:         $prefs->store();
144:     }
145: 
146: }
147: 
API documentation generated by ApiGen