Просмотр файла inc/classes/pager.php

Размер файла: 2.3Kb
<?php
///Класс постраничной навигации by Wapweb/////
##############################################
class pager {

	// Public methods&objects
	public $count;
	public $on_page;
	public $end;
	
	public function __construct($count,$on_page,$end) {
		$this->count = $count;
		$this->on_page = $on_page;
		$this->end = $end;
	}
	
	public function get_start() {
		return $this->start = $this->get_page() * $this->on_page - $this->on_page;
	}
	
	public function print_nav() {
		if ($this->get_total() > 1) {
			return '<div class="main">Навигация:<br/>'.$this->get_nav().'</div>';
		} else return false;
	}
	
	//Private methods&objects
	private $total;
	private $start;
	private $view;
	private $page;
	
	private function get_total() {
		return $this->total = intval(($this->count - 1) / ($this->on_page)) + 1;
	}
	
	private function get_page() {
		$this->page = isset($_GET['page']) && !empty($_GET['page']) ? intval($_GET['page']) : 1;
		if (empty($this->page) || $this->page < 0) $this->page = 1;
		if ($this->page > $this->get_total()) $this->page = $this->get_total();
		return $this->page;
	}
	
	private function get_nav() {
		if ($this->get_page() != 1) $this->view = '<a href= "'.$this->end. ($this->get_page() - 1) .'"><<<</a> ';
		if (($this->get_page() - 4) > 0) $this->view.= '<a href="'.($this->end).'page-1">1</a>...';
		if($this->get_page() - 2 > 0) $this->view.= ' <a href= "'.$this->end. ($this->get_page() - 2) .'">'. ($this->get_page() - 2) .'</a> ';
		if($this->get_page() - 1 > 0) $this->view.= '<a href= "'.$this->end. ($this->get_page() - 1) .'">'. ($this->get_page() - 1) .'</a> ';
								$this->view.= '<b>['.$this->get_page().']</b>';
		if($this->get_page() + 1 <= $this->get_total()) $this->view.= ' <a href="'.$this->end.($this->get_page() + 1) .'">'. ($this->get_page() + 1) .'</a>';
		if($this->get_page() + 2 <= $this->get_total()) $this->view.= ' <a href= "'.$this->end.($this->get_page() + 2) .'">'. ($this->get_page() + 2) .'</a>';
		if (($this->get_page() + 4) <= $this->get_total()) $this->view.= '...<a href="'.($this->end).($this->get_total()).'">'.($this->get_total()).'</a>';
		if ($this->get_page() != $this->get_total()) $this->view.= ' <a href="'.($this->end).($this->get_page() + 1) .'">>>></a>';
		return $this->view;
	}
	
}
?>