1867e166c90eb8366707c48a6f8540c3f91a1957..a4186ab0762833a4c4dd741e6dd112185efc2272
2019-10-17 Fibinger Ádám
History felület alapok és némi refaktor
a4186a diff | tree
2019-10-17 Fibinger Ádám
Template útvonal módosítása
3305a7 diff | tree
2019-10-17 Fibinger Ádám
Csapatok előtöltése az API adatok alapján
b40e93 diff | tree
9 files added
1 files deleted
3 files modified
501 ■■■■ changed files
EOG/Models/MatchHistory.php 20 ●●●● patch | view | raw | blame | history
EOG/Models/TeamList.php 70 ●●●●● patch | view | raw | blame | history
EOG/Utils/TwigFactory.php 2 ●●● patch | view | raw | blame | history
common/base.php 16 ●●●●● patch | view | raw | blame | history
common/history-base.php 22 ●●●●● patch | view | raw | blame | history
form.php 84 ●●●●● patch | view | raw | blame | history
match-history.php 10 ●●●●● patch | view | raw | blame | history
save-history.php 5 ●●●●● patch | view | raw | blame | history
save-teams.php 20 ●●●●● patch | view | raw | blame | history
templates/admin/form.twig 94 ●●●●● 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 120 ●●●●● 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)
EOG/Models/TeamList.php
New file
@@ -0,0 +1,70 @@
<?php
namespace EOG\Models;
class TeamList
{
    /**
     * @var string[] Csapatok listája (előtöltve)
     */
    protected $teams = [];
    private $requiredRawFields = ['name', 'seed', 'status'];
    public function fromJson(string $jsonString)
    {
        $rawData = json_decode($jsonString, true);
        if ($rawData === null) return false;
        if (!is_array($rawData)) {
            return false;
        }
        $this->teams = [];
        foreach ($rawData as $key => $team) {
            $rawKeys = array_keys($team);
            if (count(array_intersect($rawKeys, $this->requiredRawFields)) != 3) {
                continue;
            }
            if ($team['status'] == 'checkedIn') {
                $this->teams[] = $team;
            }
        }
        return (bool)count($this->teams);
    }
    public function getTeamNames()
    {
        return array_column($this->teams, 'name');
    }
    /**
     * @return string[]
     */
    public function getTeams(): array
    {
        return $this->teams;
    }
    /**
     * @param string[] $teams
     * @return TeamList
     */
    public function setTeams(array $teams): TeamList
    {
        $this->teams = $teams;
        return $this;
    }
    public function getJson()
    {
        return json_encode($this->teams);
    }
}
EOG/Utils/TwigFactory.php
@@ -42,7 +42,7 @@
            $loader = new FilesystemLoader($fileSystemPaths);
        }
        $twigEnvironmentOptions['cache'] = static::CACHE_DIR;
        //$twigEnvironmentOptions['cache'] = static::CACHE_DIR;
        $twigEnvironmentOptions['auto_reload'] = true;
        if (IS_DEV)
