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

View File

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