Refactor pkgbase_comments_count()

Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
Lukas Fleischer 2014-04-05 19:32:44 +02:00
parent 206678dfb7
commit 122636cbb6

View file

@ -25,28 +25,26 @@ function pkgbase_categories() {
/** /**
* Get the number of non-deleted comments for a specific package base * Get the number of non-deleted comments for a specific package base
* *
* @param string $pkgid The package base ID to get comment count for * @param string $base_id The package base ID to get comment count for
* *
* @return string The number of comments left for a specific package * @return string The number of comments left for a specific package
*/ */
function pkgbase_comments_count($base_id) { function pkgbase_comments_count($base_id) {
$dbh = DB::connect();
$base_id = intval($base_id); $base_id = intval($base_id);
if ($base_id > 0) { if (!$base_id) {
$dbh = DB::connect(); return null;
$q = "SELECT COUNT(*) FROM PackageComments ";
$q.= "WHERE PackageBaseID = " . $base_id;
$q.= " AND DelUsersID IS NULL";
} }
$dbh = DB::connect();
$q = "SELECT COUNT(*) FROM PackageComments ";
$q.= "WHERE PackageBaseID = " . $base_id . " ";
$q.= "AND DelUsersID IS NULL";
$result = $dbh->query($q); $result = $dbh->query($q);
if (!$result) { if (!$result) {
return; return null;
} }
$row = $result->fetch(PDO::FETCH_NUM); return $result->fetchColumn(0);
return $row[0];
} }
/** /**