From 7a397279805473a76251db4821b7a8c0a76a554c Mon Sep 17 00:00:00 2001
From: Fibinger Ádám <adam.fibinger@wup.hu>
Date: Fri, 01 May 2020 16:33:27 +0200
Subject: [PATCH] Csapat import - Battlefy Edition

---
 EOG/Models/TeamList.php |   25 ++++++++++++++-----------
 1 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/EOG/Models/TeamList.php b/EOG/Models/TeamList.php
index f61a8de..feb2df2 100644
--- a/EOG/Models/TeamList.php
+++ b/EOG/Models/TeamList.php
@@ -11,9 +11,7 @@
 	 */
 	protected $teams = [];
 
-	private $requiredRawFields = ['name', 'seed', 'status'];
-
-	public function fromJson(string $jsonString) : int
+	public function fromJson(string $jsonString): int
 	{
 		$rawData = json_decode($jsonString, true);
 
@@ -31,16 +29,21 @@
 
 		foreach ($rawData as $key => $team)
 		{
-			$rawKeys = array_keys($team);
-			if (count(array_intersect($rawKeys, $this->requiredRawFields)) != 3)
+			$players = [];
+			if (is_array($team['players']))
 			{
-				continue;
+				foreach ($team['players'] as $player)
+				{
+					if (!empty($player['inGameName']))
+					{
+						$players[] = $player['inGameName'];
+					}
+				}
 			}
-
-			if ($team['status'] == 'checkedIn')
-			{
-				$this->teams[] = $team;
-			}
+			$this->teams[] = [
+				'name'    => $team['name'],
+				'players' => $players
+			];
 		}
 
 		return (bool)count($this->teams);

--
Gitblit v1.8.0