From a4186ab0762833a4c4dd741e6dd112185efc2272 Mon Sep 17 00:00:00 2001 From: Fibinger Ádám <adam.fibinger@wup.hu> Date: Thu, 17 Oct 2019 16:51:42 +0200 Subject: [PATCH] History felület alapok és némi refaktor --- /dev/null | 3 - common/base.php | 6 ++- EOG/Models/MatchHistory.php | 20 +++++++-- form.php | 10 ++-- save-history.php | 5 ++ templates/admin/history-round.twig | 10 +++++ common/history-base.php | 22 +++++++++++ templates/admin/stripe-form.twig | 2 templates/admin/history.twig | 28 ++++++++++++++ match-history.php | 10 +++++ 10 files changed, 100 insertions(+), 16 deletions(-) diff --git a/EOG/Models/MatchHistory.php b/EOG/Models/MatchHistory.php index 720edcf..cfe6f99 100644 --- a/EOG/Models/MatchHistory.php +++ b/EOG/Models/MatchHistory.php @@ -9,7 +9,7 @@ const ROLE_ATTACK = 'att'; const ROLE_DEFEND = 'def'; - protected $sites = [ + protected $maps = [ 'Bank' => [ 'CEO Office / Executive Lounge', 'Open Area / Staff Room', @@ -84,9 +84,14 @@ /** * @return array */ - public function getSites(): array + public function getMaps(): array { - return $this->sites; + return $this->maps; + } + + public function getMapNames() + { + return array_keys($this->maps); } /** @@ -95,6 +100,11 @@ public function getCurrentMap(): string { return $this->currentMap; + } + + public function getCurrentSites(): array + { + return $this->maps[$this->currentMap]; } /** @@ -107,13 +117,13 @@ private function validMap($mapName) { - $mapList = array_keys($this->sites); + $mapList = array_keys($this->maps); return in_array($mapName, $mapList); } private function validSite($siteName) { - return in_array($siteName, $this->sites[$this->currentMap]); + return in_array($siteName, $this->maps[$this->currentMap]); } public function setCurrentMap(string $mapName) diff --git a/common/base.php b/common/base.php index 5f35160..0071d85 100644 --- a/common/base.php +++ b/common/base.php @@ -9,6 +9,8 @@ define('SITE_ROOT', dirname(__DIR__)); define('OVERLAY_DIR', dirname(SITE_ROOT) . '/overlays/'); -$last_json = OVERLAY_DIR . 'last.json'; +define('STRIPE_JSON', OVERLAY_DIR . 'last.json'); +define('TEAMS_JSON', OVERLAY_DIR . 'teams.json'); +define('HISTORY_JSON', OVERLAY_DIR . 'history.json'); -$twig = \EOG\Utils\TwigFactory::getEnvironment(SITE_ROOT.'/templates/'); \ No newline at end of file +$twig = \EOG\Utils\TwigFactory::getEnvironment(SITE_ROOT . '/templates/'); \ No newline at end of file diff --git a/common/history-base.php b/common/history-base.php new file mode 100644 index 0000000..67b6547 --- /dev/null +++ b/common/history-base.php @@ -0,0 +1,22 @@ +<?php +include_once "common/base.php"; + +$s = new \EOG\Models\Stripe(); + +if (file_exists(STRIPE_JSON)) { + $raw_json = file_get_contents(STRIPE_JSON); + $stateArray = json_decode($raw_json, true); + if (is_array($stateArray)) { + $s->loadFromArray($stateArray); + } +} + +$history = new \EOG\Models\MatchHistory(); + +if (file_exists(HISTORY_JSON)) { + $raw_json = file_get_contents(HISTORY_JSON); + $stateArray = json_decode($raw_json, true); + if (is_array($stateArray)) { + $history->loadState($stateArray); + } +} \ No newline at end of file diff --git a/form.php b/form.php index cfa9739..5e543f0 100644 --- a/form.php +++ b/form.php @@ -7,7 +7,7 @@ $s->loadFromArray($_POST['stripe']); if (!empty($s->getState())) { - file_put_contents($last_json, $s->getJson()); + file_put_contents(STRIPE_JSON, $s->getJson()); } $s->setClass('simple'); @@ -23,8 +23,8 @@ file_put_contents(OVERLAY_DIR . 'team-ban.html', $html_content); } else { - if (file_exists($last_json)) { - $raw_json = file_get_contents($last_json); + if (file_exists(STRIPE_JSON)) { + $raw_json = file_get_contents(STRIPE_JSON); $stateArray = json_decode($raw_json, true); if (is_array($stateArray)) { $s->loadFromArray($stateArray); @@ -34,8 +34,8 @@ $teams = new \EOG\Models\TeamList(); -if (file_exists(OVERLAY_DIR . 'teams.json')) { - $teams->fromJson(file_get_contents(OVERLAY_DIR . 'teams.json')); +if (file_exists(TEAMS_JSON)) { + $teams->fromJson(file_get_contents(TEAMS_JSON)); } $var = [ diff --git a/match-history.php b/match-history.php new file mode 100644 index 0000000..a6d7303 --- /dev/null +++ b/match-history.php @@ -0,0 +1,10 @@ +<?php +include_once "common/history-base.php"; + +$var = [ + 'stripe' => $s, + 'post' => !empty($_POST['stripe']), + 'history' => $history, +]; + +echo $twig->render('admin/history.twig', $var); diff --git a/save-history.php b/save-history.php new file mode 100644 index 0000000..929721f --- /dev/null +++ b/save-history.php @@ -0,0 +1,5 @@ +<?php +include_once "common/history-base.php"; + + +//validate & store as JSON \ No newline at end of file diff --git a/team-history.php b/team-history.php deleted file mode 100644 index a427b98..0000000 --- a/team-history.php +++ /dev/null @@ -1,3 +0,0 @@ -<?php - -include_once "common/base.php"; \ No newline at end of file diff --git a/templates/admin/history-round.twig b/templates/admin/history-round.twig new file mode 100644 index 0000000..168cf7c --- /dev/null +++ b/templates/admin/history-round.twig @@ -0,0 +1,10 @@ +{% set classes = [ 'btn btn-outline-secondary', 'btn btn-outline-success', 'btn btn-outline-danger', 'btn btn-outline-warning', 'btn btn-outline-info', 'btn btn-outline-light', 'btn btn-outline-dark', 'btn btn-outline-link', 'btn btn-outline-primary'] %} +{% set activeClasses = [ 'btn btn-secondary', 'btn btn-success', 'btn btn-danger', 'btn btn-warning', 'btn btn-info', 'btn btn-light', 'btn btn-dark', 'btn btn-link', 'btn btn-primary'] %} + +<div class="form-row"> + {% for site in history.getCurrentSites %} + <button class="{{ cycle(classes, loop.index0)}}" id="r_{{ loop.parent.loop.index0 }}_b_{{ loop.index0 }}" + data-outline="{{ cycle(classes, loop.index0)}}" data-selected="{{ cycle(activeClasses, loop.index0)}}" onclick="return false;">{{ site }}</button> + {% endfor %} +</div> +{{ dump(round) }} \ No newline at end of file diff --git a/templates/admin/history.twig b/templates/admin/history.twig new file mode 100644 index 0000000..387fabf --- /dev/null +++ b/templates/admin/history.twig @@ -0,0 +1,28 @@ +{% extends "admin/html-skeleton.twig" %} +{% block body %} + <form action="/generator/match-history.php" method="post"> + <select name="currentMap" id="currentMap" onchange="updateSites()"> + {% for map in history.getMapNames %} + <option value="{{ map }}" {{ history.getCurrentMap == map ? "selected" }}>{{ map }}</option> + {% endfor %} + </select> + <div class="form-group"> + <pre> + {% for round in history %} + {% include "admin/history-round.twig" %} + {% endfor %} + </pre> + </div> + </form> +{% endblock %} + +{% block lazyload %} + {{ parent() }} + <script type="text/javascript"> + var maps = {{ history.getMaps|json_encode|raw }} + function updateSites() { + var currentMap = document.getElementById('currentMap').value; + console.log(maps[currentMap]); + } + </script> +{% endblock %} \ No newline at end of file diff --git a/templates/admin/stripe-form.twig b/templates/admin/stripe-form.twig index 9300d9b..11898f5 100644 --- a/templates/admin/stripe-form.twig +++ b/templates/admin/stripe-form.twig @@ -91,7 +91,7 @@ </div> </form> - <a href="/generator/team-history.php" class="btn btn-secondary">Meccstörténet</a> + <a href="/generator/match-history.php" class="btn btn-secondary">Meccstörténet</a> {% endblock %} {% block lazyload %} {{ parent() }} -- Gitblit v1.8.0