Commit
This commit is contained in:
parent
76aca99ff0
commit
258135cd81
@ -55,18 +55,19 @@ class App
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Render given view
|
* Render given view
|
||||||
|
*
|
||||||
|
* Reason for the funky names is to avoid name conflicts
|
||||||
*/
|
*/
|
||||||
public function view(string $view, array $data = []): void
|
public function view(string $__VIEW, array $__DATA = []): void
|
||||||
{
|
{
|
||||||
// import variables into the current symbol table from an array
|
$__PATH = $this->dir . '/view/' . $__VIEW . '.php';
|
||||||
extract($data);
|
if (!file_exists($__PATH))
|
||||||
// require view file
|
|
||||||
$path = $this->dir . '/view/' . $view . '.php';
|
|
||||||
if (!file_exists($path))
|
|
||||||
{
|
{
|
||||||
throw new Exception("View does not exist");
|
throw new Exception("View does not exist");
|
||||||
}
|
}
|
||||||
require $path;
|
// import variables into the current symbol table from an array
|
||||||
|
extract($__DATA);
|
||||||
|
require $__PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1,41 +1,76 @@
|
|||||||
<?php
|
<?php
|
||||||
if (!isset($focused)) {
|
if (!isset($view))
|
||||||
$focused = FALSE;
|
{
|
||||||
|
$view = 'default';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
<div id="alertBox" class="alert danger hidden" role="alert"></div>
|
|
||||||
|
|
||||||
<?php if ($focused == FALSE): ?>
|
<?php if ($view == 'default' || $view == 'focused'): ?>
|
||||||
<h1>Resultater</h1>
|
|
||||||
<span class="float-right">[ <a class="info" href="?focused=1" target="_blank">Fokusert visning</a> ]</span>
|
|
||||||
<br>
|
|
||||||
<?php endif; ?>
|
|
||||||
|
|
||||||
<noscript>
|
<div id="alertBox" class="alert danger hidden" role="alert"></div>
|
||||||
Denne siden krever JavaScript
|
|
||||||
</noscript>
|
|
||||||
|
|
||||||
<div id="rankingTable">
|
<?php if ($view == 'default'): ?>
|
||||||
Laster inn...
|
<h1>Resultater</h1>
|
||||||
</div>
|
<p>Denne siden oppdateres automagisk.</p>
|
||||||
|
<span class="float-right">[ <a class="info" href="?view=focused" target="_blank">Fokusert visning</a> ]</span>
|
||||||
|
<span class="float-right">[ <a class="info" href="?view=summary">Sammendrag</a> ] </span>
|
||||||
|
<br>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<style>
|
<noscript>
|
||||||
.b {
|
Denne siden krever JavaScript
|
||||||
|
</noscript>
|
||||||
|
|
||||||
|
<div id="rankingTable">
|
||||||
|
Laster inn...
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
.b {
|
||||||
animation: coolFlash 1s;
|
animation: coolFlash 1s;
|
||||||
}
|
}
|
||||||
|
|
||||||
@keyframes coolFlash {
|
@keyframes coolFlash {
|
||||||
from { background: lightgreen; }
|
from { background: lightgreen; }
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script src="<?=$this->config['root_url']?>static/js/ResultService.js"></script>
|
<script src="<?=$this->config['root_url']?>static/js/ResultService.js"></script>
|
||||||
<script>
|
<script>
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
|
||||||
alertBox = document.getElementById("alertBox");
|
alertBox = document.getElementById("alertBox");
|
||||||
rankingTable = document.getElementById("rankingTable");
|
rankingTable = document.getElementById("rankingTable");
|
||||||
|
|
||||||
new ResultService(alertBox, rankingTable, '<?=$this->config['root_url']?>api/race/results.php?h=');
|
new ResultService(alertBox, rankingTable, '<?=$this->config['root_url']?>api/race/results.php?h=');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<?php if ($view == 'summary'): ?>
|
||||||
|
|
||||||
|
<h1>Sammendrag</h1>
|
||||||
|
<span class="float-right">[ <a class="danger" href="?">Tilbake til resultater</a> ] </span>
|
||||||
|
<br>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>Lag</th>
|
||||||
|
<th>Bedrift</th>
|
||||||
|
<th>Runder</th>
|
||||||
|
<th>Bestetid</th>
|
||||||
|
</tr>
|
||||||
|
<?php $i = 1; foreach ($teams as $team): ?>
|
||||||
|
<tr>
|
||||||
|
<td><?=$i++; $i?></td>
|
||||||
|
<td><?=htmlspecialchars($team->name)?></td>
|
||||||
|
<td><?=htmlspecialchars($team->company)?></td>
|
||||||
|
<td><?=htmlspecialchars($team->rounds)?></td>
|
||||||
|
<td><?=htmlspecialchars($team->best_time)?></td>
|
||||||
|
</tr>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
<?php endif; ?>
|
@ -1,17 +1,61 @@
|
|||||||
<?php $app = require '../../app/inc.php';
|
<?php $app = require '../../app/inc.php';
|
||||||
|
|
||||||
$focused = filter_input(INPUT_GET, 'focused');
|
use App\Teamtable\TeamMapper;
|
||||||
|
|
||||||
if ($focused) {
|
$view = filter_input(INPUT_GET, 'view');
|
||||||
$app->view('template/header', [
|
|
||||||
|
switch ($view) {
|
||||||
|
|
||||||
|
case 'focused':
|
||||||
|
|
||||||
|
$app->view('template/header',
|
||||||
|
[
|
||||||
"title" => "Resultater",
|
"title" => "Resultater",
|
||||||
"hide_nav" => TRUE,
|
"hide_nav" => TRUE,
|
||||||
"hide_menu" => TRUE
|
"hide_menu" => TRUE
|
||||||
]);
|
]
|
||||||
$app->view('pages/race/results', ["focused" => TRUE]);
|
);
|
||||||
|
$app->view('pages/race/results',
|
||||||
|
[
|
||||||
|
"view" => "focused"
|
||||||
|
]
|
||||||
|
);
|
||||||
$app->view('template/footer');
|
$app->view('template/footer');
|
||||||
} else {
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'summary':
|
||||||
|
|
||||||
|
$team_mapper = new TeamMapper($app->database->conn);
|
||||||
|
|
||||||
|
$teams = $team_mapper->getAll();
|
||||||
|
$filtered_teams = [];
|
||||||
|
|
||||||
|
// filter out any teams that have no rounds
|
||||||
|
foreach ($teams as $team)
|
||||||
|
{
|
||||||
|
if ($team->rounds !== 0)
|
||||||
|
{
|
||||||
|
$filtered_teams[] = $team;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$app->view('template/header', ["title" => "Sammendrag"]);
|
||||||
|
$app->view('pages/race/results',
|
||||||
|
[
|
||||||
|
"view" => "summary",
|
||||||
|
"teams" => $filtered_teams
|
||||||
|
]
|
||||||
|
);
|
||||||
|
$app->view('template/footer');
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
|
||||||
$app->view('template/header', ["title" => "Resultater"]);
|
$app->view('template/header', ["title" => "Resultater"]);
|
||||||
$app->view('pages/race/results');
|
$app->view('pages/race/results');
|
||||||
$app->view('template/footer');
|
$app->view('template/footer');
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
Reference in New Issue
Block a user