Location: PHPKode > projects > Anahita Social Engine > dependencies/plg_system_socialengine/socialengine/uikit/page/pagination.php
<?php
/**
 * @version		1.0.0
 * @category	Anahita Social Engine™
 * @copyright	Copyright (C) 2008 - 2010 rmdStudio Inc. and Peerglobe Technology Inc. All rights reserved.
 * @license		GNU GPLv2 <http://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
 * @link     	http://www.anahitapolis.com
 */

class AnUikitPagePagination extends AnUikitViewUikit
{
	protected $_layout = 'pagination';
	
	public function setLayout($layout) {}
	
	public function setCollection($collection, $url = null)
	{		
		$this->assign('collection', 		$collection);
		$this->assign('total',				$collection->getTotal());
		$this->assign('offset',				$collection->getOffset());
		$this->assign('limit' ,				$collection->getLimit());
		$this->assign('previous_page', 		null);
		$this->assign('next_page', 			null);		
		
		$num_pages = ceil( $this->total / $this->limit );
		
		$pages	   = array();
		
		if  ( is_null($url)	) 
		{
			$url  = KRequest::url();
		}
		
		$current_page_num = ceil($this->offset / $this->limit) + 1;
		
		foreach(range(1, $num_pages) as $page_num) 
		{
			$page_url   = clone $url;
			$query = array_merge( $page_url->getQuery(true), array('limit'=>$this->limit, 'start'=>($page_num - 1) * $this->limit));
			$page_url->setQuery($query);
			$current  = $current_page_num == $page_num;
			$previous = $current_page_num == $page_num + 1;
			$next	  = $current_page_num == $page_num - 1;
			$pages[]  = array(
				'number'  => $page_num,
				'url'     => $page_url,
				'current' => $current
			);
			
			if ( $previous ) {
				$this->assign('previous_page',$page_url);
			} else if ( $next ) {
				$this->assign('next_page',	$page_url);
			}
		}
		
		$this->assign('pages', $pages);
		
		return $this;
	}
	
}
Return current item: Anahita Social Engine