setApp();
$this->setLang();
$this->setModuleName();
$this->setMethodName();
$this->setRecTotal($recTotal);
$this->setRecPerPage($recPerPage);
$this->setPageTotal();
$this->setPageID($pageID);
}
/**
* The factory function.
*
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return object
*/
public function init($recTotal = 0, $recPerPage = 20, $pageID = 1)
{
return new pager($recTotal, $recPerPage, $pageID);
}
/**
* Set the recTotal property.
*
* @param int $recTotal
* @access public
* @return void
*/
public function setRecTotal($recTotal = 0)
{
$this->recTotal = (int)$recTotal;
}
/**
* Set the recTotal property.
*
* @param int $recPerPage
* @access public
* @return void
*/
public function setRecPerPage($recPerPage)
{
/* Set the cookie name. */
$this->pageCookie = 'pager' . ucfirst($this->app->getModuleName()) . ucfirst($this->app->getMethodName());
if(isset($_COOKIE[$this->pageCookie])) $recPerPage = $_COOKIE[$this->pageCookie];
$this->recPerPage = ($recPerPage > 0) ? $recPerPage : PAGER::DEFAULT_REC_PRE_PAGE;
}
/**
* Set the pageTotal property.
*
* @access public
* @return void
*/
public function setPageTotal()
{
$this->pageTotal = ceil($this->recTotal / $this->recPerPage);
}
/**
* Set the page id.
*
* @param int $pageID
* @access public
* @return void
*/
public function setPageID($pageID)
{
if($pageID > 0 and $pageID <= $this->pageTotal)
{
$this->pageID = $pageID;
}
else
{
$this->pageID = 1;
}
}
/**
* Set the $app property;
*
* @access private
* @return void
*/
private function setApp()
{
global $app;
$this->app = $app;
}
/**
* Set the $lang property.
*
* @access private
* @return void
*/
private function setLang()
{
global $lang;
$this->lang = $lang;
}
/**
* Set the $moduleName property.
*
* @access private
* @return void
*/
private function setModuleName()
{
$this->moduleName = $this->app->getModuleName();
}
/**
* Set the $methodName property.
*
* @access private
* @return void
*/
private function setMethodName()
{
$this->methodName = $this->app->getMethodName();
}
/**
* Get recTotal, recPerpage, pageID from the request params, and add them to params.
*
* @access private
* @return void
*/
private function setParams()
{
$this->params = $this->app->getParams();
foreach($this->params as $key => $value)
{
if(strtolower($key) == 'rectotal') $this->params[$key] = $this->recTotal;
if(strtolower($key) == 'recperpage') $this->params[$key] = $this->recPerPage;
if(strtolower($key) == 'pageID') $this->params[$key] = $this->pageID;
}
}
/**
* Create the limit string.
*
* @access public
* @return string
*/
public function limit()
{
$limit = '';
if($this->pageTotal > 1) $limit = ' limit ' . ($this->pageID - 1) * $this->recPerPage . ", $this->recPerPage";
return $limit;
}
/**
* Print the pager's html.
*
* @param string $align
* @param string $type
* @access public
* @return void
*/
public function show($align = 'right', $type = 'full')
{
echo $this->get($align, $type);
}
/**
* Get the pager html string.
*
* @param string $align
* @param string $type the pager type, full|short|shortest
* @access public
* @return string
*/
public function get($align = 'right', $type = 'full')
{
/* If the RecTotal is zero, return with no record. */
if($this->recTotal == 0) { return "
{$this->lang->pager->noRecord}
"; }
/* Set the params. */
$this->setParams();
/* Create the prePage and nextpage, all types have them. */
$pager = $this->createPrePage();
$pager .= $this->createNextPage();
/* The short and full type. */
if($type !== 'shortest')
{
$pager = $this->createFirstPage() . $pager;
$pager .= $this->createLastPage();
}
/* Only the full type . */
if($type == 'full')
{
$pager = $this->createDigest() . $pager;
$pager .= $this->createGoTo();
$pager .= $this->createRecPerPageJS();
}
return "