Beispiel #1
0
 public function pagination($nbProducts = 10)
 {
     if (!self::$initialized) {
         $this->init();
     }
     $nArray = Configuration::get('PS_PRODUCTS_PER_PAGE') != 10 ? array((int) Configuration::get('PS_PRODUCTS_PER_PAGE'), 10, 20, 50) : array(10, 20, 50);
     // Clean duplicate values
     $nArray = array_unique($nArray);
     asort($nArray);
     $this->n = abs((int) Tools::getValue('n', isset(self::$cookie->nb_item_per_page) && self::$cookie->nb_item_per_page >= 10 ? self::$cookie->nb_item_per_page : (int) Configuration::get('PS_PRODUCTS_PER_PAGE')));
     $this->p = abs((int) Tools::getValue('p', 1));
     if (!is_numeric(Tools::getValue('p', 1)) || Tools::getValue('p', 1) < 0) {
         Tools::redirect('404.php');
     }
     $current_url = tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']);
     //delete parameter page
     $current_url = preg_replace('/(\\?)?(&amp;)?p=\\d+/', '$1', $current_url);
     $range = 5;
     /* how many pages around page selected原值2改为更大值,但仍存在诸多问题 */
     if ($this->p < 0) {
         $this->p = 0;
     }
     if (isset(self::$cookie->nb_item_per_page) && $this->n != self::$cookie->nb_item_per_page && in_array($this->n, $nArray)) {
         self::$cookie->nb_item_per_page = $this->n;
     }
     if ($this->p > $nbProducts / $this->n + 1) {
         Tools::redirect(preg_replace('/[&?]p=\\d+/', '', $_SERVER['REQUEST_URI']));
     }
     $pages_nb = ceil($nbProducts / (int) $this->n);
     $start = (int) ($this->p - $range);
     if ($start < 1) {
         $start = 1;
     }
     $stop = (int) ($this->p + $range);
     if ($stop > $pages_nb) {
         $stop = (int) $pages_nb;
     }
     self::$smarty->assign('nb_products', $nbProducts);
     $pagination_infos = array('products_per_page' => (int) Configuration::get('PS_PRODUCTS_PER_PAGE'), 'pages_nb' => $pages_nb, 'p' => $this->p, 'n' => $this->n, 'nArray' => $nArray, 'range' => $range, 'start' => $start, 'stop' => $stop, 'current_url' => $current_url);
     self::$smarty->assign($pagination_infos);
 }
Beispiel #2
0
 public function assignPagination($limit, $nbPosts)
 {
     $this->n = $limit;
     $this->p = abs((int) Tools::getValue('p', 1));
     $current_url = tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']);
     //delete parameter page
     $current_url = preg_replace('/(\\?)?(&amp;)?p=\\d+/', '$1', $current_url);
     $range = 2;
     /* how many pages around page selected */
     if ($this->p < 1) {
         $this->p = 1;
     }
     $pages_nb = ceil($nbPosts / (int) $this->n);
     $start = (int) ($this->p - $range);
     if ($start < 1) {
         $start = 1;
     }
     $stop = (int) ($this->p + $range);
     if ($stop > $pages_nb) {
         $stop = (int) $pages_nb;
     }
     $this->context->smarty->assign('nb_posts', $nbPosts);
     $pagination_infos = array('products_per_page' => $limit, 'pages_nb' => $pages_nb, 'p' => $this->p, 'n' => $this->n, 'range' => $range, 'start' => $start, 'stop' => $stop, 'current_url' => $current_url);
     $this->context->smarty->assign($pagination_infos);
 }
 public function pagination($nbProducts = 10)
 {
     if (!self::$initialized) {
         $this->init();
     }
     $nArray = (int) Configuration::get('TAS_ITEMS_PER_PAGE') != 20 ? array((int) Configuration::get('TAS_ITEMS_PER_PAGE'), 20) : array(20);
     // Clean duplicate values
     $nArray = array_unique($nArray);
     asort($nArray);
     $this->n = abs((int) Tools::getValue('n', (isset(self::$cookie->nb_item_per_page) and self::$cookie->nb_item_per_page >= 20) ? self::$cookie->nb_item_per_page : (int) Configuration::get('TAS_ITEMS_PER_PAGE')));
     $this->p = abs((int) Tools::getValue('p', 1));
     $current_url = tools::htmlentitiesUTF8($_SERVER['REQUEST_URI']);
     //delete parameter page
     $current_url = preg_replace('/(\\?)?(&amp;)?p=\\d+/', '$1', $current_url);
     $range = 2;
     /* how many pages around page selected */
     if ($this->p < 0) {
         $this->p = 0;
     }
     if (isset(self::$cookie->nb_item_per_page) and $this->n != self::$cookie->nb_item_per_page and in_array($this->n, $nArray)) {
         self::$cookie->nb_item_per_page = $this->n;
     }
     if ($this->p > $nbProducts / $this->n + 1) {
         $this->p = 1;
     }
     $pages_nb = ceil($nbProducts / (int) $this->n);
     $start = (int) ($this->p - $range);
     if ($start < 1) {
         $start = 1;
     }
     $stop = (int) ($this->p + $range);
     if ($stop > $pages_nb) {
         $stop = (int) $pages_nb;
     }
     self::$smarty->assign('nb_products', $nbProducts);
     $pagination_infos = array('products_per_page' => (int) Configuration::get('TAS_ITEMS_PER_PAGE'), 'pages_nb' => $pages_nb, 'p' => $this->p, 'n' => $this->n, 'nArray' => $nArray, 'range' => $range, 'start' => $start, 'stop' => $stop, 'current_url' => $current_url);
     self::$smarty->assign($pagination_infos);
 }