Pro-tip: Always make sure you read Trello before adding a feature (un-doing pagination).
This commit is contained in:
parent
af8ad218be
commit
c9b343a1fb
@ -6,7 +6,6 @@ require_once('message.php');
|
||||
require_once('player.php');
|
||||
|
||||
const dataDir = 'data/';
|
||||
const messagesPerPage = 5;
|
||||
|
||||
// In Java this is "DateTimeFormatter.ISO_LOCAL_DATE_TIME"
|
||||
const jsonDateTimeFormat = 'Y-m-d\TH:i:s';
|
||||
@ -221,6 +220,7 @@ function parseDateTime($dateTime, $timezone)
|
||||
return DateTime::createFromFormat(jsonDateTimeFormat, $dateTime, $timezone);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Converts an interval to minutes, days or months, depending on the size.
|
||||
*
|
||||
@ -249,77 +249,6 @@ function approximateHumanInterval($interval)
|
||||
return $humanString;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
* @return string
|
||||
*/
|
||||
function htmlPreviousLink($page)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
if ($page != 0)
|
||||
{
|
||||
$vars = $_GET;
|
||||
$vars['page'] = $page - 1;
|
||||
$html = '<a href=?' . http_build_query($vars) . '>Previous</a>';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
* @param int $maxPage
|
||||
* @return string
|
||||
*/
|
||||
function htmlNextLink($page, $maxPage)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
if ($page < $maxPage)
|
||||
{
|
||||
$vars = $_GET;
|
||||
$vars['page'] = $page + 1;
|
||||
$html = '<a href=?' . http_build_query($vars) . '>Next</a> ';
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $page
|
||||
* @param int $maxPage
|
||||
* @return string
|
||||
*/
|
||||
function htmlPageNumbers($page, $maxPage)
|
||||
{
|
||||
$html = '';
|
||||
|
||||
for ($i = 0; $i <= $maxPage; $i++)
|
||||
{
|
||||
if (!empty($html))
|
||||
{
|
||||
$html .= ' ';
|
||||
}
|
||||
|
||||
$humanPage = $i + 1;
|
||||
$currPage = $i == $page;
|
||||
|
||||
if (!$currPage)
|
||||
{
|
||||
$vars = $_GET;
|
||||
$vars['page'] = $i;
|
||||
$html .= '<a href=?' . http_build_query($vars) . '>' . $humanPage . '</a>';
|
||||
}
|
||||
else
|
||||
{
|
||||
$html .= '<span style="font-weight:bold">' . $humanPage . '</span>';
|
||||
}
|
||||
}
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param String $input
|
||||
* @return String
|
||||
@ -330,14 +259,12 @@ function removeBadCharacters($input)
|
||||
}
|
||||
|
||||
$validIdentifier = isset($_GET['identifier']);
|
||||
$page = isset($_GET['page']) ? $_GET['page'] : 0;
|
||||
$error = "";
|
||||
$identifierError = "";
|
||||
|
||||
$identifier = null;
|
||||
$filePath = null;
|
||||
$snapshot = null;
|
||||
$report = null;
|
||||
$maxPage = null;
|
||||
|
||||
if ($validIdentifier)
|
||||
{
|
||||
@ -350,16 +277,11 @@ if ($validIdentifier)
|
||||
$dataArray = toDataArray($filePath);
|
||||
$snapshot = toSnapshot($identifier, $dataArray);
|
||||
$report = toReport($dataArray['report'], $snapshot->getPlayers());
|
||||
$maxPage = ceil(count($snapshot->getMessages()) / messagesPerPage) - 1;
|
||||
|
||||
if ($page > $maxPage) {
|
||||
$error = "Invalid page number.";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$validIdentifier = false;
|
||||
$error = "Invalid identifier.";
|
||||
$identifierError = "Invalid identifier.";
|
||||
}
|
||||
}
|
||||
?>
|
||||
@ -406,11 +328,11 @@ if ($validIdentifier)
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($error)) { ?>
|
||||
<?php if (isset($_GET['identifier']) && !$validIdentifier && !empty($identifierError)) { ?>
|
||||
<div id="content" class="center-block" style="text-align: center; background-color: rgba(204, 34, 42, 0.52);">
|
||||
<p class="error-oh-no" style="font-size: 60px;">What did you do?!?!?</p>
|
||||
<img src="img/shaun.gif" />
|
||||
<p class="error-oh-no" style="font-size: 40px;">Error: <?= $error ?></p>
|
||||
<p class="error-oh-no" style="font-size: 40px;">Error: <?= $identifierError ?></p>
|
||||
<br>
|
||||
</div>
|
||||
<?php } else { ?>
|
||||
@ -434,16 +356,7 @@ if ($validIdentifier)
|
||||
<?php
|
||||
$messages = $snapshot->getMessages();
|
||||
|
||||
$startIndex = $page * messagesPerPage;
|
||||
$endIndex = $startIndex + messagesPerPage;
|
||||
|
||||
if ($endIndex > count($messages)) {
|
||||
$endIndex = count($messages);
|
||||
}
|
||||
|
||||
for ($i = $startIndex; $i < $endIndex; $i++) {
|
||||
$message = $messages[$i];
|
||||
|
||||
foreach($messages as $message):
|
||||
$typeId = $message->getType();
|
||||
$typeDisplayName = Message::$TYPE_DISPLAY_NAMES[$typeId];
|
||||
$isPM = $typeId == Message::TYPE_PM;
|
||||
@ -455,19 +368,10 @@ if ($validIdentifier)
|
||||
<span class="label <?php if($isPM) echo "label-primary chat pm"; else echo "label-info chat"; ?>" style="font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;"><?= $typeDisplayName ?></span>
|
||||
<span class="black"><?= $involved; ?>:</span> <?= $message->getMessage(); ?>
|
||||
|
||||
<?php if ($i != $endIndex){ // Don't break on the last element ?>
|
||||
<br>
|
||||
<?php } ?>
|
||||
<?php if ($message != end($messages)){ // Don't break on the last element ?>
|
||||
<br>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div>
|
||||
<?php
|
||||
// TODO separate these into 3 divs aligned bottom-centre
|
||||
// this ensures these links are in the same place every time
|
||||
echo htmlPreviousLink($page);
|
||||
echo htmlPageNumbers($page, $maxPage);
|
||||
echo htmlNextLink($page, $maxPage);
|
||||
?>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
<div id="users" class="col-lg-5">
|
||||
@ -539,7 +443,7 @@ if ($validIdentifier)
|
||||
</body>
|
||||
</html>
|
||||
<?php
|
||||
foreach ($connections as $connection) {
|
||||
$connection->close();
|
||||
}
|
||||
foreach ($connections as $connection) {
|
||||
$connection->close();
|
||||
}
|
||||
?>
|
||||
|
Loading…
Reference in New Issue
Block a user