2011-04-01 06:09:48 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* A base class for decorators that wrap around a list to provide additional
|
2012-01-17 00:34:54 +01:00
|
|
|
* functionality. It passes through list methods to the underlying list
|
2011-05-02 10:12:39 +02:00
|
|
|
* implementation.
|
2011-04-01 06:09:48 +02:00
|
|
|
*
|
|
|
|
* @package sapphire
|
|
|
|
* @subpackage model
|
|
|
|
*/
|
2012-03-09 02:28:14 +01:00
|
|
|
abstract class SS_ListDecorator extends ViewableData implements SS_List, SS_Sortable, SS_Filterable, SS_Limitable {
|
2011-04-01 06:09:48 +02:00
|
|
|
|
|
|
|
protected $list;
|
|
|
|
|
2011-05-02 10:12:39 +02:00
|
|
|
public function __construct(SS_List $list) {
|
|
|
|
$this->list = $list;
|
|
|
|
$this->failover = $this->list;
|
|
|
|
|
2011-04-01 06:09:48 +02:00
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the list this decorator wraps around.
|
|
|
|
*
|
2011-05-02 10:12:39 +02:00
|
|
|
* @return SS_List
|
2011-04-01 06:09:48 +02:00
|
|
|
*/
|
|
|
|
public function getList() {
|
|
|
|
return $this->list;
|
|
|
|
}
|
|
|
|
|
|
|
|
// PROXIED METHODS ---------------------------------------------------------
|
|
|
|
|
|
|
|
public function offsetExists($key) {
|
|
|
|
return $this->list->offsetExists($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function offsetGet($key) {
|
|
|
|
return $this->list->offsetGet($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function offsetSet($key, $value) {
|
|
|
|
$this->list->offsetSet($key, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function offsetUnset($key) {
|
|
|
|
$this->list->offsetUnset($key);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toArray($index = null) {
|
|
|
|
return $this->list->toArray($index);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function toNestedArray($index = null){
|
|
|
|
return $this->list->toNestedArray($index);
|
|
|
|
}
|
|
|
|
|
2011-05-02 10:12:39 +02:00
|
|
|
public function add($item) {
|
|
|
|
$this->list->add($item);
|
2011-04-01 06:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function remove($itemObject) {
|
|
|
|
$this->list->remove($itemObject);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getIterator() {
|
|
|
|
return $this->list->getIterator();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function exists() {
|
|
|
|
return $this->list->exists();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function First() {
|
|
|
|
return $this->list->First();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Last() {
|
|
|
|
return $this->list->Last();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function TotalItems() {
|
|
|
|
return $this->list->TotalItems();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function Count() {
|
|
|
|
return $this->list->Count();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function forTemplate() {
|
|
|
|
return $this->list->forTemplate();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function map($index = 'ID', $titleField = 'Title', $emptyString = null, $sort = false) {
|
|
|
|
return $this->list->map($index, $titleField, $emptyString, $sort);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function find($key, $value) {
|
|
|
|
return $this->list->find($key, $value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function column($value = 'ID') {
|
|
|
|
return $this->list->column($value);
|
|
|
|
}
|
|
|
|
|
2011-05-02 10:12:39 +02:00
|
|
|
public function canSortBy($by) {
|
|
|
|
return $this->list->canSortBy($by);
|
2011-04-01 06:09:48 +02:00
|
|
|
}
|
2012-01-17 00:34:54 +01:00
|
|
|
|
2011-12-08 22:08:46 +01:00
|
|
|
/**
|
|
|
|
* Sorts this list by one or more fields. You can either pass in a single
|
|
|
|
* field name and direction, or a map of field names to sort directions.
|
|
|
|
*
|
|
|
|
* @example $list->sort('Name'); // default ASC sorting
|
|
|
|
* @example $list->sort('Name DESC'); // DESC sorting
|
|
|
|
* @example $list->sort('Name', 'ASC');
|
|
|
|
* @example $list->sort(array('Name'=>'ASC,'Age'=>'DESC'));
|
|
|
|
*/
|
|
|
|
public function sort() {
|
|
|
|
$args = func_get_args();
|
2012-01-17 00:34:54 +01:00
|
|
|
return call_user_func_array(array($this->list, 'sort'), $args);
|
2011-12-08 22:08:46 +01:00
|
|
|
}
|
2012-01-17 00:34:54 +01:00
|
|
|
|
2012-03-09 02:26:27 +01:00
|
|
|
public function canFilterBy($by) {
|
|
|
|
return $this->list->canFilterBy($by);
|
|
|
|
}
|
|
|
|
|
2011-12-08 22:08:46 +01:00
|
|
|
/**
|
|
|
|
* Filter the list to include items with these charactaristics
|
2012-01-17 00:34:54 +01:00
|
|
|
*
|
2011-12-08 22:08:46 +01:00
|
|
|
* @example $list->filter('Name', 'bob'); // only bob in list
|
|
|
|
* @example $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
|
|
|
|
* @example $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob or someone with Age 21
|
2012-01-17 00:34:54 +01:00
|
|
|
* @example $list->filter(array('Name'=>'bob, 'Age'=>array(21, 43))); // bob or anyone with Age 21 or 43
|
2011-12-08 22:08:46 +01:00
|
|
|
*/
|
|
|
|
public function filter(){
|
|
|
|
$args = func_get_args();
|
2012-01-17 00:34:54 +01:00
|
|
|
return call_user_func_array(array($this->list, 'filter'), $args);
|
2011-12-08 22:08:46 +01:00
|
|
|
}
|
2012-01-17 00:34:54 +01:00
|
|
|
|
2012-03-09 03:28:11 +01:00
|
|
|
public function limit($limit, $offset = 0) {
|
2012-03-09 05:50:32 +01:00
|
|
|
return $this->list->limit($limit, $offset);
|
2012-03-09 02:02:37 +01:00
|
|
|
}
|
|
|
|
|
2011-12-08 22:08:46 +01:00
|
|
|
/**
|
|
|
|
* Exclude the list to not contain items with these charactaristics
|
|
|
|
*
|
|
|
|
* @example $list->exclude('Name', 'bob'); // exclude bob from list
|
|
|
|
* @example $list->exclude('Name', array('aziz', 'bob'); // exclude aziz and bob from list
|
|
|
|
* @example $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob or someone with Age 21
|
|
|
|
* @example $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob or anyone with Age 21 or 43
|
|
|
|
*/
|
|
|
|
public function exclude(){
|
|
|
|
$args = func_get_args();
|
2012-01-17 00:34:54 +01:00
|
|
|
return call_user_func_array(array($this->list, 'exclude'), $args);
|
2011-04-01 06:09:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function debug() {
|
|
|
|
return $this->list->debug();
|
|
|
|
}
|
|
|
|
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|