* @copyright 2007-2015 Orange35 * @license http://creativecommons.org/licenses/by-nc-sa/3.0/ */ require_once(dirname(__FILE__).'/../../homefeaturedpaginated.php'); class HomefeaturedpaginatedPaginationModuleFrontController extends FrontController { public function pagination($total_products = null) { if (!self::$initialized) $this->init(); elseif (!$this->context) $this->context = Context::getContext(); // Retrieve the default number of products per page and the other available selections $default_products_per_page = max(1, (int)Configuration::get(HomeFeaturedPaginated::PS_IPP)); $n_array = array($default_products_per_page, $default_products_per_page * 2, $default_products_per_page * 5); if ((int)Tools::getValue('n') && (int)$total_products > 0) $n_array[] = $total_products; $this->n = $default_products_per_page; // Retrieve the page number (either the GET parameter or the first page) $this->p = (int)Tools::getValue('p', 1); // If the parameter is not correct then redirect (do not merge with the previous line, the redirect is required in order to avoid duplicate content) if (!is_numeric($this->p) || $this->p < 1) Tools::redirect(self::$link->getPaginationLink(false, false, $this->n, false, 1, false)); // Remove the page parameter in order to get a clean URL for the pagination template $current_url = preg_replace('/(\?)?(&)?p=\d+/', '$1', Tools::htmlentitiesUTF8($_SERVER['REQUEST_URI'])); if ($this->n != $default_products_per_page || isset($this->context->cookie->nb_item_per_page)) $this->context->cookie->nb_item_per_page = $this->n; $pages_nb = ceil($total_products / (int)$this->n); if ($this->p > $pages_nb && $total_products != 0) Tools::redirect(self::$link->getPaginationLink(false, false, $this->n, false, $pages_nb, false)); $range = 2; /* how many pages around page selected */ $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(array( 'nb_products' => $total_products, 'products_per_page' => $this->n, 'pages_nb' => $pages_nb, 'p' => $this->p, 'n' => $this->n, 'nArray' => $n_array, 'range' => $range, 'start' => $start, 'stop' => $stop, 'current_url' => $current_url )); } }