Update the web side to handle to handle the new changes.
This commit is contained in:
parent
6d9bcb8e66
commit
1042032836
@ -6,9 +6,12 @@
|
|||||||
/** @var Player[] */
|
/** @var Player[] */
|
||||||
private $recipients;
|
private $recipients;
|
||||||
|
|
||||||
/** @var Int */
|
/** @var DateTime */
|
||||||
private $timestamp;
|
private $timestamp;
|
||||||
|
|
||||||
|
/** @var String */
|
||||||
|
private $type;
|
||||||
|
|
||||||
/** @var String */
|
/** @var String */
|
||||||
private $message;
|
private $message;
|
||||||
|
|
||||||
@ -16,14 +19,16 @@
|
|||||||
* Message constructor.
|
* Message constructor.
|
||||||
* @param Player $sender
|
* @param Player $sender
|
||||||
* @param Player[] $recipients
|
* @param Player[] $recipients
|
||||||
* @param Int $timestamp
|
* @param DateTime $dateTime
|
||||||
* @param String $message
|
* @param String $type
|
||||||
|
* @param Message
|
||||||
*/
|
*/
|
||||||
function Message($sender, $recipients, $timestamp, $message)
|
function Message($sender, $recipients, $dateTime, $type, $message)
|
||||||
{
|
{
|
||||||
$this->sender = $sender;
|
$this->sender = $sender;
|
||||||
$this->recipients = $recipients;
|
$this->recipients = $recipients;
|
||||||
$this->timestamp = $timestamp;
|
$this->timestamp = $dateTime;
|
||||||
|
$this->type = $type;
|
||||||
$this->message = $message;
|
$this->message = $message;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,13 +49,18 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Int
|
* @return DateTime
|
||||||
*/
|
*/
|
||||||
public function getTimestamp()
|
public function getTimestamp()
|
||||||
{
|
{
|
||||||
return $this->timestamp;
|
return $this->timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return String
|
* @return String
|
||||||
*/
|
*/
|
||||||
|
@ -6,6 +6,9 @@ require_once('player.php');
|
|||||||
|
|
||||||
$dataDir = 'data/';
|
$dataDir = 'data/';
|
||||||
|
|
||||||
|
// In Java this is "DateTimeFormatter.ISO_LOCAL_DATE_TIME"
|
||||||
|
$jsonDateTimeFormat = 'Y-m-d\TH:i:s';
|
||||||
|
|
||||||
// ID corresponds to the Report ID
|
// ID corresponds to the Report ID
|
||||||
if (!isset($_GET['identifier']) || empty($_GET['identifier']))
|
if (!isset($_GET['identifier']) || empty($_GET['identifier']))
|
||||||
{
|
{
|
||||||
@ -53,7 +56,7 @@ function displayMessages($snapshot)
|
|||||||
function getMessageHTML($message)
|
function getMessageHTML($message)
|
||||||
{
|
{
|
||||||
$sender = $message->getSender();
|
$sender = $message->getSender();
|
||||||
return '<span data-player-uuid="' . $sender->getUUID() . '">' . $sender->getUsername() . '</span> - ' . $message->getMessage();
|
return '[' . $message->getType() . '] <span data-player-uuid="' . $sender->getUUID() . '">' . $sender->getUsername() . '</span> - ' . $message->getMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,24 +66,26 @@ function getMessageHTML($message)
|
|||||||
*/
|
*/
|
||||||
function toSnapshot($identifier, $snapshotData)
|
function toSnapshot($identifier, $snapshotData)
|
||||||
{
|
{
|
||||||
|
$timezone = new DateTimeZone($snapshotData["timezone"]);
|
||||||
$players = toPlayers($snapshotData['usernames']);
|
$players = toPlayers($snapshotData['usernames']);
|
||||||
$messages = toMessages($players, $snapshotData['snapshots']);
|
$messages = toMessages($players, $snapshotData['snapshots'], $timezone);
|
||||||
$timeGenerated = $snapshotData["time_generated"];
|
$generated = parseDateTime($snapshotData["generated"], $timezone);
|
||||||
return new Snapshot($identifier, $messages, $players, $timeGenerated);
|
return new Snapshot($identifier, $messages, $players, $generated);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Player[] $players
|
* @param Player[] $players
|
||||||
* @param array $messagesData Messages data array.
|
* @param array $messagesData Messages data array.
|
||||||
|
* @param DateTimeZone $timezone
|
||||||
* @return Message[]
|
* @return Message[]
|
||||||
*/
|
*/
|
||||||
function toMessages($players, $messagesData)
|
function toMessages($players, $messagesData, $timezone)
|
||||||
{
|
{
|
||||||
$messages = array();
|
$messages = array();
|
||||||
|
|
||||||
for ($i = 0; $i < count($messagesData); $i++)
|
for ($i = 0; $i < count($messagesData); $i++)
|
||||||
{
|
{
|
||||||
$messages[$i] = getMessage($players, $messagesData[$i]);
|
$messages[$i] = getMessage($players, $messagesData[$i], $timezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $messages;
|
return $messages;
|
||||||
@ -89,16 +94,18 @@ function toMessages($players, $messagesData)
|
|||||||
/**
|
/**
|
||||||
* @param Player[] $players
|
* @param Player[] $players
|
||||||
* @param array $messageData Message data array.
|
* @param array $messageData Message data array.
|
||||||
|
* @param DateTimeZone $timezone
|
||||||
* @return Message
|
* @return Message
|
||||||
*/
|
*/
|
||||||
function getMessage($players, $messageData)
|
function getMessage($players, $messageData, $timezone)
|
||||||
{
|
{
|
||||||
$sender = getPlayer($players, $messageData['sender']);
|
$sender = getPlayer($players, $messageData['sender']);
|
||||||
$recipients = getPlayersFromUUIDs($players, $messageData['recipients']);
|
$recipients = getPlayersFromUUIDs($players, $messageData['recipients']);
|
||||||
$timestamp = $messageData['time'];
|
$dateTime = parseDateTime($messageData['time'], $timezone);
|
||||||
|
$type = $messageData['type'];
|
||||||
$message = $messageData['message'];
|
$message = $messageData['message'];
|
||||||
|
|
||||||
return new Message($sender, $recipients, $timestamp, $message);
|
return new Message($sender, $recipients, $dateTime, $type, $message);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -153,6 +160,17 @@ function getPlayer($players, $uuid)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param String $dateTime
|
||||||
|
* @param DateTimeZone $timezone
|
||||||
|
* @return DateTime
|
||||||
|
*/
|
||||||
|
function parseDateTime($dateTime, $timezone)
|
||||||
|
{
|
||||||
|
global $jsonDateTimeFormat;
|
||||||
|
return DateTime::createFromFormat($jsonDateTimeFormat, $dateTime, $timezone);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param String $input
|
* @param String $input
|
||||||
* @return String
|
* @return String
|
||||||
@ -169,17 +187,6 @@ function removeBadCharacters($input)
|
|||||||
<body>
|
<body>
|
||||||
<?php
|
<?php
|
||||||
displayMessages($snapshot);
|
displayMessages($snapshot);
|
||||||
|
|
||||||
// convert to friendly date time
|
|
||||||
$seconds = $snapshot->getTimeGenerated() / 1000;
|
|
||||||
$friendlyDateTime = date('m/d/y \a\t h:ia', $seconds);
|
|
||||||
|
|
||||||
echo '<p>';
|
|
||||||
echo 'Snapshot taken at: ' . $friendlyDateTime;
|
|
||||||
echo '<br />';
|
|
||||||
echo 'Player names were valid at this time.';
|
|
||||||
echo '</p>';
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<script type="text/javascript" src="main.js"></script>
|
<script type="text/javascript" src="main.js"></script>
|
||||||
</body>
|
</body>
|
||||||
|
@ -10,22 +10,22 @@
|
|||||||
/** @var Player[] */
|
/** @var Player[] */
|
||||||
private $players; // String UUID as Key
|
private $players; // String UUID as Key
|
||||||
|
|
||||||
/** @var Int */
|
/** @var DateTime */
|
||||||
private $timeGenerated;
|
private $generated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Snapshot constructor.
|
* Snapshot constructor.
|
||||||
* @param String $identifier
|
* @param String $identifier
|
||||||
* @param Message[] $messages
|
* @param Message[] $messages
|
||||||
* @param Player[] $players
|
* @param Player[] $players
|
||||||
* @param Int $timeGenerated
|
* @param DateTime $generated
|
||||||
*/
|
*/
|
||||||
function Snapshot($identifier, $messages, $players, $timeGenerated)
|
function Snapshot($identifier, $messages, $players, $generated)
|
||||||
{
|
{
|
||||||
$this->identifier = $identifier;
|
$this->identifier = $identifier;
|
||||||
$this->messages = $messages;
|
$this->messages = $messages;
|
||||||
$this->players = $players;
|
$this->players = $players;
|
||||||
$this->timeGenerated = $timeGenerated;
|
$this->generated = $generated;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -52,8 +52,11 @@
|
|||||||
return $this->players;
|
return $this->players;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return DateTime
|
||||||
|
*/
|
||||||
public function getTimeGenerated()
|
public function getTimeGenerated()
|
||||||
{
|
{
|
||||||
return $this->timeGenerated;
|
return $this->generated;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user