]> git.nbdom.net Git - nb.git/commitdiff
lib/php/db/table.php
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 20 Jun 2018 02:36:44 +0000 (03:36 +0100)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 20 Jun 2018 02:36:44 +0000 (03:36 +0100)
lib/php/db/table.php

index d3b848ba7a285afae3b70961c409ed8e73b56276..3bbb5996ae2b4f2581d7bbc7a2dd7c91089bc06d 100644 (file)
@@ -710,15 +710,19 @@ Class Table extends nb {
 
        }
 
+       private function splitLimit($limit) {
+               return strpos($limit,',')!==false
+                       ? preg_split('/\s*,\s*/',$limit)
+                       : [0,$limit]
+               ;
+       }
+
        public function nav($count,$tot,$limit) {
 
                $html = '';
 
                if ($count<$tot) {
-                       list($x,$y) = strpos($limit,',')!==false
-                               ? preg_split('/\s*,\s*/',$limit)
-                               : [0,$limit]
-                       ;
+                       list($x,$y) = $this->splitLimit($limit);
 
                        $prev = $x - $y;
                        $next = $x + $y;
@@ -734,7 +738,7 @@ Class Table extends nb {
 
                if ($prev>=0) $html .= '<span class="prev"><a href="'.$this->url_list('limit',preg_replace('/^0,/','',"$prev,$y")).'">&lt;&lt;</a></span>&nbsp;';
 
-               $html .= '<span class="count">'.($tot ? ($x+1) : 0).' - '.( $count<($x+$y) ? $count : ($x+$y) ).' / '.$tot.'</span>';
+               $html .= '<span class="count">'.($tot ? ($x+1) : 0).' - '.( $tot<($x+$y) ? $tot : ($x+$y) ).' / '.$tot.'</span>';
 
                if ($next<$tot) $html .= '&nbsp;<span class="prev"><a href="'.$this->url_list('limit',"$next,$y").'">&gt;&gt;</a></span>';
 
@@ -993,10 +997,8 @@ Class Table extends nb {
 
                        if ($this->p('orderby') and !$count) $sql .= ' ORDER BY '.$this->p('orderby');
 
-                       if ($_limit = $limit = $this->db()->limit) {
-                               $_limit = str_replace(' OFFSET ',',',$_limit);
-                               $_limit = str_replace(',',' OFFSET ',$_limit);
-                               $sql .= ' LIMIT '.$_limit;
+                       if ($limit = $this->db()->limit) {
+                               $sql .= ' LIMIT ' . join(' OFFSET ',array_reverse($this->splitLimit($limit)));
                        } else {
                                $limit = '';
                        }
@@ -1433,9 +1435,7 @@ Class Table extends nb {
                        'total_pages' => ceil($this->tot / $limit) // calculate pages count
                ]);
 
-               #$this->_html_table->display_tablenav('top');
                $this->_html_table->display();
-               #$this->_html_table->display_tablenav('bottom');
                unset($this->_html_table);
                return '';
        }