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