2012-03-09 02:26:27 +01:00
|
|
|
<?php
|
|
|
|
|
2016-06-15 06:03:16 +02:00
|
|
|
namespace SilverStripe\ORM;
|
|
|
|
|
2012-03-09 02:26:27 +01:00
|
|
|
/**
|
|
|
|
* Additional interface for {@link SS_List} classes that are filterable.
|
2012-07-20 04:51:12 +02:00
|
|
|
*
|
|
|
|
* All methods in this interface are immutable - they should return new instances with the filter
|
|
|
|
* applied, rather than applying the filter in place
|
|
|
|
*
|
2016-09-09 08:43:05 +02:00
|
|
|
* @see SS_List, Sortable, Limitable
|
2012-03-09 02:26:27 +01:00
|
|
|
*/
|
2016-09-09 08:43:05 +02:00
|
|
|
interface Filterable extends SS_List {
|
2012-03-09 02:26:27 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns TRUE if the list can be filtered by a given field expression.
|
|
|
|
*
|
|
|
|
* @param string $by
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function canFilterBy($by);
|
2014-07-30 01:07:01 +02:00
|
|
|
|
2012-03-09 02:26:27 +01:00
|
|
|
/**
|
2012-12-12 05:22:45 +01:00
|
|
|
* Return a new instance of this list that only includes items with these charactaristics
|
|
|
|
*
|
2016-09-09 08:43:05 +02:00
|
|
|
* @return Filterable
|
2012-07-20 04:51:12 +02:00
|
|
|
* @example $list = $list->filter('Name', 'bob'); // only bob in the list
|
|
|
|
* @example $list = $list->filter('Name', array('aziz', 'bob'); // aziz and bob in list
|
|
|
|
* @example $list = $list->filter(array('Name'=>'bob, 'Age'=>21)); // bob with the age 21
|
|
|
|
* @example $list = $list->filter(array('Name'=>'bob, 'Age'=>array(21, 43))); // bob with the Age 21 or 43
|
2012-09-26 23:34:00 +02:00
|
|
|
* @example $list = $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
|
2012-03-09 02:26:27 +01:00
|
|
|
*/
|
|
|
|
public function filter();
|
2013-10-30 14:08:55 +01:00
|
|
|
|
2015-08-28 17:55:23 +02:00
|
|
|
/**
|
|
|
|
* Return a copy of this list which contains items matching any of these charactaristics.
|
|
|
|
*
|
|
|
|
* @example // only bob in the list
|
|
|
|
* $list = $list->filterAny('Name', 'bob');
|
|
|
|
* // SQL: WHERE "Name" = 'bob'
|
|
|
|
* @example // azis or bob in the list
|
|
|
|
* $list = $list->filterAny('Name', array('aziz', 'bob');
|
|
|
|
* // SQL: WHERE ("Name" IN ('aziz','bob'))
|
|
|
|
* @example // bob or anyone aged 21 in the list
|
|
|
|
* $list = $list->filterAny(array('Name'=>'bob, 'Age'=>21));
|
|
|
|
* // SQL: WHERE ("Name" = 'bob' OR "Age" = '21')
|
|
|
|
* @example // bob or anyone aged 21 or 43 in the list
|
|
|
|
* $list = $list->filterAny(array('Name'=>'bob, 'Age'=>array(21, 43)));
|
|
|
|
* // SQL: WHERE ("Name" = 'bob' OR ("Age" IN ('21', '43'))
|
|
|
|
* @example // all bobs, phils or anyone aged 21 or 43 in the list
|
|
|
|
* $list = $list->filterAny(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
|
|
|
|
* // SQL: WHERE (("Name" IN ('bob', 'phil')) OR ("Age" IN ('21', '43'))
|
|
|
|
*
|
|
|
|
* @param string|array See {@link filter()}
|
2016-08-19 00:51:35 +02:00
|
|
|
* @return static
|
2015-08-28 17:55:23 +02:00
|
|
|
*/
|
|
|
|
public function filterAny();
|
|
|
|
|
2012-03-09 02:26:27 +01:00
|
|
|
/**
|
2012-12-12 05:22:45 +01:00
|
|
|
* Return a new instance of this list that excludes any items with these charactaristics
|
2012-03-09 02:26:27 +01:00
|
|
|
*
|
2016-09-09 08:43:05 +02:00
|
|
|
* @return Filterable
|
2012-07-20 04:51:12 +02:00
|
|
|
* @example $list = $list->exclude('Name', 'bob'); // exclude bob from list
|
|
|
|
* @example $list = $list->exclude('Name', array('aziz', 'bob'); // exclude aziz and bob from list
|
|
|
|
* @example $list = $list->exclude(array('Name'=>'bob, 'Age'=>21)); // exclude bob that has Age 21
|
|
|
|
* @example $list = $list->exclude(array('Name'=>'bob, 'Age'=>array(21, 43))); // exclude bob with Age 21 or 43
|
2012-09-26 23:34:00 +02:00
|
|
|
* @example $list = $list->exclude(array('Name'=>array('bob','phil'), 'Age'=>array(21, 43)));
|
|
|
|
* // bob age 21 or 43, phil age 21 or 43 would be excluded
|
2012-03-09 02:26:27 +01:00
|
|
|
*/
|
|
|
|
public function exclude();
|
2013-10-30 14:08:55 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a new instance of this list that excludes any items with these charactaristics
|
|
|
|
* Filter this List by a callback function. The function will be passed each record of the List in turn,
|
|
|
|
* and must return true for the record to be included. Returns the filtered list.
|
|
|
|
*
|
|
|
|
* @example $list = $list->filterByCallback(function($item, $list) { return $item->Age == 9; })
|
2016-08-19 00:51:35 +02:00
|
|
|
* @param callable $callback
|
2016-09-09 08:43:05 +02:00
|
|
|
* @return Filterable
|
2013-10-30 14:08:55 +01:00
|
|
|
*/
|
|
|
|
public function filterByCallback($callback);
|
2015-08-28 17:55:23 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the first item with the given ID
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function byID($id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter this list to only contain the given Primary IDs
|
|
|
|
*
|
|
|
|
* @param array $ids Array of integers
|
|
|
|
* @return SS_List
|
|
|
|
*/
|
|
|
|
public function byIDs($ids);
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|