Fibinger Ádám
2019-10-17 a4186ab0762833a4c4dd741e6dd112185efc2272
History felület alapok és némi refaktor
4 files modified
5 files added
1 files deleted
114 ■■■■ changed files
EOG/Models/MatchHistory.php 20 ●●●● patch | view | raw | blame | history
common/base.php 4 ●●● patch | view | raw | blame | history
common/history-base.php 22 ●●●●● patch | view | raw | blame | history
form.php 10 ●●●● patch | view | raw | blame | history
match-history.php 10 ●●●●● patch | view | raw | blame | history
save-history.php 5 ●●●●● patch | view | raw | blame | history
team-history.php 3 ●●●●● patch | view | raw | blame | history
templates/admin/history-round.twig 10 ●●●●● patch | view | raw | blame | history
templates/admin/history.twig 28 ●●●●● patch | view | raw | blame | history
templates/admin/stripe-form.twig 2 ●●● patch | view | raw | blame | history
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)
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/');
common/history-base.php
New file
@@ -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);
    }
}
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 = [
match-history.php
New file
@@ -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);
save-history.php
New file
@@ -0,0 +1,5 @@
<?php
include_once "common/history-base.php";
//validate & store as JSON
team-history.php
File was deleted
templates/admin/history-round.twig
New file
@@ -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) }}
templates/admin/history.twig
New file
@@ -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 %}
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() }}