Fix pagination in the package request list

This was not implemented properly in commit 8260111 (Add a package
request list, 2014-06-24).

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2014-07-02 08:18:15 +02:00
parent 64c4e51698
commit a149fc493f
2 changed files with 20 additions and 5 deletions

View file

@ -14,9 +14,6 @@ if (!isset($base_id)) {
exit();
}
$results = pkgreq_list();
$total = count($results);
/* Sanitize paging variables. */
if (isset($_GET['O'])) {
$_GET['O'] = max(intval($_GET['O']), 0);
@ -30,6 +27,9 @@ if (!isset($base_id)) {
$_GET["PP"] = 50;
}
$results = pkgreq_list($_GET['O'], $_GET['PP']);
$total = pkgreq_count();
/* Calculate the results to use. */
$first = $_GET['O'] + 1;

View file

@ -2,12 +2,26 @@
include_once("config.inc.php");
include_once("pkgbasefuncs.inc.php");
/**
* Get the number of package requests
*
* @return int The total number of package requests
*/
function pkgreq_count() {
$dbh = DB::connect();
$q = "SELECT COUNT(*) FROM PackageRequests";
return $dbh->query($q)->fetchColumn();
}
/**
* Get a list of all package requests
*
* @param int $offset The index of the first request to return
* @param int $limit The maximum number of requests to return
*
* @return array List of pacakge requests with details
*/
function pkgreq_list() {
function pkgreq_list($offset, $limit) {
$dbh = DB::connect();
$q = "SELECT PackageRequests.ID, ";
@ -21,6 +35,7 @@ function pkgreq_list() {
$q.= "RequestTypes.ID = PackageRequests.ReqTypeID ";
$q.= "INNER JOIN Users ON Users.ID = PackageRequests.UsersID ";
$q.= "ORDER BY Status ASC, RequestTS DESC ";
$q.= "LIMIT " . $limit . " OFFSET " . $offset;
return $dbh->query($q)->fetchAll();
}