common/base.php
New file
@@ -0,0 +1,16 @@
<?php
ini_set('display_errors', E_ALL);
include "vendor/autoload.php";
define('IS_DEV', true);
define('SITE_ROOT', dirname(__DIR__));
define('OVERLAY_DIR', dirname(SITE_ROOT) . '/overlays/');
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
@@ -1,65 +1,49 @@
<?php
ini_set('display_errors', E_ALL);
include "vendor/autoload.php";
define('IS_DEV', (!isset($_SERVER['HTTP_HOST'])));
define('SITE_ROOT', __DIR__);
if (IS_DEV)
{
    define('OVERLAY_DIR', dirname(__DIR__) . '/esl-overlay/');
}
else
{
    define('OVERLAY_DIR', dirname(__DIR__) . '/overlays/');
}
$last_json = OVERLAY_DIR . 'last.json';
$twig = \EOG\Utils\TwigFactory::getEnvironment(SITE_ROOT);
include_once "common/base.php";
$s = new \EOG\Models\Stripe();
if (!empty($_POST['stripe']))
{
    $s->loadFromArray($_POST['stripe']);
if (!empty($_POST['stripe'])) {
    $s->loadFromArray($_POST['stripe']);
    if (!empty($s->getState()))
    {
        file_put_contents($last_json, $s->getJson());
    }
    if (!empty($s->getState())) {
        file_put_contents(STRIPE_JSON, $s->getJson());
    }
    $s->setClass('simple');
    $html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
    file_put_contents(OVERLAY_DIR . 'simple.html', $html_content);
    $s->setClass('simple');
    $html_content = $twig->render('overlay-base.twig', ['stripe' => $s]);
    file_put_contents(OVERLAY_DIR . 'simple.html', $html_content);
    $s->setClass('team');
    $html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
    file_put_contents(OVERLAY_DIR . 'team.html', $html_content);
    $s->setClass('team');
    $html_content = $twig->render('overlay-base.twig', ['stripe' => $s]);
    file_put_contents(OVERLAY_DIR . 'team.html', $html_content);
    $s->setClass('team-ban');
    $html_content = $twig->render('templates/overlay-base.twig', ['stripe' => $s]);
    file_put_contents(OVERLAY_DIR . 'team-ban.html', $html_content);
    $s->setClass('team-ban');
    $html_content = $twig->render('overlay-base.twig', ['stripe' => $s]);
    file_put_contents(OVERLAY_DIR . 'team-ban.html', $html_content);
} else {
    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);
        }
    }
}
else
{
    if (file_exists($last_json))
    {
        $raw_json = file_get_contents($last_json);
        $stateArray = json_decode($raw_json, true);
        if (is_array($stateArray))
        {
            $s->loadFromArray($stateArray);
        }
    }
$teams = new \EOG\Models\TeamList();
if (file_exists(TEAMS_JSON)) {
    $teams->fromJson(file_get_contents(TEAMS_JSON));
}
$var = [
    'stripe'    => $s,
    'operators' => $s->getOperators(),
    'post'      => !empty($_POST['stripe'])
    'stripe' => $s,
    'teamNames' => $teams->getTeamNames(),
    'operators' => $s->getOperators(),
    'post' => !empty($_POST['stripe'])
];
echo $twig->render('templates/admin/form.twig', $var);
echo $twig->render('admin/stripe-form.twig', $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
save-teams.php
New file
@@ -0,0 +1,20 @@
<?php
include_once "common/base.php";
if (empty($_POST['json'])) {
    header('Location: /generator/form.php', true, 302);
}
$teams = new \EOG\Models\TeamList();
$success = false;
if ($teams->fromJson($_POST['json'])) {
    $success = file_put_contents(OVERLAY_DIR . 'teams.json', $teams->getJson());
}
if ($success) {
    header('Location: /generator/form.php', true, 302);
} else {
    echo "Szar van a palacsintában";
}
templates/admin/form.twig
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
New file
@@ -0,0 +1,120 @@
{% extends "admin/html-skeleton.twig" %}
{% block body %}
    <form action="/generator/form.php" method="post">
        <input type="hidden" name="stripe[class]" value="team-ban"/>
        <div class="form-group">
            <div class="form-row">
                <div class="col-md-8 mb-3">
                    <label for="validationServer01">Kupa neve</label>
                    <input type="text" name="stripe[cup][name]" class="form-control" id="validationServer01"
                           placeholder="Pld.: 5on5 Bomb Cup" value="{{ stripe.cup.name }}" required>
                </div>
                <div class="col-md-2 mb-3">
                    <label for="validationServer02">Kupa sorszám</label>
                    <input type="text" name="stripe[cup][number]" class="form-control" id="validationServer02"
                           placeholder="Pld.: #654"
                           value="{{ stripe.cup.number }}" required>
                </div>
            </div>
        </div>
        <div class="form-group">
            <div class="form-row">
                <label for="teamname">Csapat gyorsfeltöltés:</label>
                <select id="teamname">
                    {% for teamName in teamNames %}
                        <option value="{{ teamName }}">{{ teamName }}</option>
                    {% endfor %}
                </select>
                <button class="btn btn-primary"
                        title="Legyen az itt kiválasztott a kék csapat"
                        onclick="$('#team_blue_name').val($('#teamname').val()); return false;">Legyen kék</button>
                <button class="btn btn-warning"
                        title="Csapat színcsere"
                        onclick="$('#team_orange_name').val($('#teamname').val()); return false;">Legyen narancs</button>
            </div>
        </div>
        <div class="form-group">
            <div class="form-row">
                <div class="form-group bg-primary">
                    <div class="col-md-12 mb-4">
                        <label for="team_blue_name" class="bg-primary">Kék csapat neve</label>
                        <input type="text" name="stripe[team][blue][name]" class="form-control" id="team_blue_name"
                               placeholder="Pld.: Impress!ve" value="{{ stripe.team.blue.name }}" required>
                    </div>
                    <div class="col-md-12 mb-4">
                        <label for="op-blue" class="bg-primary">Banolt operátorok</label>
                        <select name="stripe[team][blue][ban][]" class="operators" id="op-blue" style="width: 100%"
                                multiple>
                            {% for operator in operators %}
                                <option value="{{ operator }}" {{ operator in stripe.team.blue.ban ? "selected" }}>{{ operator|capitalize }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <button class="btn btn-info" title="Csapat színcsere" onclick="swapTeams(); return false;"><=>
                    </button>
                </div>
                <div class="form-group bg-warning">
                    <div class="col-md-12 mb-4">
                        <label for="team_orange_name">Narancs csapat neve</label>
                        <input type="text" name="stripe[team][orange][name]" class="form-control" id="team_orange_name"
                               placeholder="Pld.: Opress!ve" value="{{ stripe.team.orange.name }}" required>
                    </div>
                    <div class="col-md-12 mb-4">
                        <label for="op-orange" class="bg-warning">Banolt operátorok</label>
                        <select name="stripe[team][orange][ban][]" class="operators" id="op-orange" style="width: 100%"
                                multiple>
                            {% for operator in operators %}
                                <option value="{{ operator }}" {{ operator in stripe.team.orange.ban ? "selected" }}>{{ operator|capitalize }}</option>
                            {% endfor %}
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="form-group">
            <button class="btn btn-primary mx-auto" type="submit">Overlay felülírása</button>
        </div>
    </form>
    <form action="/generator/save-teams.php" method="post">
        <div class="form-group">
            <div class="col-md-4 mb-4">
                <label for="json">Csapatok API Input adatai:</label>
                Pld: https://api.eslgaming.com/play/v1/leagues/198846/contestants válasz eredménye
                <textarea class="form-control" name="json" id="json"></textarea>
                <button class="btn btn-secondary" type="submit">Csapatok frissítése</button>
            </div>
        </div>
    </form>
    <a href="/generator/match-history.php" class="btn btn-secondary">Meccstörténet</a>
{% endblock %}
{% block lazyload %}
    {{ parent() }}
    <script type="text/javascript">
        $('.operators').chosen(
            {
                'placeholder_text_multiple': 'Banolt operátorok',
                'max_selected_options': 2
            }
        );
        $('#teamname').chosen();
        function swapTeams() {
            var blue = document.getElementById('team_blue_name');
            var orange = document.getElementById('team_orange_name');
            var blue_name = blue.value;
            blue.value = orange.value;
            orange.value = blue_name;
            return false;
        }
    </script>
{% endblock %}