2007-07-19 12:40:28 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2008-08-12 04:51:33 +02:00
|
|
|
* This class represents a set of {@link ViewableData} subclasses (mostly {@link DataObject} or {@link ArrayData}).
|
2008-02-25 03:10:37 +01:00
|
|
|
* It is used by the ORM-layer of Silverstripe to return query-results from {@link SQLQuery}.
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2009-12-18 04:35:26 +01:00
|
|
|
class DataObjectSet extends ViewableData implements IteratorAggregate, Countable, ArrayAccess {
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* The DataObjects in this set.
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $items = array();
|
|
|
|
|
|
|
|
protected $odd = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the current DataObject is the first in this set.
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
protected $first = true;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* True if the current DataObject is the last in this set.
|
|
|
|
* @var boolean
|
|
|
|
*/
|
|
|
|
protected $last = false;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The current DataObject in this set.
|
|
|
|
* @var DataObject
|
|
|
|
*/
|
|
|
|
protected $current = null;
|
|
|
|
|
|
|
|
/**
|
2008-02-25 03:10:37 +01:00
|
|
|
* Create a new DataObjectSet. If you pass one or more arguments, it will try to convert them into {@link ArrayData} objects.
|
|
|
|
* @todo Does NOT automatically convert objects with complex datatypes (e.g. converting arrays within an objects to its own DataObjectSet)
|
|
|
|
*
|
|
|
|
* @param ViewableData|array|mixed $items Parameters to use in this set, either as an associative array, object with simple properties, or as multiple parameters.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-02-25 03:10:37 +01:00
|
|
|
public function __construct($items = null) {
|
2007-07-19 12:40:28 +02:00
|
|
|
if($items) {
|
2008-02-25 03:10:37 +01:00
|
|
|
// if the first parameter is not an array, or we have more than one parameter, collate all parameters to an array
|
|
|
|
// otherwise use the passed array
|
|
|
|
$itemsArr = (!is_array($items) || count(func_get_args()) > 1) ? func_get_args() : $items;
|
|
|
|
|
|
|
|
// We now have support for using the key of a data object set
|
|
|
|
foreach($itemsArr as $i => $item) {
|
|
|
|
if(is_subclass_of($item, 'ViewableData')) {
|
|
|
|
$this->items[$i] = $item;
|
|
|
|
} elseif(is_object($item) || ArrayLib::is_associative($item)) {
|
|
|
|
$this->items[$i] = new ArrayData($item);
|
|
|
|
} else {
|
|
|
|
user_error(
|
|
|
|
"DataObjectSet::__construct: Passed item #{$i} is not an object or associative array,
|
|
|
|
can't be properly iterated on in templates",
|
|
|
|
E_USER_WARNING
|
|
|
|
);
|
|
|
|
$this->items[$i] = $item;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
2009-12-18 04:35:26 +01:00
|
|
|
/**
|
|
|
|
* Necessary for interface ArrayAccess. Returns whether an item with $key exists
|
|
|
|
* @param mixed $key
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function offsetExists($key) {
|
|
|
|
return isset($this->items[$key]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Necessary for interface ArrayAccess. Returns item stored in array with index $key
|
|
|
|
* @param mixed $key
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
public function offsetGet($key) {
|
|
|
|
return $this->items[$key];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Necessary for interface ArrayAccess. Set an item with the key in $key
|
|
|
|
* @param mixed $key
|
|
|
|
* @param mixed $value
|
|
|
|
*/
|
|
|
|
public function offsetSet($key, $value) {
|
|
|
|
$this->items[$key] = $value;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Necessary for interface ArrayAccess. Unset an item with the key in $key
|
|
|
|
* @param mixed $key
|
|
|
|
*/
|
|
|
|
public function offsetUnset($key) {
|
|
|
|
unset($this->items[$key]);
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Destory all of the DataObjects in this set.
|
|
|
|
*/
|
|
|
|
public function destroy() {
|
2009-11-22 06:16:38 +01:00
|
|
|
foreach($this as $item) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$item->destroy();
|
|
|
|
}
|
|
|
|
}
|
2009-12-18 04:35:26 +01:00
|
|
|
|
2009-12-16 06:37:50 +01:00
|
|
|
/**
|
|
|
|
* Removes all the items in this set.
|
|
|
|
*/
|
|
|
|
public function emptyItems() {
|
|
|
|
$this->items = array();
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert this DataObjectSet to an array of DataObjects.
|
|
|
|
* @param string $index Index the array by this field.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray($index = null) {
|
|
|
|
$map = array();
|
2009-11-22 06:16:38 +01:00
|
|
|
foreach($this as $item) {
|
|
|
|
if($index) $map[$item->$index] = $item;
|
|
|
|
else $map[] = $item;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $map;
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Convert this DataObjectSet to an array of maps.
|
|
|
|
* @param string $index Index the array by this field.
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toNestedArray($index = null){
|
|
|
|
if(!$index) {
|
|
|
|
$index = "ID";
|
|
|
|
}
|
|
|
|
|
|
|
|
$map = array();
|
|
|
|
|
2009-11-22 06:16:38 +01:00
|
|
|
foreach( $this as $item ) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$map[$item->$index] = $item->getAllFields();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $map;
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2009-04-29 02:07:39 +02:00
|
|
|
* Returns an array of ID => Title for the items in this set.
|
|
|
|
*
|
|
|
|
* This is an alias of {@link DataObjectSet->map()}
|
|
|
|
*
|
|
|
|
* @deprecated 2.5 Please use map() instead
|
|
|
|
*
|
|
|
|
* @param string $index The field to use as a key for the array
|
|
|
|
* @param string $titleField The field (or method) to get values for the map
|
|
|
|
* @param string $emptyString Empty option text e.g "(Select one)"
|
|
|
|
* @param bool $sort Sort the map alphabetically based on the $titleField value
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toDropDownMap($index = 'ID', $titleField = 'Title', $emptyString = null, $sort = false) {
|
|
|
|
return $this->map($index, $titleField, $emptyString, $sort);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Add an item to the DataObject Set.
|
|
|
|
* @param DataObject $item Item to add.
|
|
|
|
* @param string $key Key to index this DataObject by.
|
|
|
|
*/
|
|
|
|
public function push($item, $key = null) {
|
|
|
|
if($key != null) {
|
|
|
|
unset($this->items[$key]);
|
|
|
|
$this->items[$key] = $item;
|
|
|
|
} else {
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-08-16 08:34:30 +02:00
|
|
|
/**
|
|
|
|
* Add an item to the beginning of the DataObjectSet
|
|
|
|
* @param DataObject $item Item to add
|
|
|
|
* @param string $key Key to index this DataObject by.
|
|
|
|
*/
|
|
|
|
public function insertFirst($item, $key = null) {
|
2008-02-25 03:10:37 +01:00
|
|
|
if($key == null) {
|
|
|
|
array_unshift($this->items, $item);
|
2007-08-16 08:34:30 +02:00
|
|
|
} else {
|
2010-05-25 05:53:43 +02:00
|
|
|
$this->items = array_merge(array($key=>$item), $this->items);
|
2007-08-16 08:34:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Insert a DataObject at the beginning of this set.
|
|
|
|
* @param DataObject $item Item to insert.
|
|
|
|
*/
|
2010-10-19 03:20:56 +02:00
|
|
|
public function unshift($item) {
|
|
|
|
$this->insertFirst($item);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2010-10-19 03:20:56 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a DataObject from the beginning of this set and return it.
|
|
|
|
* This is the equivalent of pop() but acts on the head of the set.
|
|
|
|
* Opposite of unshift().
|
|
|
|
*
|
|
|
|
* @return DataObject (or null if there are no items in the set)
|
|
|
|
*/
|
|
|
|
public function shift() {
|
|
|
|
return array_shift($this->items);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a DataObject from the end of this set and return it.
|
|
|
|
* This is the equivalent of shift() but acts on the tail of the set.
|
|
|
|
* Opposite of push().
|
|
|
|
*
|
|
|
|
* @return DataObject (or null if there are no items in the set)
|
|
|
|
*/
|
|
|
|
public function pop() {
|
|
|
|
return array_pop($this->items);
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Remove a DataObject from this set.
|
|
|
|
* @param DataObject $itemObject Item to remove.
|
|
|
|
*/
|
|
|
|
public function remove($itemObject) {
|
|
|
|
foreach($this->items as $key=>$item){
|
|
|
|
if($item === $itemObject){
|
|
|
|
unset($this->items[$key]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-01-10 12:35:50 +01:00
|
|
|
/**
|
|
|
|
* Replaces $itemOld with $itemNew
|
|
|
|
*
|
|
|
|
* @param DataObject $itemOld
|
|
|
|
* @param DataObject $itemNew
|
|
|
|
*/
|
|
|
|
public function replace($itemOld, $itemNew) {
|
|
|
|
foreach($this->items as $key => $item) {
|
|
|
|
if($item === $itemOld) {
|
|
|
|
$this->items[$key] = $itemNew;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Merge another set onto the end of this set.
|
2010-10-15 05:26:27 +02:00
|
|
|
* To merge without causing duplicates, consider calling
|
|
|
|
* {@link removeDuplicates()} after this method on the new set.
|
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* @param DataObjectSet $anotherSet Set to mege onto this set.
|
|
|
|
*/
|
|
|
|
public function merge($anotherSet){
|
2008-08-12 04:51:33 +02:00
|
|
|
if($anotherSet) {
|
2010-05-25 05:53:43 +02:00
|
|
|
foreach($anotherSet as $item){
|
2008-08-12 04:51:33 +02:00
|
|
|
$this->push($item);
|
2010-05-25 05:53:43 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Gets a specific slice of an existing set.
|
|
|
|
*
|
|
|
|
* @param int $offset
|
|
|
|
* @param int $length
|
|
|
|
* @return DataObjectSet
|
|
|
|
*/
|
|
|
|
public function getRange($offset, $length) {
|
2010-05-25 05:53:43 +02:00
|
|
|
$set = array_slice($this->items, (int)$offset, (int)$length);
|
|
|
|
return new DataObjectSet($set);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2008-03-11 02:31:43 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2008-03-11 02:31:43 +01:00
|
|
|
* Returns an Iterator for this DataObjectSet.
|
|
|
|
* This function allows you to use DataObjectSets in foreach loops
|
|
|
|
* @return DataObjectSet_Iterator
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2008-03-11 02:31:43 +01:00
|
|
|
public function getIterator() {
|
|
|
|
return new DataObjectSet_Iterator($this->items);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns false if the set is empty.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function exists() {
|
2009-11-22 06:16:38 +01:00
|
|
|
return $this->count() > 0;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the first item in the set.
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
public function First() {
|
2007-09-14 19:59:33 +02:00
|
|
|
if(count($this->items) < 1)
|
|
|
|
return null;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$keys = array_keys($this->items);
|
2010-05-25 05:53:43 +02:00
|
|
|
return $this->items[$keys[0]];
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the last item in the set.
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
public function Last() {
|
2007-09-14 19:59:33 +02:00
|
|
|
if(count($this->items) < 1)
|
|
|
|
return null;
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$keys = array_keys($this->items);
|
|
|
|
return $this->items[$keys[sizeof($keys)-1]];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-03-31 03:01:04 +02:00
|
|
|
* @deprecated 3.0 Use {@link DataObjectSet::Count()}.
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
public function TotalItems() {
|
2011-03-31 03:01:04 +02:00
|
|
|
return $this->Count();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the actual number of items in this dataset.
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function Count() {
|
|
|
|
return sizeof($this->items);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns this set as a XHTML unordered list.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function UL() {
|
2009-11-22 06:16:38 +01:00
|
|
|
if($this->exists()) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$result = "<ul id=\"Menu1\">\n";
|
2009-11-22 06:16:38 +01:00
|
|
|
foreach($this as $item) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$result .= "<li onclick=\"location.href = this.getElementsByTagName('a')[0].href\"><a href=\"$item->Link\">$item->Title</a></li>\n";
|
|
|
|
}
|
|
|
|
$result .= "</ul>\n";
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns this set as a XHTML unordered list.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function forTemplate() {
|
|
|
|
return $this->UL();
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
|
|
|
/**
|
2009-04-29 02:07:39 +02:00
|
|
|
* Returns an array of ID => Title for the items in this set.
|
2007-07-19 12:40:28 +02:00
|
|
|
*
|
2009-04-29 02:07:39 +02:00
|
|
|
* @param string $index The field to use as a key for the array
|
|
|
|
* @param string $titleField The field (or method) to get values for the map
|
|
|
|
* @param string $emptyString Empty option text e.g "(Select one)"
|
|
|
|
* @param bool $sort Sort the map alphabetically based on the $titleField value
|
|
|
|
* @return array
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2009-04-29 02:07:39 +02:00
|
|
|
public function map($index = 'ID', $titleField = 'Title', $emptyString = null, $sort = false) {
|
2008-08-12 04:51:33 +02:00
|
|
|
$map = array();
|
2009-11-22 06:16:38 +01:00
|
|
|
foreach($this as $item) {
|
|
|
|
$map[$item->$index] = ($item->hasMethod($titleField))
|
|
|
|
? $item->$titleField() : $item->$titleField;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2009-11-22 06:16:38 +01:00
|
|
|
if($emptyString) $map = array('' => $emptyString) + $map;
|
2009-04-29 02:07:39 +02:00
|
|
|
|
|
|
|
if($sort) asort($map);
|
|
|
|
|
2007-09-14 19:59:33 +02:00
|
|
|
return $map;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2009-11-22 06:16:38 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find an item in this list where the field $key is equal to $value
|
|
|
|
* Eg: $doSet->find('ID', 4);
|
|
|
|
* @return ViewableData The first matching item.
|
|
|
|
*/
|
|
|
|
public function find($key, $value) {
|
|
|
|
foreach($this as $item) {
|
|
|
|
if($item->$key == $value) return $item;
|
|
|
|
}
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a column of the given field
|
|
|
|
* @param string $value The field name
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function column($value = "ID") {
|
|
|
|
$list = array();
|
2009-11-22 06:16:38 +01:00
|
|
|
foreach($this as $item ){
|
2008-12-04 23:38:32 +01:00
|
|
|
$list[] = ($item->hasMethod($value)) ? $item->$value() : $item->$value;
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
return $list;
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2009-04-23 04:37:44 +02:00
|
|
|
* Returns an array of DataObjectSets. The array is keyed by index.
|
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* @param string $index The field name to index the array by.
|
|
|
|
* @return array
|
|
|
|
*/
|
2009-11-22 06:16:38 +01:00
|
|
|
public function groupBy($index){
|
|
|
|
foreach($this as $item ){
|
2009-04-23 04:37:44 +02:00
|
|
|
$key = ($item->hasMethod($index)) ? $item->$index() : $item->$index;
|
|
|
|
if(!isset($result[$key])) {
|
|
|
|
$result[$key] = new DataObjectSet();
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2009-04-23 04:37:44 +02:00
|
|
|
$result[$key]->push($item);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Groups the items by a given field.
|
|
|
|
* Returns a DataObjectSet suitable for use in a nested template.
|
|
|
|
* @param string $index The field to group by
|
|
|
|
* @param string $childControl The name of the nested page control
|
|
|
|
* @return DataObjectSet
|
|
|
|
*/
|
|
|
|
public function GroupedBy($index, $childControl = "Children") {
|
|
|
|
$grouped = $this->groupBy($index);
|
|
|
|
$groupedAsSet = new DataObjectSet();
|
|
|
|
foreach($grouped as $group) {
|
|
|
|
$groupedAsSet->push($group->First()->customise(array(
|
|
|
|
$childControl => $group
|
|
|
|
)));
|
|
|
|
}
|
|
|
|
return $groupedAsSet;
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a nested unordered list out of a "chain" of DataObject-relations,
|
|
|
|
* using the automagic ComponentSet-relation-methods to find subsequent DataObjectSets.
|
|
|
|
* The formatting of the list can be different for each level, and is evaluated as an SS-template
|
|
|
|
* with access to the current DataObjects attributes and methods.
|
2007-09-14 19:59:33 +02:00
|
|
|
*
|
2007-07-19 12:40:28 +02:00
|
|
|
* Example: Groups (Level 0, the "calling" DataObjectSet, needs to be queried externally)
|
|
|
|
* and their Members (Level 1, determined by the Group->Members()-relation).
|
|
|
|
*
|
|
|
|
* @param array $nestingLevels
|
|
|
|
* Defines relation-methods on DataObjects as a string, plus custom
|
|
|
|
* SS-template-code for the list-output. Use "Root" for the current DataObjectSet (is will not evaluate into
|
|
|
|
* a function).
|
|
|
|
* Caution: Don't close the list-elements (determined programatically).
|
|
|
|
* You need to escape dollar-signs that need to be evaluated as SS-template-code.
|
|
|
|
* Use $EvenOdd to get appropriate classes for CSS-styling.
|
|
|
|
* Format:
|
|
|
|
* array(
|
|
|
|
* array(
|
2007-09-14 19:59:33 +02:00
|
|
|
* "dataclass" => "Root",
|
2007-07-19 12:40:28 +02:00
|
|
|
* "template" => "<li class=\"\$EvenOdd\"><a href=\"admin/crm/show/\$ID\">\$AccountName</a>"
|
|
|
|
* ),
|
|
|
|
* array(
|
2007-09-14 19:59:33 +02:00
|
|
|
* "dataclass" => "GrantObjects",
|
2007-07-19 12:40:28 +02:00
|
|
|
* "template" => "<li class=\"\$EvenOdd\"><a href=\"admin/crm/showgrant/\$ID\">#\$GrantNumber: \$TotalAmount.Nice, \$ApplicationDate.ShortMonth \$ApplicationDate.Year</a>"
|
|
|
|
* )
|
|
|
|
* );
|
|
|
|
* @param string $ulExtraAttributes Extra attributes
|
|
|
|
*
|
|
|
|
* @return string Unordered List (HTML)
|
|
|
|
*/
|
|
|
|
public function buildNestedUL($nestingLevels, $ulExtraAttributes = "") {
|
|
|
|
return $this->getChildrenAsUL($nestingLevels, 0, "", $ulExtraAttributes);
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Gets called recursively on the child-objects of the chain.
|
|
|
|
*
|
|
|
|
* @param array $nestingLevels see {@buildNestedUL}
|
|
|
|
* @param int $level Current nesting level
|
|
|
|
* @param string $template Template for list item
|
|
|
|
* @param string $ulExtraAttributes Extra attributes
|
|
|
|
* @return string
|
|
|
|
*/
|
2008-11-21 02:06:21 +01:00
|
|
|
public function getChildrenAsUL($nestingLevels, $level = 0, $template = "<li id=\"record-\$ID\" class=\"\$EvenOdd\">\$Title", $ulExtraAttributes = null, &$itemCount = 0) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$output = "";
|
|
|
|
$hasNextLevel = false;
|
|
|
|
$ulExtraAttributes = " $ulExtraAttributes";
|
|
|
|
$output = "<ul" . eval($ulExtraAttributes) . ">\n";
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$currentNestingLevel = $nestingLevels[$level];
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// either current or default template
|
|
|
|
$currentTemplate = (!empty($currentNestingLevel)) ? $currentNestingLevel['template'] : $template;
|
|
|
|
$myViewer = SSViewer::fromString($currentTemplate);
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2008-11-21 02:06:21 +01:00
|
|
|
if(isset($nestingLevels[$level+1]['dataclass'])){
|
2009-02-02 00:49:53 +01:00
|
|
|
$childrenMethod = $nestingLevels[$level+1]['dataclass'];
|
2008-11-21 02:06:21 +01:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
// sql-parts
|
2008-11-21 02:06:21 +01:00
|
|
|
|
|
|
|
$filter = (isset($nestingLevels[$level+1]['filter'])) ? $nestingLevels[$level+1]['filter'] : null;
|
|
|
|
$sort = (isset($nestingLevels[$level+1]['sort'])) ? $nestingLevels[$level+1]['sort'] : null;
|
|
|
|
$join = (isset($nestingLevels[$level+1]['join'])) ? $nestingLevels[$level+1]['join'] : null;
|
|
|
|
$limit = (isset($nestingLevels[$level+1]['limit'])) ? $nestingLevels[$level+1]['limit'] : null;
|
|
|
|
$having = (isset($nestingLevels[$level+1]['having'])) ? $nestingLevels[$level+1]['having'] : null;
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
foreach($this as $parent) {
|
2007-09-14 19:59:33 +02:00
|
|
|
$evenOdd = ($itemCount % 2 == 0) ? "even" : "odd";
|
2007-07-19 12:40:28 +02:00
|
|
|
$parent->setField('EvenOdd', $evenOdd);
|
|
|
|
$template = $myViewer->process($parent);
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// if no output is selected, fall back to the id to keep the item "clickable"
|
2007-09-14 19:59:33 +02:00
|
|
|
$output .= $template . "\n";
|
|
|
|
|
2008-11-21 02:06:21 +01:00
|
|
|
if(isset($childrenMethod)) {
|
2007-07-19 12:40:28 +02:00
|
|
|
// workaround for missing groupby/having-parameters in instance_get
|
|
|
|
// get the dataobjects for the next level
|
|
|
|
$children = $parent->$childrenMethod($filter, $sort, $join, $limit, $having);
|
|
|
|
if($children) {
|
2007-09-14 19:59:33 +02:00
|
|
|
$output .= $children->getChildrenAsUL($nestingLevels, $level+1, $currentTemplate, $ulExtraAttributes);
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$output .= "</li>\n";
|
|
|
|
$itemCount++;
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$output .= "</ul>\n";
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $output;
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2009-03-10 23:08:52 +01:00
|
|
|
* Sorts the current DataObjectSet instance.
|
|
|
|
* @param string $fieldname The name of the field on the DataObject that you wish to sort the set by.
|
|
|
|
* @param string $direction Direction to sort by, either "ASC" or "DESC".
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
|
|
|
public function sort($fieldname, $direction = "ASC") {
|
|
|
|
if($this->items) {
|
2010-12-11 06:43:08 +01:00
|
|
|
if (is_string($fieldname) && preg_match('/(.+?)(\s+?)(A|DE)SC$/', $fieldname, $matches)) {
|
2010-04-13 04:17:25 +02:00
|
|
|
$fieldname = $matches[1];
|
|
|
|
$direction = $matches[3].'SC';
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
column_sort($this->items, $fieldname, $direction, false);
|
|
|
|
}
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
2010-02-23 23:15:23 +01:00
|
|
|
* Remove duplicates from this set based on the dataobjects field.
|
|
|
|
* Assumes all items contained in the set all have that field.
|
2010-10-15 05:26:27 +02:00
|
|
|
* Useful after merging to sets via {@link merge()}.
|
|
|
|
*
|
2010-02-23 23:15:23 +01:00
|
|
|
* @param string $field the field to check for duplicates
|
2007-07-19 12:40:28 +02:00
|
|
|
*/
|
2010-02-23 23:15:23 +01:00
|
|
|
public function removeDuplicates($field = 'ID') {
|
2007-07-19 12:40:28 +02:00
|
|
|
$exists = array();
|
|
|
|
foreach($this->items as $key => $item) {
|
2010-10-04 06:15:33 +02:00
|
|
|
if(isset($exists[$fullkey = ClassInfo::baseDataClass($item) . ":" . $item->$field])) {
|
2007-07-19 12:40:28 +02:00
|
|
|
unset($this->items[$key]);
|
|
|
|
}
|
2010-10-04 06:15:33 +02:00
|
|
|
$exists[$fullkey] = true;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns information about this set in HTML format for debugging.
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function debug() {
|
2008-11-11 03:36:30 +01:00
|
|
|
$val = "<h2>" . $this->class . "</h2><ul>";
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach($this as $item) {
|
|
|
|
$val .= "<li style=\"list-style-type: disc; margin-left: 20px\">" . Debug::text($item) . "</li>";
|
|
|
|
}
|
|
|
|
$val .= "</ul>";
|
|
|
|
return $val;
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
/**
|
|
|
|
* Groups the set by $groupField and returns the parent of each group whose class
|
|
|
|
* is $groupClassName. If $collapse is true, the group will be collapsed up until an ancestor with the
|
|
|
|
* given class is found.
|
|
|
|
* @param string $groupField The field to group by.
|
|
|
|
* @param string $groupClassName Classname.
|
|
|
|
* @param string $sortParents SORT clause to insert into the parents SQL.
|
|
|
|
* @param string $parentField Parent field.
|
|
|
|
* @param boolean $collapse Collapse up until an ancestor with the given class is found.
|
|
|
|
* @param string $requiredParents Required parents
|
|
|
|
* @return DataObjectSet
|
|
|
|
*/
|
|
|
|
public function groupWithParents($groupField, $groupClassName, $sortParents = null, $parentField = 'ID', $collapse = false, $requiredParents = null) {
|
2011-03-23 00:16:18 +01:00
|
|
|
$groupTable = ClassInfo::baseDataClass($groupClassName);
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// Each item in this DataObjectSet is grouped into a multidimensional array
|
|
|
|
// indexed by it's parent. The parent IDs are later used to find the parents
|
|
|
|
// that make up the returned set.
|
|
|
|
$groupedSet = array();
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// Array to store the subgroups matching the requirements
|
|
|
|
$resultsArray = array();
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// Put this item into the array indexed by $groupField.
|
|
|
|
// the keys are later used to retrieve the top-level records
|
2009-11-22 06:16:38 +01:00
|
|
|
foreach( $this as $item ) {
|
2007-07-19 12:40:28 +02:00
|
|
|
$groupedSet[$item->$groupField][] = $item;
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$parentSet = null;
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// retrieve parents for this set
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// TODO How will we collapse the hierarchy to bridge the gap?
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// if collapse is specified, then find the most direct ancestor of type
|
|
|
|
// $groupClassName
|
|
|
|
if($collapse) {
|
|
|
|
// The most direct ancestors with the type $groupClassName
|
|
|
|
$parentSet = array();
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// get direct parents
|
2011-03-23 00:16:18 +01:00
|
|
|
$parents = DataObject::get($groupClassName, "\"$groupTable\".\"$parentField\" IN( " . implode( ",", array_keys( $groupedSet ) ) . ")", $sortParents );
|
2007-07-19 12:40:28 +02:00
|
|
|
|
|
|
|
// for each of these parents...
|
|
|
|
foreach($parents as $parent) {
|
|
|
|
// store the old parent ID. This is required to change the grouped items
|
|
|
|
// in the $groupSet array
|
|
|
|
$oldParentID = $parent->ID;
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// get the parental stack
|
|
|
|
$parentObjects= $parent->parentStack();
|
|
|
|
$parentStack = array();
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
foreach( $parentObjects as $parentObj )
|
|
|
|
$parentStack[] = $parentObj->ID;
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// is some particular IDs are required, then get the intersection
|
|
|
|
if($requiredParents && count($requiredParents)) {
|
|
|
|
$parentStack = array_intersect($requiredParents, $parentStack);
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$newParent = null;
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// If there are no parents, the group can be omitted
|
|
|
|
if(empty($parentStack)) {
|
|
|
|
$newParent = new DataObjectSet();
|
|
|
|
} else {
|
2011-03-23 00:16:18 +01:00
|
|
|
$newParent = DataObject::get_one( $groupClassName, "\"$groupTable\".\"$parentField\" IN( " . implode( ",", $parentStack ) . ")" );
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// change each of the descendant's association from the old parent to
|
|
|
|
// the new parent. This effectively collapses the hierarchy
|
|
|
|
foreach( $groupedSet[$oldParentID] as $descendant ) {
|
|
|
|
$groupedSet[$newParent->ID][] = $descendant;
|
|
|
|
}
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
// Add the most direct ancestor of type $groupClassName
|
|
|
|
$parentSet[] = $newParent;
|
2007-09-14 19:59:33 +02:00
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
// otherwise get the parents of these items
|
|
|
|
} else {
|
2007-09-14 19:59:33 +02:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$requiredIDs = array_keys( $groupedSet );
|
|
|
|
|
|
|
|
if( $requiredParents && cont($requiredParents)) {
|
|
|
|
$requiredIDs = array_intersect($requiredParents, $requiredIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(empty($requiredIDs)) {
|
|
|
|
$parentSet = new DataObjectSet();
|
|
|
|
} else {
|
2011-03-23 00:16:18 +01:00
|
|
|
$parentSet = DataObject::get( $groupClassName, "\"$groupTable\".\"$parentField\" IN( " . implode( ",", $requiredIDs ) . ")", $sortParents );
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$parentSet = $parentSet->toArray();
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach($parentSet as $parent) {
|
|
|
|
$resultsArray[] = $parent->customise(array(
|
|
|
|
"GroupItems" => new DataObjectSet($groupedSet[$parent->$parentField])
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
return new DataObjectSet($resultsArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a field to this set without writing it to the database
|
|
|
|
* @param DataObject $field Field to add
|
|
|
|
*/
|
|
|
|
function addWithoutWrite($field) {
|
|
|
|
$this->items[] = $field;
|
|
|
|
}
|
2007-08-16 08:34:30 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the DataObjectSet contains all of the IDs givem
|
|
|
|
* @param $idList An array of object IDs
|
|
|
|
*/
|
|
|
|
function containsIDs($idList) {
|
|
|
|
foreach($idList as $item) $wants[$item] = true;
|
2009-11-22 06:16:38 +01:00
|
|
|
foreach($this as $item) if($item) unset($wants[$item->ID]);
|
2007-08-16 08:34:30 +02:00
|
|
|
return !$wants;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns true if the DataObjectSet contains all of and *only* the IDs given.
|
|
|
|
* Note that it won't like duplicates very much.
|
|
|
|
* @param $idList An array of object IDs
|
|
|
|
*/
|
|
|
|
function onlyContainsIDs($idList) {
|
2009-11-22 06:16:38 +01:00
|
|
|
return $this->containsIDs($idList) && sizeof($idList) == $this->count();
|
2007-08-16 08:34:30 +02:00
|
|
|
}
|
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2009-03-10 23:08:52 +01:00
|
|
|
* Sort a 2D array by particular column.
|
|
|
|
* @param array $data The array to sort.
|
2010-12-11 06:43:08 +01:00
|
|
|
* @param mixed $column The name of the column you wish to sort by, or an array of column=>directions to sort by.
|
2009-03-10 23:08:52 +01:00
|
|
|
* @param string $direction Direction to sort by, either "ASC" or "DESC".
|
2007-07-19 12:40:28 +02:00
|
|
|
* @param boolean $preserveIndexes Preserve indexes
|
|
|
|
*/
|
|
|
|
function column_sort(&$data, $column, $direction = "ASC", $preserveIndexes = true) {
|
2010-12-11 06:43:08 +01:00
|
|
|
global $column_sort_field;
|
|
|
|
|
|
|
|
// if we were only given a string for column, move it into an array
|
|
|
|
if (is_string($column)) $column = array($column => $direction);
|
|
|
|
|
|
|
|
// convert directions to integers
|
|
|
|
foreach ($column as $k => $v) {
|
|
|
|
if ($v == 'ASC') {
|
|
|
|
$column[$k] = 1;
|
|
|
|
}
|
|
|
|
elseif ($v == 'DESC') {
|
|
|
|
$column[$k] = -1;
|
|
|
|
}
|
|
|
|
elseif (!is_numeric($v)) {
|
|
|
|
$column[$k] = 0;
|
|
|
|
}
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2010-12-11 06:43:08 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
$column_sort_field = $column;
|
2010-12-11 06:43:08 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
if($preserveIndexes) {
|
|
|
|
uasort($data, "column_sort_callback_basic");
|
|
|
|
} else {
|
|
|
|
usort($data, "column_sort_callback_basic");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback used by column_sort
|
|
|
|
*/
|
|
|
|
function column_sort_callback_basic($a, $b) {
|
2010-12-11 06:43:08 +01:00
|
|
|
global $column_sort_field;
|
|
|
|
$result = 0;
|
|
|
|
// loop through each sort field
|
|
|
|
foreach ($column_sort_field as $field => $multiplier) {
|
|
|
|
// if A < B then no further examination is necessary
|
|
|
|
if ($a->$field < $b->$field) {
|
|
|
|
$result = -1 * $multiplier;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// if A > B then no further examination is necessary
|
|
|
|
elseif ($a->$field > $b->$field) {
|
|
|
|
$result = $multiplier;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// A == B means we need to compare the two using the next field
|
|
|
|
// if this was the last field, then function returns that objects
|
|
|
|
// are equivalent
|
2007-07-19 12:40:28 +02:00
|
|
|
}
|
2010-12-11 06:43:08 +01:00
|
|
|
|
2007-07-19 12:40:28 +02:00
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
2008-03-11 02:31:43 +01:00
|
|
|
/**
|
|
|
|
* An Iterator for a DataObjectSet
|
2010-10-13 05:53:12 +02:00
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
2008-03-11 02:31:43 +01:00
|
|
|
*/
|
|
|
|
class DataObjectSet_Iterator implements Iterator {
|
|
|
|
function __construct($items) {
|
|
|
|
$this->items = $items;
|
|
|
|
|
|
|
|
$this->current = $this->prepareItem(current($this->items));
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Prepare an item taken from the internal array for
|
|
|
|
* output by this iterator. Ensures that it is an object.
|
|
|
|
* @param DataObject $item Item to prepare
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
protected function prepareItem($item) {
|
|
|
|
if(is_object($item)) {
|
|
|
|
$item->iteratorProperties(key($this->items), sizeof($this->items));
|
|
|
|
}
|
|
|
|
// This gives some reliablity but it patches over the root cause of the bug...
|
|
|
|
// else if(key($this->items) !== null) $item = new ViewableData();
|
|
|
|
return $item;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the current object of the iterator.
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
public function current() {
|
|
|
|
return $this->current;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the key of the current object of the iterator.
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function key() {
|
|
|
|
return key($this->items);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the next item in this set.
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
public function next() {
|
|
|
|
$this->current = $this->prepareItem(next($this->items));
|
|
|
|
return $this->current;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Rewind the iterator to the beginning of the set.
|
|
|
|
* @return DataObject The first item in the set.
|
|
|
|
*/
|
|
|
|
public function rewind() {
|
|
|
|
$this->current = $this->prepareItem(reset($this->items));
|
|
|
|
return $this->current;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check the iterator is pointing to a valid item in the set.
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
public function valid() {
|
|
|
|
return $this->current !== false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the next item in this set without progressing the iterator.
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
public function peekNext() {
|
|
|
|
return $this->getOffset(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the prvious item in this set, without affecting the iterator.
|
|
|
|
* @return DataObject
|
|
|
|
*/
|
|
|
|
public function peekPrev() {
|
|
|
|
return $this->getOffset(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the object in this set offset by $offset from the iterator pointer.
|
|
|
|
* @param int $offset The offset.
|
2009-05-20 01:11:38 +02:00
|
|
|
* @return DataObject|boolean DataObject of offset item, or boolean FALSE if not found
|
2008-03-11 02:31:43 +01:00
|
|
|
*/
|
|
|
|
public function getOffset($offset) {
|
|
|
|
$keys = array_keys($this->items);
|
|
|
|
foreach($keys as $i => $key) {
|
|
|
|
if($key == key($this->items)) break;
|
|
|
|
}
|
2009-05-20 01:11:38 +02:00
|
|
|
|
|
|
|
if(isset($keys[$i + $offset])) {
|
|
|
|
$requiredKey = $keys[$i + $offset];
|
|
|
|
return $this->items[$requiredKey];
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2008-03-11 02:31:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-02-02 00:49:53 +01:00
|
|
|
?>
|