mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
API CHANGE: Added SS_Filterable, an extra interface to apply to lists.
This commit is contained in:
parent
a55e06f6b5
commit
f000a47813
@ -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
|
||||
|
@ -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
|
||||
*
|
||||
|
40
model/Filterable.php
Normal file
40
model/Filterable.php
Normal file
@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Additional interface for {@link SS_List} classes that are filterable.
|
||||
*
|
||||
* @see SS_List, SS_Sortable, SS_Limitable
|
||||
*/
|
||||
interface SS_Filterable {
|
||||
|
||||
/**
|
||||
* Returns TRUE if the list can be filtered by a given field expression.
|
||||
*
|
||||
* @param string $by
|
||||
* @return bool
|
||||
*/
|
||||
public function canFilterBy($by);
|
||||
|
||||
/**
|
||||
* 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();
|
||||
|
||||
}
|
@ -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();
|
||||
|
||||
}
|
@ -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
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user