Skip to content

Commit

Permalink
#211 - further fixes to the pagination links in the ActiveRecordContr…
Browse files Browse the repository at this point in the history
…oller, and updated the TagController to support simple record linking
  • Loading branch information
alphadevx committed Sep 7, 2015
1 parent 4bfd7f2 commit de4fefc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
28 changes: 17 additions & 11 deletions Alpha/Controller/ActiveRecordController.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ActiveRecordController extends Controller implements ControllerInterface
*
* @since 2.0
*/
protected $start = 1;
protected $start = 0;

/**
* The amount of records to return during pageination.
Expand All @@ -76,7 +76,7 @@ class ActiveRecordController extends Controller implements ControllerInterface
*
* @since 2.0
*/
protected $limit = 1;
protected $limit;

/**
* The count of the records of this type in the database (used during pagination).
Expand Down Expand Up @@ -668,12 +668,15 @@ protected function renderPageLinks()

$body = '';

$end = (($this->start - 1) + $config->get('app.list.page.amount'));
// the index of the last record displayed on this page
$last = $this->start + $config->get('app.list.page.amount');

if ($end > $this->recordCount) {
$end = $this->recordCount;
// ensure that the last index never overruns the total record count
if ($last > $this->recordCount) {
$last = $this->recordCount;
}

// render a message for an empty list
if ($this->recordCount > 0) {
$body .= '<ul class="pagination">';
} else {
Expand All @@ -682,7 +685,8 @@ protected function renderPageLinks()
return $body;
}

if ($this->start > 1) {
// render "Previous" link
if ($this->start > 0) {
// handle secure URLs
if ($this->request->getParam('token', null) != null) {
$body .= '<li><a href="'.FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.$this->request->getParam('ActiveRecordType').'&start='.($this->start - $this->limit).'&limit='.$this->limit).'">&lt;&lt;-Previous</a></li>';
Expand All @@ -693,26 +697,28 @@ protected function renderPageLinks()
$body .= '<li class="disabled"><a href="#">&lt;&lt;-Previous</a></li>';
}

// render the page index links
if ($this->recordCount > $this->limit) {
$page = 1;

for ($i = 0; $i < $this->recordCount; $i += $this->limit) {
if ($i != ($this->start - 1)) {
if ($i != $this->start) {
// handle secure URLs
if ($this->request->getParam('token', null) != null) {
$body .= '<li><a href="'.FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.$this->request->getParam('ActiveRecordType').'&start='.($i + 1).'&limit='.$this->limit).'">'.$page.'</a></li>';
$body .= '<li><a href="'.FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.$this->request->getParam('ActiveRecordType').'&start='.$i.'&limit='.$this->limit).'">'.$page.'</a></li>';
} else {
$body .= '<li><a href="/records/'.urlencode($this->request->getParam('ActiveRecordType')).'/'.($i + 1).'/'.$this->limit.'">'.$page.'</a></li>';
$body .= '<li><a href="/records/'.urlencode($this->request->getParam('ActiveRecordType')).'/'.$i.'/'.$this->limit.'">'.$page.'</a></li>';
}
} elseif ($this->recordCount > $this->limit) {
} elseif ($this->recordCount > $this->limit) { // render an anchor for the current page
$body .= '<li class="active"><a href="#">'.$page.'</a></li>';
}

++$page;
}
}

if ($this->recordCount > $end) {
// render "Next" link
if ($this->recordCount > $last) {
// handle secure URLs
if ($this->request->getParam('token', null) != null) {
$body .= '<li><a href="'.FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType='.$this->request->getParam('ActiveRecordType').'&start='.($this->start + $this->limit).'&limit='.$this->limit).'">Next-&gt;&gt;</a></li>';
Expand Down
5 changes: 5 additions & 0 deletions Alpha/Controller/TagController.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public function doGET($request)
$body .= $message;
}

// just listing tags records, so invoke the parent
if (isset($params['start'])) {
return parent::doGET($request);
}

// render the tag manager screen
if (!isset($params['ActiveRecordType']) && !isset($params['ActiveRecordOID'])) {
$body .= '<h3>Listing active record which are tagged</h3>';
Expand Down

0 comments on commit de4fefc

Please sign in to comment.