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

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

diff --git a/EOG/Models/TeamList.php b/EOG/Models/TeamList.php
new file mode 100644
index 0000000..7897eba
--- /dev/null
+++ b/EOG/Models/TeamList.php
@@ -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);
+    }
+}
\ No newline at end of file

--
Gitblit v1.8.0