From 24bb393609c4e87e8578ddaca906c32d99a299bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Fri, 5 Feb 2010 16:36:06 +0100 Subject: [PATCH] Fixes PlSet (orders weren't working) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Raphaël Barrois --- classes/plset.php | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/classes/plset.php b/classes/plset.php index ced2559..13628c1 100644 --- a/classes/plset.php +++ b/classes/plset.php @@ -27,7 +27,7 @@ abstract class PlSet const DEFAULT_MAX_RES = 20; private $conds = null; - private $orders = null; + private $orders = array(); private $limit = null; protected $count = null; @@ -37,7 +37,7 @@ abstract class PlSet private $mod = null; private $default = null; - public function __construct(PlFilterCondition &$cond, $orders) + public function __construct(PlFilterCondition &$cond, $orders = null) { if ($cond instanceof PFC_And) { $this->conds = $cond; @@ -45,11 +45,11 @@ abstract class PlSet $this->conds = new PFC_And($cond); } - if ($orders instanceof PlFilterOrder) { - $this->orders[] = $order; - } else { + if (!is_null($orders) && $orders instanceof PlFilterOrder) { + $this->addSort($orders); + } else if (is_array($orders)){ foreach ($orders as $order) { - $this->orders[] = $order; + $this->addSort($order); } } } @@ -86,9 +86,20 @@ abstract class PlSet */ abstract protected function buildFilter(PlFilterCondition &$cond, $orders); - public function &get(PlLimit $limit = null) + /** This function returns the values of the set + * @param $limit A PlLimit for selecting users + * @param $orders An optional array of PFO to use before the "default" ones + * @return The result of $pf->get(); + */ + public function &get(PlLimit $limit = null, $orders = array()) { - $pf = $this->buildFilter($this->conds, $this->orders); + if (!is_array($orders)) { + $orders = array($orders); + } + + $orders = array_merge($orders, $this->orders); + + $pf = $this->buildFilter($this->conds, $orders); if (is_null($limit)) { $limit = new PlLimit(self::DEFAULT_MAX_RES, 0); @@ -295,7 +306,7 @@ abstract class MultipageView implements PlView { foreach ($this->order() as $order) { if (!is_null($order)) { - $this->set->addSort($order->pfo); + $this->set->addSort($order); } } $res = $this->set->get($this->limit()); -- 2.1.4