public function __construct(Sabel_View_Pager $pager, $window = null) { $this->pager = clone $pager; $this->current = $pager->getPageNumber(); $this->lastPage = $pager->getTotalPageNumber(); if (is_numeric($window)) { $this->window = $window; } }
public function build($limit, array $getValues = array()) { $page = 1; $pageKey = $this->attributes["pageKey"]; if (isset($getValues[$pageKey])) { $page = $getValues[$pageKey]; if (!is_numeric($page) || $page < 1) { $page = 1; } } $model = $this->model; $attributes =& $this->attributes; unset($getValues[$pageKey]); unset($getValues[ini_get("session.name")]); $attributes["uriQuery"] = http_build_query($getValues, "", "&"); $count = $this->lastPage * $limit; $attributes["count"] = $count; $attributes["limit"] = $limit; $attributes[$pageKey] = $page; $pager = new Sabel_View_Pager($count, $limit); $pager->setPageNumber($page); $attributes["viewer"] = new Sabel_View_PageViewer($pager); if ($count === 0) { $attributes["offset"] = 0; $attributes["results"] = array(); $model->clear(); } else { $offset = $pager->getSqlOffset(); $this->_setOrderBy($getValues); $model->setLimit($limit + 1); $model->setOffset($offset); $attributes["offset"] = $offset; $attributes["results"] = $model->{$this->method}(); $results = $attributes["results"]; if (count($results) > $limit) { array_pop($results); $attributes["results"] = $results; if ($page < $this->lastPage) { $this->hasNext = true; } } } return $this; }
public function testStandardUseAndPageNumberFirst() { $pager = new Sabel_View_Pager(200, 10); $pager->setPageNumber(1); $pv = new Sabel_View_PageViewer($pager, 5); $this->assertTrue($pv->isFirst()); $this->assertTrue($pv->isCurrent()); $this->assertFalse($pv->isLast()); $this->assertEquals(1, $pv->getCurrent()); $this->assertEquals(2, $pv->getNext()); $this->assertEquals(1, $pv->getPrevious()); $num = 1; foreach ($pv as $page) { $this->assertEquals($num++, $page->getCurrent()); } $this->assertEquals(6, $num); $this->assertEquals(1, $pv->getCurrent()); $this->assertEquals(2, $pv->getNext()); $this->assertEquals(1, $pv->getPrevious()); }
public function testInitializedPagerUse() { $pager = new Sabel_View_Pager(200, 20); $pager->setPageNumber(4.3); $this->assertEquals(200, $pager->getNumberOfItem()); $this->assertEquals(20, $pager->getLimit()); $this->assertEquals(4, $pager->getPageNumber()); $this->assertEquals(10, $pager->getTotalPageNumber()); $this->assertEquals(60, $pager->getSqlOffset()); }
public function build($limit, array $getValues = array()) { $page = 1; $pageKey = $this->attributes["pageKey"]; if (isset($getValues[$pageKey])) { $page = $getValues[$pageKey]; if (!is_numeric($page) || $page < 1) { $page = 1; } } $model = $this->model; $attributes =& $this->attributes; unset($getValues[$pageKey]); $attributes["uriQuery"] = http_build_query($getValues, "", "&"); $count = $this->isJoin ? $model->getCount(false) : $model->getCount(); $attributes["count"] = $count; $attributes["limit"] = $limit; $attributes["page"] = $page; $pager = new Sabel_View_Pager($count, $limit); $pager->setPageNumber($page); $attributes["viewer"] = new Sabel_View_PageViewer($pager); if ($count === 0) { $attributes["offset"] = 0; $attributes["results"] = array(); $model->clear(); } else { $offset = $pager->getSqlOffset(); $this->_setOrderBy($getValues); $model->setLimit($limit); $model->setOffset($offset); $attributes["offset"] = $offset; $attributes["results"] = $model->{$this->method}(); } return $this; }
public function build($limit, $page) { if (!is_numeric($page) || $page < 1) { $page = 1; } $model = $this->model; $attributes =& $this->attributes; if ($this->isJoin) { $count = $model->getCount(null, false); } else { $count = $model->getCount(); } $attributes["count"] = $count; $attributes["limit"] = $limit; $attributes["page"] = $page; $pager = Sabel_View_Pager::create($count, $limit); $pager->setPageNumber($page); $attributes["viewer"] = new Sabel_View_PageViewer($pager); if ($count === 0) { $attributes["offset"] = 0; $attributes["results"] = array(); } else { $offset = $pager->getSqlOffset(); if ($this->isJoin) { $model->getModel()->setLimit($limit); $model->getModel()->setOffset($offset); } else { $model->setLimit($limit); $model->setOffset($offset); } $attributes["offset"] = $offset; $attributes["results"] = $model->{$this->method}(); } return $this; }
public function build($limit, array $getValues = array()) { $page = 1; $pageKey = $this->attributes["pageKey"]; if (isset($getValues[$pageKey])) { $page = $getValues[$pageKey]; if (!is_numeric($page) || $page < 1) { $page = 1; } } $model = $this->model; $attributes =& $this->attributes; $uriQuery = array(); foreach ($getValues as $key => $val) { if ($key === $pageKey) { unset($getValues[$key]); } elseif (is_array($val)) { foreach ($val as $k => $v) { $uriQuery[] = urlencode("{$key}[{$k}]") . "=" . urlencode($v); } } else { $uriQuery[] = urlencode($key) . "=" . urlencode($val); } } $attributes["uriQuery"] = implode("&", $uriQuery); $count = $this->isJoin ? $model->getCount(null, false) : $model->getCount(); $attributes["count"] = $count; $attributes["limit"] = $limit; $attributes["page"] = $page; $pager = new Sabel_View_Pager($count, $limit); $pager->setPageNumber($page); $attributes["viewer"] = new Sabel_View_PageViewer($pager); if ($count === 0) { $attributes["offset"] = 0; $attributes["results"] = array(); } else { $offset = $pager->getSqlOffset(); $this->_setOrderBy($getValues); $model->setLimit($limit); $model->setOffset($offset); $attributes["offset"] = $offset; $attributes["results"] = $model->{$this->method}(); if ($this->uri === null && ($request = Sabel_Context::getRequest())) { $attributes["uri"] = get_uri_prefix() . "/" . $request->getUri(); } } return $this; }