Update chat snap site for backend changes

This commit is contained in:
Keir Nellyer 2016-08-29 12:21:57 +01:00
parent 022e9f6bd4
commit b30f395d88
2 changed files with 38 additions and 18 deletions

View File

@ -15,6 +15,9 @@
/** @var Int */ /** @var Int */
private $category; private $category;
/** @var Snapshot */
private $snapshot;
/** /**
* Report constructor. * Report constructor.
* @param Int $id * @param Int $id
@ -22,14 +25,16 @@
* @param User $suspect * @param User $suspect
* @param UserReport[] $reporters * @param UserReport[] $reporters
* @param Int $category * @param Int $category
* @param Snapshot $snapshot
*/ */
function __construct($id, $handler, $suspect, $reporters, $category) function __construct($id, $handler, $suspect, $reporters, $category, $snapshot)
{ {
$this->id = $id; $this->id = $id;
$this->handler = $handler; $this->handler = $handler;
$this->suspect = $suspect; $this->suspect = $suspect;
$this->reporters = $reporters; $this->reporters = $reporters;
$this->category = $category; $this->category = $category;
$this->snapshot = $snapshot;
} }
/** /**
@ -98,4 +103,12 @@
{ {
return $this->category; return $this->category;
} }
/**
* @return Snapshot
*/
public function getSnapshot()
{
return $this->snapshot;
}
} }

View File

@ -89,7 +89,7 @@
function getReport($reportId) function getReport($reportId)
{ {
$connection = getConnection("ACCOUNT"); $connection = getConnection("ACCOUNT");
$statement = $connection->prepare('SELECT reports.suspectId, reports.categoryId, reportHandlers.handlerId FROM reports $statement = $connection->prepare('SELECT reports.suspectId, reports.categoryId, reports.snapshotId, reportHandlers.handlerId FROM reports
LEFT JOIN reportHandlers ON reports.id = reportHandlers.reportId AND reportHandlers.aborted IS FALSE LEFT JOIN reportHandlers ON reports.id = reportHandlers.reportId AND reportHandlers.aborted IS FALSE
LEFT JOIN reportResults ON reports.id = reportResults.reportId LEFT JOIN reportResults ON reports.id = reportResults.reportId
WHERE reports.id = ?;'); WHERE reports.id = ?;');
@ -97,20 +97,26 @@
$statement->bind_param('i', $reportId); $statement->bind_param('i', $reportId);
$statement->execute(); $statement->execute();
$statement->store_result(); $statement->store_result();
$statement->bind_result($suspectId, $categoryId, $handlerId); $statement->bind_result($suspectId, $categoryId, $snapshotId, $handlerId);
if ($statement->fetch()) if ($statement->fetch())
{ {
$suspectUser = getUser($suspectId); $suspectUser = getUser($suspectId);
$reportReasons = getReporters($reportId); $reportReasons = getReporters($reportId);
$snapshot = null;
$handlerUser = null; $handlerUser = null;
if (!is_null($snapshotId))
{
$snapshot = getSnapshot($snapshotId);
}
if (!is_null($handlerId)) if (!is_null($handlerId))
{ {
$handlerUser = getUser($handlerId); $handlerUser = getUser($handlerId);
} }
return new Report($reportId, $handlerUser, $suspectUser, $reportReasons, $categoryId); return new Report($reportId, $handlerUser, $suspectUser, $reportReasons, $categoryId, $snapshot);
} }
$statement->close(); $statement->close();
@ -118,24 +124,25 @@
return null; return null;
} }
function getSnapshot($reportId) function getSnapshot($messageId)
{ {
/** @var $messages Message[] */ /** @var $messages Message[] */
$messages = array(); $messages = array();
$connection = getConnection("ACCOUNT"); $connection = getConnection("ACCOUNT");
$statement = $connection->prepare("SELECT id, senderId, snapshotType, `server`, `time`, message FROM reportSnapshots, snapshots $statement = $connection->prepare("SELECT messageId, senderId, snapshotType, `server`, `time`, message FROM snapshots, snapshotMessages, snapshotMessageMap
WHERE snapshots.id = reportSnapshots.snapshotId WHERE snapshotMessageMap.snapshotId = snapshots.id
AND reportSnapshots.reportId = ?"); AND snapshotMessages.id = snapshotMessageMap.messageId
AND snapshots.id = ?;");
$statement->bind_param('i', $reportId); $statement->bind_param('i', $messageId);
$statement->execute(); $statement->execute();
$statement->bind_result($snapshotId, $senderId, $snapshotType, $server, $time, $message); $statement->bind_result($messageId, $senderId, $snapshotType, $server, $time, $message);
$statement->store_result(); $statement->store_result();
while ($statement->fetch()) while ($statement->fetch())
{ {
$recipients = getUsers(getSnapshotRecipients($snapshotId)); $recipients = getUsers(getMessageRecipients($messageId));
$message = new Message(getUser($senderId), $recipients, $time, $snapshotType, $message, $server); $message = new Message(getUser($senderId), $recipients, $time, $snapshotType, $message, $server);
array_push($messages, $message); array_push($messages, $message);
} }
@ -154,20 +161,20 @@
} }
} }
return new Snapshot($reportId, $messages, $snapshotUsers); return new Snapshot($messageId, $messages, $snapshotUsers);
} }
/** /**
* @param $snapshotId * @param $messageId
* @return Integer[] array * @return Integer[] array
*/ */
function getSnapshotRecipients($snapshotId) function getMessageRecipients($messageId)
{ {
$recipientIds = array(); $recipientIds = array();
$connection = getConnection("ACCOUNT"); $connection = getConnection("ACCOUNT");
$statement = $connection->prepare("SELECT recipientId FROM snapshotRecipients WHERE snapshotId = ?"); $statement = $connection->prepare("SELECT recipientId FROM snapshotRecipients WHERE messageId = ?");
$statement->bind_param('i', $snapshotId); $statement->bind_param('i', $messageId);
$statement->execute(); $statement->execute();
$statement->bind_result($recipientId); $statement->bind_result($recipientId);
@ -364,7 +371,7 @@
if ($report) if ($report)
{ {
$snapshot = getSnapshot($id); $snapshot = $report->getSnapshot();
} }
else else
{ {
@ -400,7 +407,7 @@
<div id="search"> <div id="search">
<form id="id-input" name="id-input" action="view.php" method="get"> <form id="id-input" name="id-input" action="view.php" method="get">
<div class="input-group"> <div class="input-group">
<input name="id" type="text" class="form-control" placeholder="Enter report id..."> <input name="id" type="text" class="form-control" placeholder="Enter snapshot id...">
<span class="input-group-btn"> <span class="input-group-btn">
<button class="btn btn-secondary" type="submit" form="id-input"><i class="fa fa-search"></i> Search</button> <button class="btn btn-secondary" type="submit" form="id-input"><i class="fa fa-search"></i> Search</button>
</span> </span>