Update the web side to handle to handle the new changes.

This commit is contained in:
Keir 2015-12-15 21:36:54 +00:00
parent 6d9bcb8e66
commit 1042032836
3 changed files with 52 additions and 32 deletions

View File

@ -6,9 +6,12 @@
/** @var Player[] */
private $recipients;
/** @var Int */
/** @var DateTime */
private $timestamp;
/** @var String */
private $type;
/** @var String */
private $message;
@ -16,14 +19,16 @@
* Message constructor.
* @param Player $sender
* @param Player[] $recipients
* @param Int $timestamp
* @param String $message
* @param DateTime $dateTime
* @param String $type
* @param Message
*/
function Message($sender, $recipients, $timestamp, $message)
function Message($sender, $recipients, $dateTime, $type, $message)
{
$this->sender = $sender;
$this->recipients = $recipients;
$this->timestamp = $timestamp;
$this->timestamp = $dateTime;
$this->type = $type;
$this->message = $message;
}
@ -44,13 +49,18 @@
}
/**
* @return Int
* @return DateTime
*/
public function getTimestamp()
{
return $this->timestamp;
}
public function getType()
{
return $this->type;
}
/**
* @return String
*/

View File

@ -6,6 +6,9 @@ require_once('player.php');
$dataDir = 'data/';
// In Java this is "DateTimeFormatter.ISO_LOCAL_DATE_TIME"
$jsonDateTimeFormat = 'Y-m-d\TH:i:s';
// ID corresponds to the Report ID
if (!isset($_GET['identifier']) || empty($_GET['identifier']))
{
@ -53,7 +56,7 @@ function displayMessages($snapshot)
function getMessageHTML($message)
{
$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)
{
$timezone = new DateTimeZone($snapshotData["timezone"]);
$players = toPlayers($snapshotData['usernames']);
$messages = toMessages($players, $snapshotData['snapshots']);
$timeGenerated = $snapshotData["time_generated"];
return new Snapshot($identifier, $messages, $players, $timeGenerated);
$messages = toMessages($players, $snapshotData['snapshots'], $timezone);
$generated = parseDateTime($snapshotData["generated"], $timezone);
return new Snapshot($identifier, $messages, $players, $generated);
}
/**
* @param Player[] $players
* @param array $messagesData Messages data array.
* @param DateTimeZone $timezone
* @return Message[]
*/
function toMessages($players, $messagesData)
function toMessages($players, $messagesData, $timezone)
{
$messages = array();
for ($i = 0; $i < count($messagesData); $i++)
{
$messages[$i] = getMessage($players, $messagesData[$i]);
$messages[$i] = getMessage($players, $messagesData[$i], $timezone);
}
return $messages;
@ -89,16 +94,18 @@ function toMessages($players, $messagesData)
/**
* @param Player[] $players
* @param array $messageData Message data array.
* @param DateTimeZone $timezone
* @return Message
*/
function getMessage($players, $messageData)
function getMessage($players, $messageData, $timezone)
{
$sender = getPlayer($players, $messageData['sender']);
$recipients = getPlayersFromUUIDs($players, $messageData['recipients']);
$timestamp = $messageData['time'];
$dateTime = parseDateTime($messageData['time'], $timezone);
$type = $messageData['type'];
$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
* @return String
@ -169,17 +187,6 @@ function removeBadCharacters($input)
<body>
<?php
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>
</body>

View File

@ -10,22 +10,22 @@
/** @var Player[] */
private $players; // String UUID as Key
/** @var Int */
private $timeGenerated;
/** @var DateTime */
private $generated;
/**
* Snapshot constructor.
* @param String $identifier
* @param Message[] $messages
* @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->messages = $messages;
$this->players = $players;
$this->timeGenerated = $timeGenerated;
$this->generated = $generated;
}
/**
@ -52,8 +52,11 @@
return $this->players;
}
/**
* @return DateTime
*/
public function getTimeGenerated()
{
return $this->timeGenerated;
return $this->generated;
}
}