Get time since report has been created

This commit is contained in:
Keir Nellyer 2016-06-30 17:23:29 -04:00
parent c076a46078
commit 7db7c0914e
3 changed files with 90 additions and 17 deletions

View File

@ -9,7 +9,7 @@
/** @var User */
private $suspect;
/** @var SplObjectStorage */
/** @var ReporterReason[] */
private $reporters;
/** @var Int */
@ -20,7 +20,7 @@
* @param Int $id
* @param User|Null $handler
* @param User $suspect
* @param SplObjectStorage $reporters
* @param ReporterReason[] $reporters
* @param Int $category
*/
function __construct($id, $handler, $suspect, $reporters, $category)
@ -32,6 +32,34 @@
$this->category = $category;
}
/**
* @return DateTime
*/
public function getTimeCreated()
{
return $this->getOldestReport()->getTime();
}
/**
* @return ReporterReason
*/
private function getOldestReport()
{
/** @var ReporterReason $oldestReason */
$oldestReason = null;
foreach ($this->reporters as $reason)
{
// TODO: confirm this does indeed get the oldest report
if ($oldestReason == null || $reason->getTime()->diff($oldestReason->getTime()) < 0)
{
$oldestReason = $reason;
}
}
return $oldestReason;
}
/**
* @return Int
*/
@ -57,7 +85,7 @@
}
/**
* @return SplObjectStorage
* @return ReporterReason[]
*/
public function getReporters()
{

View File

@ -0,0 +1,42 @@
<?php class ReporterReason
{
private $user;
private $time;
private $reason;
/**
* @param User $user
* @param DateTime $time
* @param String $reason
*/
function __construct($user, $time, $reason)
{
$this->user = $user;
$this->time = $time;
$this->reason = $reason;
}
/**
* @return User
*/
public function getUser()
{
return $this->user;
}
/**
* @return DateTime
*/
public function getTime()
{
return $this->time;
}
/**
* @return String
*/
public function getReason()
{
return $this->reason;
}
}

View File

@ -4,6 +4,7 @@ require_once('snapshot.php');
require_once('report.php');
require_once('message.php');
require_once('user.php');
require_once('reporter_reason.php');
const CATEGORIES = array(
0 => 'Global',
@ -235,23 +236,26 @@ function getUser($id)
}
}
/**
* @param int $reportId
* @return ReporterReason[]
*/
function getReporters($reportId)
{
$connection = getConnection("ACCOUNT");
$statement = $connection->prepare("SELECT reporterId, reason FROM reportReasons WHERE reportId = ?");
$reportReasons = new SplObjectStorage();
$statement = $connection->prepare("SELECT reporterId, `time`, reason FROM reportReasons WHERE reportId = ?");
$reportReasons = array();
try
{
$statement->bind_param('i', $reportId);
$statement->execute();
$statement->bind_result($reporterId, $reason);
$statement->bind_result($reporterId, $time, $reason);
$statement->store_result(); // prevents issues with other queries running before this statement is closed
while ($statement->fetch())
{
$reporterUser = getUser($reporterId);
$reportReasons[$reporterUser] = $reason;
$reportReasons[$reporterId] = new ReporterReason(getUser($reporterId), new DateTime($time), $reason);
}
}
finally
@ -272,8 +276,9 @@ function getInvolvedUsers($snapshot, $report)
$involvedUsers = $snapshot->getPlayers();
$involvedUsers[$report->getSuspect()->getId()] = $report->getSuspect();
/** @var User $reporter */
foreach ($report->getReporters() as $reporter) {
/** @var ReporterReason $reporter */
foreach ($report->getReporters() as $reporterReason) {
$reporter = $reporterReason->getUser();
$involvedUsers[$reporter->getId()] = $reporter;
}
@ -435,17 +440,15 @@ if ($validId)
// Put all reporter usernames in array for easy access later
$reporterUsernames = array();
foreach ($report->getReporters() as $reporter)
foreach ($report->getReporters() as $reporterReason)
{
$reporterUsernames[count($reporterUsernames)] = $reporter->getUsername();
$reporterUsernames[count($reporterUsernames)] = $reporterReason->getUser()->getUsername();
}
$involvedUsers = getInvolvedUsers($snapshot, $report);
// TODO Calculate time since last report
// TODO actually calculate time
$lastReportTime = new DateTime('1999-01-12');
$age = approximateHumanInterval($lastReportTime->diff(new DateTime('now', $lastReportTime->getTimezone())));
$reportCreationTime = $report->getTimeCreated();
$age = approximateHumanInterval($reportCreationTime->diff(new DateTime('now', $reportCreationTime->getTimezone())));
if ($displayAmount == 0): ?>
<span class="black">No chat log available for this report.</span>
@ -481,7 +484,7 @@ if ($validId)
<div class="row">
<div class="col-lg-12">
<i class="fa fa-clock-o fa-fw"></i>
<span class="label label-pill label-default" title="Last Report: <?= $lastReportTime->format('Y/m/d H:i:s T') ?>"><?= $age . ' ago' ?></span>
<span class="label label-pill label-default" title="Last Report: <?= $reportCreationTime->format('Y/m/d H:i:s T') ?>"><?= $age . ' ago' ?></span>
<br>
<i class="fa fa-user-plus fa-fw"></i>