Further optimize voters.php to only need the package name

* Extends changes in 81d4cc13dc
* Modify getvotes() to use the package name rather than package ID
* Rename getvotes() to votes_for_pkgname() for clarity with new changes
* Modify routing framework and links to now use package names for voters.php

Signed-off-by: canyonknight <canyonknight@gmail.com>
Signed-off-by: Lukas Fleischer <archlinux@cryptocrack.de>
This commit is contained in:
canyonknight 2014-01-20 20:42:44 -05:00 committed by Lukas Fleischer
parent 81d4cc13dc
commit 1e9d539acf
4 changed files with 10 additions and 9 deletions

View file

@ -56,7 +56,7 @@ if (!empty($tokens[1]) && '/' . $tokens[1] == get_pkg_route()) {
include('pkgmerge.php'); include('pkgmerge.php');
return; return;
case "voters": case "voters":
$_GET['ID'] = pkgid_from_name($tokens[2]); $_GET['N'] = $tokens[2];
include('voters.php'); include('voters.php');
return; return;
default: default:

View file

@ -4,8 +4,8 @@ include_once('aur.inc.php');
include_once('pkgfuncs.inc.php'); include_once('pkgfuncs.inc.php');
$SID = $_COOKIE['AURSID']; $SID = $_COOKIE['AURSID'];
$pkgname = pkgname_from_id(intval($_GET['ID']); $pkgname = htmlspecialchars($_GET['N']);
$votes = getvotes($pkgid); $votes = votes_for_pkgname($pkgname);
$atype = account_from_sid($SID); $atype = account_from_sid($SID);
html_header(__("Voters")); html_header(__("Voters"));

View file

@ -1075,16 +1075,17 @@ function pkg_vote ($atype, $ids, $action=true) {
/** /**
* Get all usernames and IDs that voted for a specific package * Get all usernames and IDs that voted for a specific package
* *
* @param string $pkgid The package ID to get all votes for * @param string $pkgname The name of the package to retrieve votes for
* *
* @return array User IDs and usernames that voted for a specific package * @return array User IDs and usernames that voted for a specific package
*/ */
function getvotes($pkgid) { function votes_for_pkgname($pkgname) {
$dbh = DB::connect(); $dbh = DB::connect();
$q = "SELECT UsersID,Username FROM PackageVotes "; $q = "SELECT UsersID,Username,Name FROM PackageVotes ";
$q.= "LEFT JOIN Users on (UsersID = ID) "; $q.= "LEFT JOIN Users on (UsersID = Users.ID) ";
$q.= "WHERE PackageID = ". $dbh->quote($pkgid) . " "; $q.= "LEFT JOIN Packages on (PackageID = Packages.ID) ";
$q.= "WHERE Name = ". $dbh->quote($pkgname) . " ";
$q.= "ORDER BY Username"; $q.= "ORDER BY Username";
$result = $dbh->query($q); $result = $dbh->query($q);

View file

@ -194,7 +194,7 @@ if ($row["MaintainerUID"]):
<?php if ($USE_VIRTUAL_URLS): ?> <?php if ($USE_VIRTUAL_URLS): ?>
<td><a href="<?= get_pkg_uri($row['Name']); ?>voters/"><?= $votes ?></a></td> <td><a href="<?= get_pkg_uri($row['Name']); ?>voters/"><?= $votes ?></a></td>
<?php else: ?> <?php else: ?>
<td><a href="<?= get_uri('/voters/'); ?>?ID=<?= $pkgid ?>"><?= $votes ?></a></td> <td><a href="<?= get_uri('/voters/'); ?>?N=<?= htmlspecialchars($row['Name'], ENT_QUOTES) ?>"><?= $votes ?></a></td>
<?php endif; ?> <?php endif; ?>
<?php else: ?> <?php else: ?>
<td><?= $votes ?></td> <td><?= $votes ?></td>