Mini Shell

Direktori : /home/emypro/www/en/admin/core/
Upload File :
Current File : /home/emypro/www/en/admin/core/Paginate.php

<?php
/**
 * Paginate
 *
 * @author Andrew Esteves <andrew@digitalnativa.com.br>
 * @copyright Digital Nativa (www.digitalnativa.com.br)
 */

class Paginate
{
	/**
	 * Total pages
	 * @var Int
	 */
	public $total;

	/**
	 * Current page
	 * @var Int
	 */
	public $current;

	/**
	 * Current url
	 * "http://$_SERVER[HTTP_HOST]$_SERVER[PHP_SELF]";
	 * @var String
	 */
	public $url;

	/**
	 * Initialize
	 */
	public function __construct($total, $per_page)
	{
		$this->total = ceil($total / $per_page);
		$this->current = isset($_GET['page']) ? $_GET['page'] : 1;
		$this->url = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
	}

	/**
	 * Next
	 *
	 * @return String
	 * @access private
	 */
	private function _next()
	{
		if($this->total > 1 && $this->current < $this->total) {
			$next = $this->current + 1;
			return '<a href="'. $this->url .'?page='. $next .'" class="btn btn-default">Próxima</a>';
		}
	}

	/**
	 * Previous
	 *
	 * @return String
	 * @access private
	 */
	private function _prev()
	{
		if($this->total > 1 && $this->current > 1) {
			$prev = $this->current - 1;
			return '<a href="'. $this->url .'?page='. $prev .'" class="btn btn-default">Anterior</a>';
		}
	}

	/**
	 * Page
	 *
	 * @return Int
	 */
	public function page()
	{
		return isset($_GET['page']) ? $_GET['page'] : 1;
	}

	/**
	 * Render pagination
	 *
	 * @return String
	 */
	public function render()
	{
		$prev = $this->_prev();
		$next = $this->_next();

		return $prev .' '. $next .' '. $this->current .' de '. $this->total; 
	}
}

Zerion Mini Shell 1.0