You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.6 KiB
55 lines
1.6 KiB
<?php
|
|
|
|
namespace App\Model;
|
|
|
|
use App\Gateway\TeamGateway;
|
|
use App\Data\Team;
|
|
use App\Data\Member;
|
|
use App\Data\MemberRole;
|
|
use App\Data\Color;
|
|
|
|
class TeamModel {
|
|
private TeamGateway $gateway;
|
|
|
|
/**
|
|
* @param TeamGateway $gateway
|
|
*/
|
|
public function __construct(TeamGateway $gateway) {
|
|
$this->gateway = $gateway;
|
|
}
|
|
|
|
public function createTeam(string $name, string $picture, string $mainColor, string $secondColor): int {
|
|
$this->gateway->insert($name, $picture, $mainColor, $secondColor);
|
|
$result = $this->gateway->getIdTeamByName($name);
|
|
return intval($result[0]['id']);
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
* @return Team[]
|
|
*/
|
|
public function listByName(string $name): array {
|
|
$teams = [];
|
|
$results = $this->gateway->listByName($name);
|
|
foreach ($results as $row) {
|
|
$teams[] = new Team($row['id'], $row['name'], $row['picture'], Color::from($row['mainColor']), Color::from($row['secondColor']));
|
|
}
|
|
return $teams;
|
|
}
|
|
|
|
public function displayTeam(int $id): Team {
|
|
$members = [];
|
|
$result = $this->gateway->getTeamById($id)[0];
|
|
$resultMembers = $this->gateway->getMembersById($id);
|
|
foreach ($resultMembers as $row) {
|
|
if ($row['role'] == 'C') {
|
|
$role = MemberRole::coach();
|
|
} else {
|
|
$role = MemberRole::player();
|
|
}
|
|
$members[] = new Member($row['id'], $role);
|
|
}
|
|
return new Team(intval($result['id']), $result['name'], $result['picture'], Color::from($result['mainColor']), Color::from($result['secondColor']), $members);
|
|
}
|
|
}
|