<?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) : int
|
{
|
$rawData = json_decode($jsonString, true);
|
|
if ($rawData === null)
|
{
|
throw new \InvalidArgumentException("Could not decode JSON");
|
}
|
|
if (!is_array($rawData))
|
{
|
throw new \InvalidArgumentException("Data is not array");
|
}
|
|
$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);
|
}
|
}
|