X-Git-Url: http://git.polytechnique.org/?a=blobdiff_plain;f=classes%2Fplset.php;h=1c29af20bd087ad1f55a89e918e3ac26ec3cd500;hb=f992b7a5586a214d1704c9e74b7d1299e2c87a03;hp=93afc3f98bb460f4f66f77ec360aca17aa181d35;hpb=9a122520bc4c6547f6506a0cd35e49737809b1c4;p=platal.git diff --git a/classes/plset.php b/classes/plset.php index 93afc3f..1c29af2 100644 --- a/classes/plset.php +++ b/classes/plset.php @@ -1,6 +1,6 @@ conds = $cond; @@ -43,11 +45,11 @@ abstract class PlSet $this->conds = new PFC_And($cond); } - if ($orders instanceof PlFilterOrder) { - $this->orders = array($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); } } } @@ -84,14 +86,37 @@ abstract class PlSet */ abstract protected function buildFilter(PlFilterCondition &$cond, $orders); - public function &get(PlLimit $limit = null) + /** This function returns the results of the given filter + * wihtin $limit ; available when the PlFilter getter isn't the usual get + * @param &$pf The filter + * @param $limit The PlLimit + * @return The results of the filter + */ + protected function &getFilterResults(PlFilter &$pf, PlLimit $limit) { - $pf = $this->buildFilter($this->conds, $this->orders); + $res = $pf->get($limit); + return $res; + } + + /** 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()) + { + 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(20, 0); + $limit = new PlLimit(self::DEFAULT_MAX_RES, 0); } - $it = $pf->get($limit); + $it = $this->getFilterResults($pf, $limit); $this->count = $pf->getTotalCount(); return $it; } @@ -181,24 +206,24 @@ interface PlView */ class PlViewOrder { - public $pfo = null; + public $pfos = null; public $name = null; public $displaytext = null; /** Build a PlViewOrder * @param $name Name of the order (key) * @param $displaytext Text to display - * @param $pfo PlFilterOrder for the order + * @param $pfos Array of PlFilterOrder for the order */ - public function __construct($name, PlFilterOrder &$pfo, $displaytext = null) + public function __construct($name, $pfos, $displaytext = null) { - $this->name = $name; + $this->name = $name; if (is_null($displaytext)) { $this->displaytext = ucfirst($name); } else { - $this->displaytext = $displaytext; + $this->displaytext = $displaytext; } - $this->pfo = $pfo; + $this->pfos = $pfos; } } @@ -241,7 +266,7 @@ abstract class MultipageView implements PlView } } - /** Returns a list of PFO objects, the "default" one first + /** Returns a list of PFO objects in accordance with the user's choice */ public function order() { @@ -250,22 +275,14 @@ abstract class MultipageView implements PlView if ($invert) { $order = substr($order, 1); } - $list = array(); - if (count($this->sortkeys)) { - $list[0] = null; - } - foreach ($this->sortkeys as $name => $sort) { - $desc = $sort->pfo->isDescending();; - if ($invert) { - $sort->pfo->toggleDesc(); - } - if ($name == $order) { - $list[0] = $sort->pfo; - } else { - $list[] = $sort->pfo; + + $ordering = $this->sortkeys[$order]; + if ($invert) { + foreach ($ordering->pfos as $pfo) { + $pfo->toggleDesc(); } } - return $list; + return $ordering->pfos; } /** Returns information on the order of bounds @@ -280,7 +297,7 @@ abstract class MultipageView implements PlView public function limit() { - return null; + return new PlLimit($this->entriesPerPage, $this->offset); } /** Name of the template to use for displaying items of the view @@ -290,6 +307,7 @@ abstract class MultipageView implements PlView /** Returns the value of a boundary of the current view (in order * to show "from C to F") * @param $obj The boundary result whose value must be shown to the user + * @return The bound */ abstract protected function getBoundValue($obj); @@ -299,19 +317,22 @@ abstract class MultipageView implements PlView public function apply(PlPage &$page) { foreach ($this->order() as $order) { - $this->set->addSort($order->pfo); + if (!is_null($order)) { + $this->set->addSort($order); + } } $res = $this->set->get($this->limit()); $show_bounds = $this->bounds(); - $end = end($res); if ($show_bounds) { + $start = current($res); + $end = end($res); if ($show_bounds == 1) { - $first = $this->getBoundValue($res[0]); + $first = $this->getBoundValue($start); $last = $this->getBoundValue($end); } elseif ($show_bounds == -1) { $first = $this->getBoundValue($end); - $last = $this->getBoundValue($res[0]); + $last = $this->getBoundValue($start); } $page->assign('first', $first); $page->assign('last', $last); @@ -321,6 +342,9 @@ abstract class MultipageView implements PlView $page->assign('order', Env::v('order', $this->defaultkey)); $page->assign('orders', $this->sortkeys); $page->assign_by_ref('plview', $this); + if (is_array($res)) { + $page->assign('set_keys', array_keys($res)); + } $page->assign_by_ref('set', $res); $count = $this->set->count(); $this->pages = intval(ceil($count / $this->entriesPerPage));