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
|
|
|
|
*
|
2012-03-09 02:26:27 +01:00
|
|
|
* @see SS_List, SS_Sortable, SS_Limitable
|
2013-11-29 05:12:47 +01:00
|
|
|
* @package framework
|
2016-06-15 06:03:16 +02:00
|
|
|
* @subpackage orm
|
2012-03-09 02:26:27 +01:00
|
|
|
*/
|
2014-07-30 01:07:01 +02:00
|
|
|
interface SS_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
|
|
|
|
*
|
|
|
|
* @return SS_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
|
|
|
|
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
|
|
|
*
|
2012-12-12 05:22:45 +01:00
|
|
|
* @return SS_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; })
|
|
|
|
* @return SS_Filterable
|
|
|
|
*/
|
|
|
|
public function filterByCallback($callback);
|
2012-03-24 04:04:52 +01:00
|
|
|
}
|