X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;ds=sidebyside;f=classes%2Fplset.php;h=baac0728522934dae287cd9a9b77887f516892c9;hb=54d6549cad8056b1f0656b2d8fc83a853631758e;hp=ced255911ceb351fffb932b13907647affe3ab73;hpb=4c27b6a2f30e59b046bdc2534135741e3fae0016;p=platal.git diff --git a/classes/plset.php b/classes/plset.php index ced2559..baac072 100644 --- a/classes/plset.php +++ b/classes/plset.php @@ -26,9 +26,9 @@ abstract class PlSet { const DEFAULT_MAX_RES = 20; - private $conds = null; - private $orders = null; - private $limit = null; + protected $conds = null; + protected $orders = array(); + protected $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());