Added support for WhoKarma

This commit is contained in:
Max Klaversma 2014-05-01 00:19:35 +02:00 committed by Steffen Schröder
parent a9db406f9a
commit 84e01f5694

View File

@ -557,7 +557,29 @@ class KarmaPlugin implements CallbackListener, TimerListener, Plugin {
* @return array * @return array
*/ */
public function getMapPlayerVotes(Map $map) { public function getMapPlayerVotes(Map $map) {
$mysqli = $this->maniaControl->database->mysqli;
$query = "SELECT * FROM `" . self::TABLE_KARMA . "`
WHERE `mapIndex` = {$map->index}
AND `vote` >= 0";
$result = $mysqli->query($query);
if ($mysqli->error) {
trigger_error($mysqli->error);
return false;
}
$votes = array();
while($vote = $result->fetch_object()) {
$player = $this->maniaControl->playerManager->getPlayerByIndex($vote->playerIndex);
$karma = $vote->vote;
$votes[] = array('player' => $player, 'karma' => $karma);
}
usort($votes, function($a, $b) {
return $a['karma'] - $b['karma'];
});
$votes = array_reverse($votes);
return $votes;
} }
/** /**