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

View File

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