From f000a47813ca94766aab727893bf7a2985a22058 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Fri, 9 Mar 2012 14:26:27 +1300 Subject: [PATCH] API CHANGE: Added SS_Filterable, an extra interface to apply to lists. --- model/ArrayList.php | 2 +- model/DataList.php | 2 +- model/Filterable.php | 40 ++++++++++++++++++++++++++++++++++++++++ model/List.php | 41 ----------------------------------------- model/ListDecorator.php | 6 +++++- 5 files changed, 47 insertions(+), 44 deletions(-) create mode 100644 model/Filterable.php diff --git a/model/ArrayList.php b/model/ArrayList.php index 14f01c4b5..1de211f40 100644 --- a/model/ArrayList.php +++ b/model/ArrayList.php @@ -5,7 +5,7 @@ * @package sapphire * @subpackage model */ -class ArrayList extends ViewableData implements SS_List, SS_Limitable { +class ArrayList extends ViewableData implements SS_List, SS_Filterable, SS_Limitable { /** * Holds the items in the list diff --git a/model/DataList.php b/model/DataList.php index 7ca91002d..bb9e2bfa4 100644 --- a/model/DataList.php +++ b/model/DataList.php @@ -6,7 +6,7 @@ * @package sapphire * @subpackage model */ -class DataList extends ViewableData implements SS_List, SS_Limitable { +class DataList extends ViewableData implements SS_List, SS_Filterable, SS_Limitable { /** * The DataObject class name that this data list is querying * diff --git a/model/Filterable.php b/model/Filterable.php new file mode 100644 index 000000000..5fcdda99b --- /dev/null +++ b/model/Filterable.php @@ -0,0 +1,40 @@ +filter('Name', 'bob'); // only bob in the list + * @example $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list + * @example $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob with the age 21 + * @example $list->filter(array('Name'=>'bob, 'Age'=>array(21, 43))); // bob with the Age 21 or 43 + * @example $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43))); // aziz with the age 21 or 43 and bob with the Age 21 or 43 + */ + public function filter(); + + /** + * 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 that has Age 21 + * @example $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43 + * @example $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43))); // bob age 21 or 43, phil age 21 or 43 would be excluded + */ + public function exclude(); + +} \ No newline at end of file diff --git a/model/List.php b/model/List.php index 5d2b0d176..970c8a23c 100644 --- a/model/List.php +++ b/model/List.php @@ -78,45 +78,4 @@ interface SS_List extends ArrayAccess, Countable, IteratorAggregate { */ public function column($colName = "ID"); - /** - * Returns TRUE if the list can be sorted by a field. - * - * @param string $by - * @return bool - */ - public function canSortBy($by); - - /** - * 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(); - - /** - * Filter the list to include items with these charactaristics - * - * @example $list->filter('Name', 'bob'); // only bob in the list - * @example $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list - * @example $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob with the age 21 - * @example $list->filter(array('Name'=>'bob, 'Age'=>array(21, 43))); // bob with the Age 21 or 43 - * @example $list->filter(array('Name'=>array('aziz','bob'), 'Age'=>array(21, 43))); // aziz with the age 21 or 43 and bob with the Age 21 or 43 - */ - public function filter(); - - /** - * 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 that has Age 21 - * @example $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43 - * @example $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43))); // bob age 21 or 43, phil age 21 or 43 would be excluded - */ - public function exclude(); - } \ No newline at end of file diff --git a/model/ListDecorator.php b/model/ListDecorator.php index 1cd1d47c8..46efb202b 100644 --- a/model/ListDecorator.php +++ b/model/ListDecorator.php @@ -7,7 +7,7 @@ * @package sapphire * @subpackage model */ -abstract class SS_ListDecorator extends ViewableData implements SS_List, S_Limitable { +abstract class SS_ListDecorator extends ViewableData implements SS_List, SS_Filterable, SS_Limitable { protected $list; @@ -119,6 +119,10 @@ abstract class SS_ListDecorator extends ViewableData implements SS_List, S_Limit return call_user_func_array(array($this->list, 'sort'), $args); } + public function canFilterBy($by) { + return $this->list->canFilterBy($by); + } + /** * Filter the list to include items with these charactaristics *