limits = $limits; } else { $this->limits = array(10); } $this->limit = ($limit > 0) ? $limit : $this->limits[0];// ilość produktów na stornie $this->limitstart = ($limitstart > 0) ? (floor($limitstart / $this->limit) * $this->limit) : 0; $this->total = $total; $this->page = intval($this->limitstart / $this->limit) + 1; $this->pages = (int)ceil($this->total / $this->limit); $this->max2show = 10; $this->req_method = 'GET'; $this->req_args = array(); $this->page_nr_arg_name = 'nr'; } public function set_request_args($args) { $this->req_args = $args; } public function set_request_arg_page_nr_name($nr_name) { $this->page_nr_arg_name = $nr_name; } public function set_request_method_post() { $this->req_method = 'POST'; $this->_post_uniq_id = uniqid('PageNav_'); } public function set_request_method_get() { $this->req_method = 'GET'; } /** * Generate page nr link. */ public function get_page_link($nr) { $params = array(); foreach ($this->req_args as $k => $v) { $params [$k] = $v; } $params[$this->page_nr_arg_name] = ($nr - 1) * $this->limit; $params_out = array(); foreach ($params as $k => $v) { $params_out[] = $k . "=" . $v; } return "?" . implode("&", $params_out); } function render_post_form() { $out = ''; if (!$this->_post_form_rendered) { $out .= ''; $out .= '
'; $this->_post_form_rendered = true; } return $out; } /** * Render navigation links. */ public function render($type = 'table') { $out = ''; if ($this->req_method == 'POST') { $out .= $this->render_post_form(); } $out .= '| ';
if (0) {//TODO: count($this->limits)) {
$out .= ' ';
$out .= ' Pokaż: ';
$out .= ' ';
$out .= ' ';//class="limit"
}//if (0)
$out .= ' | ';
$out .= ' ';
if ($this->total > $this->limit) {# nie pokazuje listy stron jak jest tylko jedna
/*
* _1 2 3 4 5 6 7 8 ... 59 60
* 1 _2 3 4 5 6 7 8 ... 59 60
* 1 2 _3 4 5 6 7 8 ... 59 60
* 1 2 3 _4 5 6 7 8 ... 59 60
* 1 2 3 4 _5 6 7 8 ... 59 60
* 1 2 3 4 5 _6 7 8 ... 59 60
* 1 2 ... 5 6 _7 8 9 ... 59 60
* 1 2 ... 6 7 _8 9 10 ... 59 60
* ...
* 1 2 ... 52 53 _54 55 56 ... 59 60
* 1 2 ... 53 54 _55 56 57 58 59 60
* 1 2 ... 53 54 55 _56 57 58 59 60
* 1 2 ... 53 54 55 56 _57 58 59 60
* 1 2 ... 53 54 55 56 57 _58 59 60
*/
if ($this->page == 1) {
$out .= ' << ';
$out .= ' < ';
}
else {
$out .= $this->link(' << ', 1, array('title'=>"Pierwsza"));
$out .= $this->link(' < ', $this->page - 1, array('title'=>"Poprzednia"));
}
if ($this->pages > $this->max2show) {
$out .= $this->show_page(1);
$out .= $this->show_page(2);
if ($this->page <= 6) {//show [0:8] ... [-2]
for ($i = 3; $i <= 8; $i++) {
$out .= $this->show_page($i);
}
$out .= ' ... ';
}
else if ($this->page > $this->pages - 6) {//show [0:2] ... [-8]
$out .= ' ... ';
for ($i = $this->pages - 7; $i <= $this->pages - 2; $i++) {
$out .= $this->show_page($i);
}
}
else {//show [0:2] ... [$i-2:$i+2] ... [-2]
$out .= ' ... ';
for ($i = $this->page - 2; $i <= $this->page + 2; $i++) {
$out .= $this->show_page($i);
}
$out .= ' ... ';
}
$out .= $this->show_page($this->pages - 1);
$out .= $this->show_page($this->pages);
}
else {//print all nr
for ($i = 1; $i <= $this->pages; $i++) {
$out .= ' '.$this->show_page($i).' ';
}
}
if ($this->page == $this->pages) {
$out .= ' > ';
$out .= ' >> ';
}
else {
$out .= $this->link(' > ', $this->page + 1, array('title'=>"Następna"));
$out .= $this->link(' >> ', $this->pages, array('title'=>"Ostatnia"));
}
if ($type != 'links_only') {
$out .= ' ';//.strony
$out .= ''; } } if ($type != 'links_only') { $out .= 'strona '.$this->page.' z '.$this->pages.''; $out .= ' (' . $this->total . ' rekordów)'; } $out .= ' |