Skip to content
Snippets Groups Projects
Commit e305a5a0 authored by Jared Hancock's avatar Jared Hancock Committed by Peter Rotich
Browse files

queue: Fix pagination of tickets

Turns out the pagination system is somewhat chicken and egg with respect to
determining the number of pages. The query needs to be sent to the database
to fetch the page content so that the database can also count the total
number of records available.
parent 5be0de0d
Branches
Tags
No related merge requests found
...@@ -25,10 +25,15 @@ class PageNate { ...@@ -25,10 +25,15 @@ class PageNate {
function __construct($total,$page,$limit=20,$url='') { function __construct($total,$page,$limit=20,$url='') {
$this->total = intval($total);
$this->limit = max($limit, 1 ); $this->limit = max($limit, 1 );
$this->page = max($page, 1 ); $this->page = max($page, 1 );
$this->start = max((($page-1)*$this->limit),0); $this->start = max((($page-1)*$this->limit),0);
$this->setURL($url);
$this->setTotal($total);
}
function setTotal($total) {
$this->total = intval($total);
$this->pages = ceil( $this->total / $this->limit ); $this->pages = ceil( $this->total / $this->limit );
if (($this->limit > $this->total) || ($this->page>ceil($this->total/$this->limit))) { if (($this->limit > $this->total) || ($this->page>ceil($this->total/$this->limit))) {
...@@ -37,7 +42,6 @@ class PageNate { ...@@ -37,7 +42,6 @@ class PageNate {
if (($this->limit-1)*$this->start > $this->total) { if (($this->limit-1)*$this->start > $this->total) {
$this->start -= $this->start % $this->limit; $this->start -= $this->start % $this->limit;
} }
$this->setURL($url);
} }
function setURL($url='',$vars='') { function setURL($url='',$vars='') {
...@@ -160,5 +164,9 @@ class PageNate { ...@@ -160,5 +164,9 @@ class PageNate {
return $qs->limit($end-$start)->offset($start); return $qs->limit($end-$start)->offset($start);
} }
function paginateSimple(QuerySet $qs) {
return $qs->limit($this->getLimit() + $this->slack)->offset($this->getStart());
}
} }
?> ?>
...@@ -91,10 +91,11 @@ if (!$sorted && isset($sort['queuesort'])) { ...@@ -91,10 +91,11 @@ if (!$sorted && isset($sort['queuesort'])) {
// Apply pagination // Apply pagination
$page = ($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1; $page = ($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1;
$pageNav = new Pagenate(PHP_INT_MAX, $page, PAGE_LIMIT);
$tickets = $pageNav->paginateSimple($tickets);
$count = $tickets->total(); $count = $tickets->total();
$pageNav = new Pagenate($count, $page, PAGE_LIMIT); $pageNav->setTotal($count);
$pageNav->setURL('tickets.php', $args); $pageNav->setURL('tickets.php', $args);
$tickets = $pageNav->paginate($tickets);
?> ?>
<!-- SEARCH FORM START --> <!-- SEARCH FORM START -->
...@@ -211,7 +212,7 @@ if ( ...@@ -211,7 +212,7 @@ if (
$canManageTickets = $thisstaff->canManageTickets(); $canManageTickets = $thisstaff->canManageTickets();
if ($canManageTickets) { ?> if ($canManageTickets) { ?>
<th style="width:12px"></th> <th style="width:12px"></th>
<?php <?php
} }
foreach ($columns as $C) { foreach ($columns as $C) {
$heading = Format::htmlchars($C->getLocalHeading()); $heading = Format::htmlchars($C->getLocalHeading());
...@@ -234,9 +235,9 @@ foreach ($columns as $C) { ...@@ -234,9 +235,9 @@ foreach ($columns as $C) {
foreach ($tickets as $T) { foreach ($tickets as $T) {
echo '<tr>'; echo '<tr>';
if ($canManageTickets) { ?> if ($canManageTickets) { ?>
<td><input type="checkbox" class="ckb" name="tids[]" <td><input type="checkbox" class="ckb" name="tids[]"
value="<?php echo $T['ticket_id']; ?>" /></td> value="<?php echo $T['ticket_id']; ?>" /></td>
<?php <?php
} }
foreach ($columns as $C) { foreach ($columns as $C) {
list($contents, $styles) = $C->render($T); list($contents, $styles) = $C->render($T);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment