[ Index ]
 

Code source de Horde 3.1.3

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/Horde/DataTree/ -> null.php (source)

   1  <?php
   2  /**
   3   * The DataTree_null:: class provides a dummy implementation of the
   4   * DataTree:: API; no data will last beyond a single page request.
   5   *
   6   * $Horde: framework/DataTree/DataTree/null.php,v 1.15.2.4 2005/10/18 11:01:05 jan Exp $
   7   *
   8   * Copyright 1999, 2000, 2001, 2002 Stephane Huther <shuther@bigfoot.com>
   9   * Copyright 2001, 2002 Chuck Hagenbuch <chuck@horde.org>
  10   *
  11   * See the enclosed file COPYING for license information (LGPL).  If you
  12   * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
  13   *
  14   * @author  Chuck Hagenbuch <chuck@horde.org>
  15   * @since   Horde 3.0
  16   * @package Horde_DataTree
  17   */
  18  class DataTree_null extends DataTree {
  19  
  20      /**
  21       * Cache of attributes for any objects created during this page request.
  22       *
  23       * @var array
  24       */
  25      var $_attributeCache = array();
  26  
  27      /**
  28       * Cache of data for any objects created during this page request.
  29       *
  30       * @var array
  31       */
  32      var $_dataCache = array();
  33  
  34      /**
  35       * Load (a subset of) the datatree into the $_data array. Part of the
  36       * DataTree API that must be overridden by subclasses.
  37       *
  38       * @param string  $root    Which portion of the tree to load. Defaults to
  39       *                         all of it.
  40       * @param boolean $reload  Re-load already loaded values?
  41       *
  42       * @return mixed  True on success or a PEAR_Error on failure.
  43       *
  44       * @access private
  45       */
  46      function _load($root = null, $reload = false)
  47      {
  48      }
  49  
  50      /**
  51       * Load a specific object identified by its unique ID ($id), and
  52       * its parents, into the $_data array.
  53       *
  54       * @param integer $cid  The unique ID of the object to load.
  55       *
  56       * @return mixed  True on success or a PEAR_Error on failure.
  57       *
  58       * @access private
  59       */
  60      function _loadById($cid)
  61      {
  62      }
  63  
  64      /**
  65       * Get a tree sorted by the specified attribute name and/or key.
  66       *
  67       * @since Horde 3.1
  68       *
  69       * @param string  $root       Which portion of the tree to sort.
  70       *                            Defaults to all of it.
  71       * @param boolean $loadTree   Sort the tree starting at $root, or just the
  72       *                            requested level and direct parents?
  73       *                            Defaults to single level.
  74       * @param array $sortby_name  Attribute name to use for sorting.
  75       * @param array $sortby_key   Attribute key to use for sorting.
  76       * @param array $direction    Sort direction:
  77       *                              0 - ascending
  78       *                              1 - descending
  79       */
  80      function getSortedTree($root, $loadTree = false, $sortby_name = null, $sortby_key = null, $direction = 0)
  81      {
  82          return array();
  83      }
  84  
  85      /**
  86       * Add an object. Part of the DataTree API that must be
  87       * overridden by subclasses.
  88       *
  89       * @param mixed $fullname  The object to add (string or DataTreeObject).
  90       */
  91      function add($object)
  92      {
  93          if (is_a($object, 'DataTreeObject')) {
  94              $fullname = $object->getName();
  95              $order = $object->order;
  96          } else {
  97              $fullname = $object;
  98              $order = null;
  99          }
 100  
 101          $id = md5(mt_rand());
 102          if (strpos($fullname, ':') !== false) {
 103              $parts = explode(':', $fullname);
 104              $name = array_pop($parts);
 105              $parent = implode(':', $parts);
 106              $pid = $this->getId($parent);
 107              if (is_a($pid, 'PEAR_Error')) {
 108                  $this->add($parent);
 109              }
 110          } else {
 111              $pid = DATATREE_ROOT;
 112          }
 113  
 114          if (parent::exists($fullname)) {
 115              return PEAR::raiseError('Already exists');
 116          }
 117  
 118          $added = parent::_add($fullname, $id, $pid, $order);
 119          if (is_a($added, 'PEAR_Error')) {
 120              return $added;
 121          }
 122          return $this->updateData($object);
 123      }
 124  
 125      /**
 126       * Change order of the children of an object.
 127       *
 128       * @param string $parents  The parent id string path.
 129       * @param mixed $order     A specific new order position or an array
 130       *                         containing the new positions for the given
 131       *                         $parents object.
 132       * @param integer $cid     If provided indicates insertion of a new child
 133       *                         to the object, and will be used to avoid
 134       *                         incrementing it when shifting up all other
 135       *                         children's order. If not provided indicates
 136       *                         deletion, hence shift all other positions down
 137       *                         one.
 138       */
 139      function reorder($parents, $order = null, $cid = null)
 140      {
 141          if (is_array($order) && !empty($order)) {
 142              // Multi update.
 143              $this->_reorder($pid, $order);
 144          }
 145      }
 146  
 147      /**
 148       * Explicitly set the order for a datatree object.
 149       *
 150       * @param integer $id     The datatree object id to change.
 151       * @param integer $order  The new order.
 152       */
 153      function setOrder($id, $order)
 154      {
 155      }
 156  
 157      /**
 158       * Removes an object.
 159       *
 160       * @param mixed   $object  The object to remove.
 161       * @param boolean $force   Force removal of every child object?
 162       */
 163      function remove($object, $force = false)
 164      {
 165      }
 166  
 167      /**
 168       * Remove one or more objects by id. This function does *not* do
 169       * the validation, reordering, etc. that remove() does. If you
 170       * need to check for children, re-do ordering, etc., then you must
 171       * remove() objects one-by-one. This is for code that knows it's
 172       * dealing with single (non-parented) objects and needs to delete
 173       * a batch of them quickly.
 174       *
 175       * @param array $ids  The objects to remove.
 176       */
 177      function removeByIds($ids)
 178      {
 179      }
 180  
 181      /**
 182       * Remove one or more objects by name. This function does *not* do
 183       * the validation, reordering, etc. that remove() does. If you
 184       * need to check for children, re-do ordering, etc., then you must
 185       * remove() objects one-by-one. This is for code that knows it's
 186       * dealing with single (non-parented) objects and needs to delete
 187       * a batch of them quickly.
 188       *
 189       * @param array $names  The objects to remove.
 190       */
 191      function removeByNames($names)
 192      {
 193      }
 194  
 195      /**
 196       * Move an object to a new parent.
 197       *
 198       * @param mixed  $object     The object to move.
 199       * @param string $newparent  The new parent object. Defaults to the root.
 200       */
 201      function move($object, $newparent = null)
 202      {
 203      }
 204  
 205      /**
 206       * Change an object's name.
 207       *
 208       * @param mixed  $old_object       The old object.
 209       * @param string $new_object_name  The new object name.
 210       */
 211      function rename($old_object, $new_object_name)
 212      {
 213      }
 214  
 215      /**
 216       * Retrieve data for an object from the datatree_data field.
 217       *
 218       * @param integer $cid  The object id to fetch, or an array of object ids.
 219       */
 220      function getData($cid)
 221      {
 222          return isset($this->_dataCache[$cid]) ?
 223              $this->_dataCache[$cid] :
 224              array();
 225      }
 226  
 227      /**
 228       * Retrieve data for an object.
 229       *
 230       * @param integer $cid  The object id to fetch.
 231       */
 232      function getAttributes($cid)
 233      {
 234          if (is_array($cid)) {
 235              $data = array();
 236              foreach ($cid as $id) {
 237                  if (isset($this->_attributeCache[$id])) {
 238                      $data[$id] = $this->_attributeCache[$id];
 239                  }
 240              }
 241  
 242              return $data;
 243          } else {
 244              return isset($this->_attributeCache[$cid]) ?
 245                  $this->_attributeCache[$cid] :
 246                  array();
 247          }
 248      }
 249  
 250      /**
 251       * Returns the number of objects matching a set of attribute
 252       * criteria.
 253       *
 254       * @see buildAttributeQuery()
 255       *
 256       * @param array   $criteria   The array of criteria.
 257       * @param string  $parent     The parent node to start searching from.
 258       * @param boolean $allLevels  Return all levels, or just the direct
 259       *                            children of $parent? Defaults to all levels.
 260       * @param string  $restrict   Only return attributes with the same
 261       *                            attribute_name or attribute_id.
 262       */
 263      function countByAttributes($criteria, $parent = DATATREE_ROOT, $allLevels = true, $restrict = 'name')
 264      {
 265          if (!count($criteria)) {
 266              return 0;
 267          }
 268  
 269          return count($this->_attributeCache);
 270      }
 271  
 272      /**
 273       * Returns a set of object ids based on a set of attribute criteria.
 274       *
 275       * @see buildAttributeQuery()
 276       *
 277       * @param array   $criteria     The array of criteria.
 278       * @param string  $parent       The parent node to start searching from.
 279       * @param boolean $allLevels    Return all levels, or just the direct
 280       *                              children of $parent? Defaults to all levels.
 281       * @param string  $restrict     Only return attributes with the same
 282       *                              attribute_name or attribute_id.
 283       * @param integer $from         The object to start to fetching
 284       * @param integer $count        The number of objects to fetch
 285       * @param string  $sortby_name  Attribute name to use for sorting.
 286       * @param string  $sortby_key   Attribute key to use for sorting.
 287       * @param integer $direction    Sort direction:
 288       *                                0 - ascending
 289       *                                1 - descending
 290       */
 291      function getByAttributes($criteria, $parent = DATATREE_ROOT, $allLevels = true, $restrict = 'name', $from = 0, $count = 0,
 292                               $sortby_name = null, $sortby_key = null, $direction = 0)
 293      {
 294          if (!count($criteria)) {
 295              return PEAR::raiseError('no criteria');
 296          }
 297  
 298          return array_keys($this->_attributeCache);
 299      }
 300  
 301      /**
 302       * Sorts IDs by attribute values. IDs without attributes will be
 303       * added to the end of the sorted list.
 304       *
 305       * @param array $unordered_ids  Array of ids to sort.
 306       * @param array $sortby_name    Attribute name to use for sorting.
 307       * @param array $sortby_key     Attribute key to use for sorting.
 308       * @param array $direction      Sort direction:
 309       *                                0 - ascending
 310       *                                1 - descending
 311       *
 312       * @return array  Sorted ids.
 313       */
 314      function sortByAttributes($unordered_ids, $sortby_name = null, $sortby_key = null, $direction = 0)
 315      {
 316          return $unordered_ids;
 317      }
 318  
 319      /**
 320       * Returns a list of all of the available values of the given
 321       * attribute name/key combination. Either attribute_name or
 322       * attribute_key MUST be supplied, and both MAY be supplied.
 323       *
 324       * @param string $attribute_name  The name of the attribute.
 325       * @param string $attribute_key   The key value of the attribute.
 326       * @param string $parent          The parent node to start searching from.
 327       * @param boolean $allLevels      Return all levels, or just the direct
 328       *                                children of $parent?
 329       *
 330       * @return array  An array of all of the available values.
 331       */
 332      function getAttributeValues($attribute_name = null, $attribute_key = null, $parent = DATATREE_ROOT, $allLevels = true)
 333      {
 334          return array();
 335      }
 336  
 337      /**
 338       * Update the data in an object. Does not change the object's
 339       * parent or name, just serialized data.
 340       *
 341       * @param string $object  The object.
 342       */
 343      function updateData($object)
 344      {
 345          if (!is_a($object, 'DataTreeObject')) {
 346              return true;
 347          }
 348  
 349          $cid = $this->getId($object->getName());
 350          if (is_a($cid, 'PEAR_Error')) {
 351              return $cid;
 352          }
 353  
 354          // We handle data differently if we can map it to
 355          // attributes.
 356          if (method_exists($object, '_toAttributes')) {
 357              $this->_attributeCache[$cid] = $object->_toAttributes();
 358          } else {
 359              $this->_dataCache[$cid] = $object->getData();
 360          }
 361  
 362          return true;
 363      }
 364  
 365  }


Généré le : Sun Feb 25 18:01:28 2007 par Balluche grâce à PHPXref 0.7