diff options
author | Lukas Fleischer <archlinux@cryptocrack.de> | 2014-04-05 19:33:32 +0200 |
---|---|---|
committer | Lukas Fleischer <archlinux@cryptocrack.de> | 2014-04-05 19:52:51 +0200 |
commit | 5415bc945aa43e5ee293cd0b6025ccb62426c159 (patch) | |
tree | e8127c3eb05c4d43986dcba9a865e2eaa54a800f /web | |
parent | 122636cbb6413d67c37ba73bd7014ae0a977d5c4 (diff) |
Refactor pkgbase_comments()
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web')
-rw-r--r-- | web/lib/pkgbasefuncs.inc.php | 49 | ||||
-rw-r--r-- | web/lib/pkgfuncs.inc.php | 3 |
2 files changed, 25 insertions, 27 deletions
diff --git a/web/lib/pkgbasefuncs.inc.php b/web/lib/pkgbasefuncs.inc.php index 24ce7a9..5be7048 100644 --- a/web/lib/pkgbasefuncs.inc.php +++ b/web/lib/pkgbasefuncs.inc.php @@ -50,37 +50,33 @@ function pkgbase_comments_count($base_id) { /** * Get all package comment information for a specific package base * - * @param int $pkgid The package base ID to get comments for + * @param int $base_id The package base ID to get comments for + * @param int $limit Maximum number of comments to return (0 means unlimited) * * @return array All package comment information for a specific package base */ -function pkgbase_comments($base_id) { +function pkgbase_comments($base_id, $limit) { $base_id = intval($base_id); - $comments = array(); - if ($base_id > 0) { - $dbh = DB::connect(); - $q = "SELECT PackageComments.ID, UserName, UsersID, Comments, CommentTS "; - $q.= "FROM PackageComments LEFT JOIN Users "; - $q.= "ON PackageComments.UsersID = Users.ID "; - $q.= "WHERE PackageBaseID = " . $base_id . " "; - $q.= "AND DelUsersID IS NULL "; - $q.= "ORDER BY CommentTS DESC"; - - if (!isset($_GET['comments'])) { - $q.= " LIMIT 10"; - } - - $result = $dbh->query($q); - - if (!$result) { - return; - } + $limit = intval($limit); + if (!$base_id) { + return null; + } - while ($row = $result->fetch(PDO::FETCH_ASSOC)) { - $comments[] = $row; - } + $dbh = DB::connect(); + $q = "SELECT PackageComments.ID, UserName, UsersID, Comments, "; + $q.= "CommentTS FROM PackageComments LEFT JOIN Users "; + $q.= "ON PackageComments.UsersID = Users.ID "; + $q.= "WHERE PackageBaseID = " . $base_id . " "; + $q.= "AND DelUsersID IS NULL ORDER BY CommentTS DESC"; + if ($limit > 0) { + $q.=" LIMIT " . $limit; + } + $result = $dbh->query($q); + if (!$result) { + return null; } - return $comments; + + return $result->fetchAll(); } /** @@ -239,7 +235,8 @@ function pkgbase_display_details($base_id, $row, $SID="") { include('pkg_comment_form.php'); } - $comments = pkgbase_comments($base_id); + $limit = isset($_GET['comments']) ? 0 : 10; + $comments = pkgbase_comments($base_id, $limit); if (!empty($comments)) { include('pkg_comments.php'); } diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index 76fed89..c6b4a27 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -301,7 +301,8 @@ function pkg_display_details($id=0, $row, $SID="") { include('pkg_comment_form.php'); } - $comments = pkgbase_comments($base_id); + $limit = isset($_GET['comments']) ? 0 : 10; + $comments = pkgbase_comments($base_id, $limit); if (!empty($comments)) { include('pkg_comments.php'); } |