Location: PHPKode > projects > Content*Builder > contentbuilder/lib/pageSplit.class.php
<?php

class PageSplit {
	
	var $limit  = 5;
	var $offset = 0;
	var $numpage;
	
	var $nextPage, $lastPage, $lastAvailable, $nextAvailable, $thisPage;
	var $pages = array();
	
	function PageSplit($limitation, $oset, $np) {
		$this->limit  = $limitation;
		$this->offset = $oset;
		$this->numpage = $np;
		
		$this->buildPages();
	}
	
	function buildPages() {
		if ($this->offset >= $this->limit) {
			$this->lastPage = $this->offset - $this->limit;
			$this->lastAvailable = true;
		} else {
			$this->lastPage = 0;
			$this->lastAvailable = false;
		}
		
		if ($this->offset != $this->limit * ($this->numpage - 1)) {
			$this->nextPage = $this->offset + $this->limit;
			$this->nextAvailable = true;
		} else { 
			$this->nextPage = 0;
			$this->nextAvailable = false; 
		}
		
		for ($i = 1; $i <= $this->numpage; $i++) {
			if ((($i-1) * $this->limit) == $this->offset) {
				$this->thisPage = $i;
			}			
			$this->pages[$i] = ($i-1) * $this->limit;
		}
	}
	
	function checkLastAvailable() {
		return($this->lastAvailable);
	}
	
	function checkNextAvailable() {
		return($this->nextAvailable);
	}
	
	function checkThisPage($check) {
		if($check == $this->thisPage) {
			$result = true;
		} else { $result = false; }
		return($result);
	}
	
	function getLastPage() {
		return($this->lastPage);
	}
	
	function getNextPage() {
		return($this->nextPage);
	}
	
	function getPages() {
		return($this->pages); 
	}
	
	function getBackLink($urlStuff, $text) {
		if($this->checkLastAvailable()) {
			$back = '<a href="'.$urlStuff.'&offset='.$this->getLastPage().'">'.$text.'</a> ';
		} else { 
			$back = $text; 
		}
		return $back;
	}
	
	function getNextLink($urlStuff, $text) {
		if($this->checkNextAvailable()) {
			$next = '<a href="'.$urlStuff.'&offset='.$this->getNextPage().'">'.$text.'</a> ';
		} else { 
			$next = $text; 
		}
		return $next;
	}
	
	function getPageLinks($urlStuff) {
		foreach($this->pages as $key => $value) {
			if(!$this->checkThisPage($key)) {
				$pageLinks .= ' <a href="'.$urlStuff.'&offset='.$value.'">'.$key.'</a>';
			} else { $pageLinks .= ' '.$key; }
		}
		return($pageLinks);
	}	
}

?>
Return current item: Content*Builder