X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplfilter.php;h=8355308a82ec04aad9995a751c8048b492a0b5a7;hb=571e48acadea9f5d2e5073fd993746ec33c369d1;hp=47abccee3185dd3cbbc58eca51381ff5ee01d035;hpb=e05c0f5486db7ffb0fbd9ca7c0b20484a93c60c5;p=platal.git diff --git a/classes/plfilter.php b/classes/plfilter.php index 47abcce..8355308 100644 --- a/classes/plfilter.php +++ b/classes/plfilter.php @@ -1,6 +1,6 @@ _tokens = null; } + protected function buildExport($type) + { + $export = array('type' => $type); + if ($this->desc) { + $export['order'] = 'desc'; + } + return $export; + } + public function export() { throw new Exception("This instance is not exportable"); @@ -77,7 +86,7 @@ abstract class PlFilterOrder implements PlExportable $this->desc = $desc; } - public function buildSort(PlFilter &$pf) + public function buildSort(PlFilter $pf) { $sel = $this->getSortTokens($pf); $this->_tokens = $sel; @@ -93,10 +102,10 @@ abstract class PlFilterOrder implements PlExportable } /** This function must return the tokens to use for ordering - * @param &$pf The PlFilter whose results must be ordered + * @param $pf The PlFilter whose results must be ordered * @return The name of the field to use for ordering results */ - abstract protected function getSortTokens(PlFilter &$pf); + abstract protected function getSortTokens(PlFilter $pf); } // }}} @@ -110,10 +119,20 @@ abstract class PlFilterGroupableOrder extends PlFilterOrder * the returned token will be used to group the values. * It will always be called AFTER getSortTokens(). */ - public function getGroupToken(PlFilter &$pf) + public function getGroupToken(PlFilter $pf) { return $this->_tokens; } + + /** This function is called when trying to restrict to one of the + * specific values of the group token. + * + * @return A PlFilterCondition. + */ + public function getCondition($group_value) + { + return null; + } } // }}} @@ -128,7 +147,7 @@ class PFO_Random extends PlFilterOrder $this->seed = $seed; } - protected function getSortTokens(PlFilter &$pf) + protected function getSortTokens(PlFilter $pf) { if ($this->seed == null) { return 'RAND()'; @@ -153,7 +172,7 @@ interface PlFilterCondition extends PlExportable const COND_TRUE = 'TRUE'; const COND_FALSE = 'FALSE'; - public function buildCondition(PlFilter &$pf); + public function buildCondition(PlFilter $pf); } // }}} @@ -162,21 +181,21 @@ abstract class PFC_OneChild implements PlFilterCondition { protected $child; - public function __construct(&$child = null) + public function __construct($child = null) { if (!is_null($child) && ($child instanceof PlFilterCondition)) { $this->setChild($child); } } - public function setChild(PlFilterCondition &$cond) + public function setChild(PlFilterCondition $cond) { - $this->child =& $cond; + $this->child = $cond; } public function export() { - return array('child' => $child->export()); + return array('child' => $this->child->export()); } } // }}} @@ -193,16 +212,16 @@ abstract class PFC_NChildren implements PlFilterCondition public function addChildren(array $conds) { - foreach ($conds as &$cond) { + foreach ($conds as $cond) { if (!is_null($cond) && ($cond instanceof PlFilterCondition)) { $this->addChild($cond); } } } - public function addChild(PlFilterCondition &$cond) + public function addChild(PlFilterCondition $cond) { - $this->children[] =& $cond; + $this->children[] = $cond; } protected function catConds(array $cond, $op, $fallback) @@ -219,8 +238,9 @@ abstract class PFC_NChildren implements PlFilterCondition public function export() { $export = array(); - foreach ($this->children as $child) + foreach ($this->children as $child) { $export[] = $child->export(); + } return array('children' => $export); } } @@ -229,7 +249,7 @@ abstract class PFC_NChildren implements PlFilterCondition // {{{ class PFC_True class PFC_True implements PlFilterCondition { - public function buildCondition(PlFilter &$uf) + public function buildCondition(PlFilter $uf) { return self::COND_TRUE; } @@ -244,7 +264,7 @@ class PFC_True implements PlFilterCondition // {{{ class PFC_False class PFC_False implements PlFilterCondition { - public function buildCondition(PlFilter &$uf) + public function buildCondition(PlFilter $uf) { return self::COND_FALSE; } @@ -259,7 +279,7 @@ class PFC_False implements PlFilterCondition // {{{ class PFC_Not class PFC_Not extends PFC_OneChild { - public function buildCondition(PlFilter &$uf) + public function buildCondition(PlFilter $uf) { $val = $this->child->buildCondition($uf); if ($val == self::COND_TRUE) { @@ -283,14 +303,14 @@ class PFC_Not extends PFC_OneChild // {{{ class PFC_And class PFC_And extends PFC_NChildren { - public function buildCondition(PlFilter &$uf) + public function buildCondition(PlFilter $uf) { if (empty($this->children)) { return self::COND_FALSE; } else { $true = self::COND_FALSE; $conds = array(); - foreach ($this->children as &$child) { + foreach ($this->children as $child) { $val = $child->buildCondition($uf); if ($val == self::COND_TRUE) { $true = self::COND_TRUE; @@ -315,14 +335,14 @@ class PFC_And extends PFC_NChildren // {{{ class PFC_Or class PFC_Or extends PFC_NChildren { - public function buildCondition(PlFilter &$uf) + public function buildCondition(PlFilter $uf) { if (empty($this->children)) { return self::COND_TRUE; } else { $true = self::COND_TRUE; $conds = array(); - foreach ($this->children as &$child) { + foreach ($this->children as $child) { $val = $child->buildCondition($uf); if ($val == self::COND_TRUE) { return self::COND_TRUE; @@ -353,9 +373,9 @@ abstract class PlFilter implements PlExportable */ public abstract function filter(array $objects, $limit = null); - public abstract function setCondition(PlFilterCondition &$cond); + public abstract function setCondition(PlFilterCondition $cond); - public abstract function addSort(PlFilterOrder &$sort); + public abstract function addSort(PlFilterOrder $sort); public abstract function getTotalCount(); @@ -374,6 +394,14 @@ abstract class PlFilter implements PlExportable */ public abstract function get($limit = null); + /** Get ids, selecting only those within a limit + * @param $limit The portion of the matching objects to select + */ + public function getIds($limit = null) + { + return $this->get($limit); + } + /** PRIVATE FUNCTIONS */