Add staffhistory implementation and links

This commit is contained in:
ruan 2015-09-20 13:23:22 +02:00
parent 7cfa109b95
commit 17f13948f0
2 changed files with 45 additions and 20 deletions

View File

@ -16,17 +16,18 @@ class History {
* @param array $array
* @param string $type
* @param string $uuid
* @param string $field
* @param array $counts
*/
static function push($page, &$array, $type, $uuid, &$counts) {
static function push($page, &$array, $type, $uuid, $field, &$counts) {
$table = $page->settings->table[$type];
$count_st = $page->conn->prepare("SELECT COUNT(*) AS count FROM $table WHERE uuid=:uuid");
$count_st = $page->conn->prepare("SELECT COUNT(*) AS count FROM $table WHERE $field=:uuid");
$count_st->bindParam(":uuid", $uuid, PDO::PARAM_STR);
if ($count_st->execute() && ($row = $count_st->fetch()) !== null) {
$counts[$type] = $row['count'];
}
$st = $page->conn->prepare("SELECT * FROM $table WHERE uuid=:uuid ORDER BY time");
$st = $page->conn->prepare("SELECT * FROM $table WHERE $field=:uuid ORDER BY time");
$st->bindParam(":uuid", $uuid, PDO::PARAM_STR);
// Incompatible with pager as rows are usort()'d
@ -62,6 +63,8 @@ if (!isset($_GET['uuid'])) {
die("Missing arguments (uuid).");
}
$staffhistory = (isset($_GET['staffhistory']) && $_GET['staffhistory'] === "1");
$uuid = $_GET['uuid'];
$name = $page->get_name($uuid);
@ -69,7 +72,13 @@ if ($name === null) {
die("Player not found in database.");
}
if ($staffhistory) {
$page->name = "Recent Punishments by $name";
} else {
$page->name = "Recent Punishments for $name";
}
$page->print_title();
$page->print_page_header();
@ -91,10 +100,15 @@ try {
$all = array();
$counts = array();
History::push($page, $all, 'bans', $uuid, $counts);
History::push($page, $all, 'mutes', $uuid, $counts);
History::push($page, $all, 'warnings', $uuid, $counts);
History::push($page, $all, 'kicks', $uuid, $counts);
$field = "uuid";
if ($staffhistory) {
$field = "banned_by_uuid";
}
History::push($page, $all, 'bans', $uuid, $field, $counts);
History::push($page, $all, 'mutes', $uuid, $field, $counts);
History::push($page, $all, 'warnings', $uuid, $field, $counts);
History::push($page, $all, 'kicks', $uuid, $field, $counts);
$total = 0;
foreach ($counts as $count) {
@ -135,7 +149,7 @@ try {
$page->print_table_rows($row, array(
'Type' => $label,
'Player' => $page->get_avatar($name, $row['uuid']),
'Player' => $page->get_avatar($page->get_name($row['uuid']), $row['uuid']),
'Moderator' => $page->get_avatar($page->get_banner_name($row), $row['banned_by_uuid']),
'Reason' => $page->clean($row['reason']),
'Date' => $page->millis_to_date($row['time']),
@ -151,6 +165,9 @@ try {
if ($from !== null) {
$args .= "&from=$from";
}
if ($staffhistory) {
$args .= "&staffhistory=1";
}
$page->print_pager($total, $args);
}
} else {

View File

@ -38,9 +38,17 @@ abstract class Info {
return $this->row['until'] <= 0;
}
function history_link($player_name, $row) {
$uuid = $row['uuid'];
return "<a href=\"history.php?uuid=$uuid\">$player_name</a>";
function history_link($player_name, $uuid, $args = "") {
return "<a href=\"history.php?uuid=$uuid$args\">$player_name</a>";
}
function punished_avatar($player_name, $row) {
return $this->page->get_avatar($player_name, $row['uuid'], false, $this->history_link($player_name, $row['uuid']));
}
function moderator_avatar($row) {
$banner_name = $this->page->get_banner_name($row);
return $this->page->get_avatar($banner_name, $row['banned_by_uuid'], false, $this->history_link($banner_name, $row['banned_by_uuid'], "&staffhistory=1"));
}
abstract function basic_info($row, $player_name);
@ -50,8 +58,8 @@ class BanInfo extends Info {
function basic_info($row, $player_name) {
$page = $this->page;
return array(
'Banned Player' => $page->get_avatar($player_name, $row['uuid'], false, $this->history_link($player_name, $row)),
'Banned By' => $page->get_avatar($page->get_banner_name($row), $row['banned_by_uuid'], false),
'Banned Player' => $this->punished_avatar($player_name, $row),
'Banned By' => $this->moderator_avatar($row),
'Ban Reason' => $page->clean($row['reason']),
'Ban Placed' => $page->millis_to_date($row['time']),
'Expires' => $page->expiry($row),
@ -63,8 +71,8 @@ class MuteInfo extends Info {
function basic_info($row, $player_name) {
$page = $this->page;
return array(
'Muted Player' => $page->get_avatar($player_name, $row['uuid'], false, $this->history_link($player_name, $row)),
'Muted By' => $page->get_avatar($page->get_banner_name($row), $row['banned_by_uuid'], false),
'Muted Player' => $this->punished_avatar($player_name, $row),
'Muted By' => $this->moderator_avatar($row),
'Mute Reason' => $page->clean($row['reason']),
'Mute Placed' => $page->millis_to_date($row['time']),
'Expires' => $page->expiry($row),
@ -80,8 +88,8 @@ class WarnInfo extends Info {
function basic_info($row, $player_name) {
$page = $this->page;
return array(
'Warned Player' => $page->get_avatar($player_name, $row['uuid'], false, $this->history_link($player_name, $row)),
'Warned By' => $page->get_avatar($page->get_banner_name($row), $row['banned_by_uuid'], false),
'Warned Player' => $this->punished_avatar($player_name, $row),
'Warned By' => $this->moderator_avatar($row),
'Warning Reason' => $page->clean($row['reason']),
'Warning Placed' => $page->millis_to_date($row['time']),
'Expires' => $page->expiry($row),
@ -93,8 +101,8 @@ class KickInfo extends Info {
function basic_info($row, $player_name) {
$page = $this->page;
return array(
'Kicked Player' => $page->get_avatar($player_name, $row['uuid'], false, $this->history_link($player_name, $row)),
'Kicked By' => $page->get_avatar($page->get_banner_name($row), $row['banned_by_uuid'], false),
'Kicked Player' => $this->punished_avatar($player_name, $row),
'Kicked By' => $this->moderator_avatar($row),
'Kick Reason' => $page->clean($row['reason']),
'Kick Date' => $page->millis_to_date($row['time']),
);