[aur-dev] [PATCH 4/4] Fix pagination in the package request list

Lukas Fleischer archlinux at cryptocrack.de
Wed Jul 2 02:29:37 EDT 2014


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

Signed-off-by: Lukas Fleischer <archlinux at cryptocrack.de>
---
 web/html/pkgreq.php         |  6 +++---
 web/lib/pkgreqfuncs.inc.php | 19 +++++++++++++++++--
 2 files changed, 20 insertions(+), 5 deletions(-)

diff --git a/web/html/pkgreq.php b/web/html/pkgreq.php
index 674f1c1..4b7d6cf 100644
--- a/web/html/pkgreq.php
+++ b/web/html/pkgreq.php
@@ -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;
 
diff --git a/web/lib/pkgreqfuncs.inc.php b/web/lib/pkgreqfuncs.inc.php
index 852554b..a79677e 100644
--- a/web/lib/pkgreqfuncs.inc.php
+++ b/web/lib/pkgreqfuncs.inc.php
@@ -3,11 +3,25 @@ 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, ";
@@ -20,7 +34,8 @@ function pkgreq_list() {
 	$q.= "FROM PackageRequests INNER JOIN RequestTypes ON ";
 	$q.= "RequestTypes.ID = PackageRequests.ReqTypeID ";
 	$q.= "INNER JOIN Users ON Users.ID = PackageRequests.UsersID ";
-	$q.= "ORDER BY Status ASC, RequestTS DESC";
+	$q.= "ORDER BY Status ASC, RequestTS DESC ";
+	$q.= "LIMIT " . $limit . " OFFSET " . $offset;
 
 	return $dbh->query($q)->fetchAll();
 }
-- 
2.0.1



More information about the aur-dev mailing list