diff options
author | Lukas Fleischer <archlinux@cryptocrack.de> | 2012-03-01 16:31:20 +0100 |
---|---|---|
committer | Lukas Fleischer <archlinux@cryptocrack.de> | 2012-07-06 11:25:28 +0200 |
commit | 9e9820ff5877f6b0a9c3c2be5127517b9f05a327 (patch) | |
tree | 38496f7e131c9544c2940165bcd76fffe9d25c75 /web | |
parent | 937cda9ccb5437ff956c04ef8cdb948f19c0d7a4 (diff) | |
download | aur-9e9820ff5877f6b0a9c3c2be5127517b9f05a327.tar.gz aur-9e9820ff5877f6b0a9c3c2be5127517b9f05a327.tar.xz |
Extend pkgname_from_id() to arrays of IDs
This allows for getting the package names of multiple packages at once,
without having to iterate over them and making one DB query per package.
pkgname_from_id() now accepts both integer arrays and single integers
(backwards compatibility mode).
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
Diffstat (limited to 'web')
-rw-r--r-- | web/lib/pkgfuncs.inc.php | 29 |
1 files changed, 23 insertions, 6 deletions
diff --git a/web/lib/pkgfuncs.inc.php b/web/lib/pkgfuncs.inc.php index ef9d461d..2dcbec8e 100644 --- a/web/lib/pkgfuncs.inc.php +++ b/web/lib/pkgfuncs.inc.php @@ -269,20 +269,37 @@ function pkgnotify_from_sid($sid="", $dbh=NULL) { # get name of package based on pkgid # -function pkgname_from_id($pkgid, $dbh=NULL) { - $pkgid = intval($pkgid); - $name = ""; - if ($pkgid > 0) { +function pkgname_from_id($pkgids, $dbh=NULL) { + if (is_array($pkgids)) { + $pkgids = sanitize_ids($pkgids); + $names = array(); if(!$dbh) { $dbh = db_connect(); } - $q = "SELECT Name FROM Packages WHERE ID = " . $pkgid; + $q = "SELECT Name FROM Packages WHERE ID IN (" . + implode(",", $pkgids) . ")"; + $result = db_query($q, $dbh); + if (mysql_num_rows($result) > 0) { + while ($row = mysql_fetch_assoc($result)) { + $names[] = $row['Name']; + } + } + return $names; + } + elseif ($pkgids > 0) { + if(!$dbh) { + $dbh = db_connect(); + } + $q = "SELECT Name FROM Packages WHERE ID = " . $pkgids; $result = db_query($q, $dbh); if (mysql_num_rows($result) > 0) { $name = mysql_result($result, 0); } + return $name; + } + else { + return NULL; } - return $name; } # Check if a package name is blacklisted. |