plset is not meant to know what it's dealing with, eg nom, promo...
authorStéphane Jacob <jacou@melix.net>
Sat, 12 Jul 2008 16:22:56 +0000 (18:22 +0200)
committerStéphane Jacob <jacou@melix.net>
Sat, 12 Jul 2008 16:53:34 +0000 (18:53 +0200)
classes/plset.php
include/userset.inc.php
templates/include/plview.multipage.tpl
templates/include/plview.referent.tpl
templates/include/plview.trombi.tpl

index 231b4d4..71bd5ee 100644 (file)
@@ -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);
index a35cded..0a4a95f 100644 (file)
@@ -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';
index 854c320..4a44961 100644 (file)
@@ -23,7 +23,7 @@
 {capture name=pages}
 {if $plview->pages > 1}
 <div class="center pages">
-  {if $show_bounds}[{$first} - {$last}]{/if}
+  {if $show_bounds}<small><strong>[{$first} - {$last}]&nbsp;</strong></small>{/if}
   {if $plview->page neq 1}
   <a href="{$platal->pl_self()}{$plset_search}order={$order}&amp;page=1">{icon name=resultset_first title="Première page"}</a>{*
   *}<a href="{$platal->pl_self()}{$plset_search}order={$order}&amp;page={$plview->page-1}">{icon name=resultset_previous title="Page précédente"}</a>
index 94225b4..76dce26 100644 (file)
@@ -21,7 +21,7 @@
 {**************************************************************************}
 
 <div class="contact-list" style="clear: both">
-{iterate from=$set item=p} 
+{foreach from=$set item=p} 
   <div class="contact"> 
     <div class="nom"> 
       {$p.nom} {$p.prenom} 
@@ -45,7 +45,7 @@
      </table> 
     </div> 
   </div> 
-{/iterate}
+{/foreach}
 </div>
 
 {* vim:set et sw=2 sts=2 sws=2 enc=utf-8: *}
index 1015f5f..6aba566 100644 (file)
@@ -26,7 +26,7 @@
 </p>
 {else}
 <table cellpadding="8" cellspacing="2" style="width: 100%">
-  {iterate from=$set item=p}
+  {foreach from=$set item=p}
   {cycle values="1,2,3" assign="loop"}
   {if $loop eq "1"}
   <tr>
@@ -46,7 +46,7 @@
   {if $loop eq "3"}
   </tr>
   {/if}
-  {/iterate}
+  {/foreach}
   {if $loop neq "3"}
   {if $lopp eq "1"}
   <td></td>