From 0dabedc06dea5066fce2d77286a966e9b00beeb3 Mon Sep 17 00:00:00 2001
From: Fibinger Ádám <adam.fibinger@wup.hu>
Date: Tue, 15 Oct 2019 18:18:02 +0200
Subject: [PATCH] Form target fix

---
 EOG/Models/MatchHistory.php |  201 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 201 insertions(+), 0 deletions(-)

diff --git a/EOG/Models/MatchHistory.php b/EOG/Models/MatchHistory.php
new file mode 100644
index 0000000..720edcf
--- /dev/null
+++ b/EOG/Models/MatchHistory.php
@@ -0,0 +1,201 @@
+<?php
+
+
+namespace EOG\Models;
+
+
+class MatchHistory implements \Iterator, \Countable
+{
+    const ROLE_ATTACK = 'att';
+    const ROLE_DEFEND = 'def';
+
+    protected $sites = [
+        'Bank' => [
+            'CEO Office / Executive Lounge',
+            'Open Area / Staff Room',
+            'Tellers\' Office / Archives',
+            'Basement CCTV Room / Basement Lockers',
+        ],
+
+        'Border' => [
+            'Supply Room / Customs Inspection',
+            'Workshop / Ventilation Room',
+            'Bathroom / Tellers',
+            'Armory Lockers / Archives',
+        ],
+
+        'Club House' => [
+            'Bedroom / Gym',
+            'Cash Room / CCTV Room',
+            'Bar / Stock Room',
+            'Basement Church / Basement Arsenal Room',
+        ],
+
+        'Coastline' => [
+            'Billiards Room / Hookah Lounge',
+            'Theater / Penthouse',
+            'Kitchen / Service Entrance',
+            'Blue Bar / Sunrise Bar',
+        ],
+
+        'Consulate' => [
+            'Meeting Room / Consulate Office',
+            'Press Room / Lobby',
+            'Basement Archives / Tellers',
+            'Basement Cafeteria / Basement Garage',
+        ],
+
+        'Kafe Dostoyevsky' => [
+            '3rd Floor Cocktail Lounge',
+            'Fireplace Hall / Mining Room',
+            'Reading Room / Fireplace Hall',
+            'Kitchen Service / Kitchen Cooking'
+        ],
+
+        'Villa' => [
+            'Aviator Room / Games Room',
+            'Trophy Room / Statuary Room',
+            'Living Room / Library',
+            'Dining Room / Kitchen'
+        ]
+    ];
+
+    private $position = 0;
+
+    protected $currentMap = 'Villa';
+    protected $history = [
+        [
+            'site' => 'Aviator Room / Games Room',
+            'win' => Stripe::TEAM_ORANGE,
+            'win_role' => self::ROLE_DEFEND
+        ],
+        [
+            'site' => 'Trophy Room / Statuary Room',
+            'win' => Stripe::TEAM_BLUE,
+            'win_role' => self::ROLE_ATTACK
+        ],
+        [
+            'site' => 'Dining Room / Kitchen',
+            'win' => Stripe::TEAM_ORANGE,
+            'win_role' => self::ROLE_ATTACK
+        ]
+    ];
+
+    /**
+     * @return array
+     */
+    public function getSites(): array
+    {
+        return $this->sites;
+    }
+
+    /**
+     * @return string
+     */
+    public function getCurrentMap(): string
+    {
+        return $this->currentMap;
+    }
+
+    /**
+     * @return array
+     */
+    public function getHistory(): array
+    {
+        return $this->history;
+    }
+
+    private function validMap($mapName)
+    {
+        $mapList = array_keys($this->sites);
+        return in_array($mapName, $mapList);
+    }
+
+    private function validSite($siteName)
+    {
+        return in_array($siteName, $this->sites[$this->currentMap]);
+    }
+
+    public function setCurrentMap(string $mapName)
+    {
+
+        if (!$this->validMap($mapName)) {
+            throw new \InvalidArgumentException("No such map: " . $mapName);
+        }
+
+        $this->currentMap = $mapName;
+    }
+
+    public function addHistoryItem(string $site, string $winner = Stripe::TEAM_BLUE, $win_role = MatchHistory::ROLE_DEFEND)
+    {
+        if (!$this->validSite($site)) {
+            throw new \InvalidArgumentException("No such site: " . $site . " on map: " . $this->currentMap);
+        }
+        if (!in_array($winner, [Stripe::TEAM_BLUE, Stripe::TEAM_ORANGE])) {
+            throw new \InvalidArgumentException("No such team: " . $winner);
+        }
+        if (!in_array($win_role, [MatchHistory::ROLE_DEFEND, MatchHistory::ROLE_ATTACK])) {
+            throw new \InvalidArgumentException("No such role: " . $win_role);
+        }
+
+        $this->history[] = [
+            'site' => $site,
+            'win' => $winner,
+            'win_role' => $win_role
+        ];
+    }
+
+    public function getState(): array
+    {
+        return
+            [
+                'history' => $this->history,
+                'map' => $this->currentMap
+            ];
+    }
+
+    public function loadState(array $state): self
+    {
+        if (!empty($state['map'])) {
+            $this->setCurrentMap($state['map']);
+        }
+
+        if (!empty($state['history'])) {
+            foreach ($state['history'] as $item) {
+                $this->addHistoryItem($item['site'], $item['win'], $item['win_role']);
+            }
+        }
+        return $this;
+    }
+
+    public function current()
+    {
+        return $this->history[$this->position];
+    }
+
+    public function next()
+    {
+        $this->position++;
+    }
+
+    public function key()
+    {
+        return $this->position;
+    }
+
+    public function valid()
+    {
+        return isset($this->history[$this->position]);
+    }
+
+    public function rewind()
+    {
+        $this->position = 0;
+    }
+
+    public function count()
+    {
+        return count($this->history);
+    }
+
+}
\ No newline at end of file

--
Gitblit v1.8.0