From b71b2a361a1a0c89d77a0d941ff92a410147f8dc Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sat, 12 Jul 2008 18:22:56 +0200 Subject: [PATCH] plset is not meant to know what it's dealing with, eg nom, promo... --- classes/plset.php | 37 ++++++++++++------------ include/userset.inc.php | 51 ++++++++++++++++++++++++++++++++++ templates/include/plview.multipage.tpl | 2 +- templates/include/plview.referent.tpl | 4 +-- templates/include/plview.trombi.tpl | 4 +-- 5 files changed, 75 insertions(+), 23 deletions(-) diff --git a/classes/plset.php b/classes/plset.php index 231b4d4..71bd5ee 100644 --- a/classes/plset.php +++ b/classes/plset.php @@ -200,6 +200,8 @@ abstract class MultipageView implements PlView protected $sortkeys = array(); protected $defaultkey = null; + protected $bound_field = null; + public function __construct(PlSet &$set, $data, array $params) { $this->set =& $set; @@ -223,6 +225,11 @@ abstract class MultipageView implements PlView return null; } + public function bounds() + { + return null; + } + protected function addSortKey($name, array $keys, $desc, $default = false) { $this->sortkeys[$name] = array('keys' => $keys, 'desc' => $desc); @@ -263,28 +270,22 @@ abstract class MultipageView implements PlView $this->order(), $this->entriesPerPage, $this->offset); - $order = Env::v('order', $this->defaultkey); + $show_bounds = $this->bounds(); $end = end($res); - $show_bounds = 0; - if (($order == "name") || ($order == "-name")) { - $first = $res[0]['nom']; - $last = $end['nom']; - $show_bounds = 1; - } elseif (($order == "promo") || ($order == "-promo")) { - $first = $end['promo']; - $last = $res[0]['promo']; - $show_bounds = 1; - } - if (($show_bounds) && ($order{0} == '-')) { - $aux = $first; - $first = $last; - $last = $aux; + if ($show_bounds) { + if ($show_bounds == 1) { + $first = $res[0][$this->bound_field]; + $last = $end[$this->bound_field]; + } elseif ($show_bounds == -1) { + $first = $end[$this->bound_field]; + $last = $res[0][$this->bound_field]; + } + $page->assign('first', $first); + $page->assign('last', $last); } - $page->assign('first', $first); - $page->assign('last', $last); $page->assign('show_bounds', $show_bounds); - $page->assign('order', $order); + $page->assign('order', Env::v('order', $this->defaultkey)); $page->assign('orders', $this->sortkeys); $page->assign_by_ref('plview', $this); $page->assign_by_ref('set', $res); diff --git a/include/userset.inc.php b/include/userset.inc.php index a35cded..0a4a95f 100644 --- a/include/userset.inc.php +++ b/include/userset.inc.php @@ -210,6 +210,23 @@ class MinificheView extends MultipageView : ""); } + public function bounds() + { + $order = Env::v('order', $this->defaultkey); + $show_bounds = 0; + if (($order == "name") || ($order == "-name")) { + $this->bound_field = "nom"; + $show_bounds = 1; + } elseif (($order == "promo") || ($order == "-promo")) { + $this->bound_field = "promo"; + $show_bounds = -1; + } + if ($order{0} == '-') { + $show_bounds = -$show_bounds; + } + return $show_bounds; + } + public function templateName() { return 'include/plview.minifiche.tpl'; @@ -235,6 +252,23 @@ class MentorView extends MultipageView ms.secteur, ms.ss_secteur"; } + public function bounds() + { + $order = Env::v('order', $this->defaultkey); + $show_bounds = 0; + if (($order == "name") || ($order == "-name")) { + $this->bound_field = "nom"; + $show_bounds = 1; + } elseif (($order == "promo") || ($order == "-promo")) { + $this->bound_field = "promo"; + $show_bounds = -1; + } + if ($order{0} == '-') { + $show_bounds = -$show_bounds; + } + return $show_bounds; + } + public function templateName() { return 'include/plview.referent.tpl'; @@ -265,6 +299,23 @@ class TrombiView extends MultipageView return "INNER JOIN photo AS p ON (p.uid = u.user_id) "; } + public function bounds() + { + $order = Env::v('order', $this->defaultkey); + $show_bounds = 0; + if (($order == "name") || ($order == "-name")) { + $this->bound_field = "nom"; + $show_bounds = 1; + } elseif (($order == "promo") || ($order == "-promo")) { + $this->bound_field = "promo"; + $show_bounds = -1; + } + if ($order{0} == '-') { + $show_bounds = -$show_bounds; + } + return $show_bounds; + } + public function templateName() { return 'include/plview.trombi.tpl'; diff --git a/templates/include/plview.multipage.tpl b/templates/include/plview.multipage.tpl index 854c320..4a44961 100644 --- a/templates/include/plview.multipage.tpl +++ b/templates/include/plview.multipage.tpl @@ -23,7 +23,7 @@ {capture name=pages} {if $plview->pages > 1}
- {if $show_bounds}[{$first} - {$last}]{/if} + {if $show_bounds}[{$first} - {$last}] {/if} {if $plview->page neq 1} {icon name=resultset_first title="Première page"}{* *}{icon name=resultset_previous title="Page précédente"} diff --git a/templates/include/plview.referent.tpl b/templates/include/plview.referent.tpl index 94225b4..76dce26 100644 --- a/templates/include/plview.referent.tpl +++ b/templates/include/plview.referent.tpl @@ -21,7 +21,7 @@ {**************************************************************************}
-{iterate from=$set item=p} +{foreach from=$set item=p}
{$p.nom} {$p.prenom} @@ -45,7 +45,7 @@
-{/iterate} +{/foreach}
{* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *} diff --git a/templates/include/plview.trombi.tpl b/templates/include/plview.trombi.tpl index 1015f5f..6aba566 100644 --- a/templates/include/plview.trombi.tpl +++ b/templates/include/plview.trombi.tpl @@ -26,7 +26,7 @@

{else} - {iterate from=$set item=p} + {foreach from=$set item=p} {cycle values="1,2,3" assign="loop"} {if $loop eq "1"} @@ -46,7 +46,7 @@ {if $loop eq "3"} {/if} - {/iterate} + {/foreach} {if $loop neq "3"} {if $lopp eq "1"} -- 2.1.4