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.
91 lines
2.4 KiB
91 lines
2.4 KiB
<?php
|
|
|
|
namespace IQBall\Core\Model;
|
|
|
|
use IQBall\Core\Data\Color;
|
|
use IQBall\Core\Data\Team;
|
|
use IQBall\Core\Data\TeamInfo;
|
|
use IQBall\Core\Gateway\AccountGateway;
|
|
use IQBall\Core\Gateway\MemberGateway;
|
|
use IQBall\Core\Gateway\TeamGateway;
|
|
|
|
class TeamModel {
|
|
private AccountGateway $users;
|
|
private TeamGateway $teams;
|
|
private MemberGateway $members;
|
|
|
|
/**
|
|
* @param TeamGateway $gateway
|
|
* @param MemberGateway $members
|
|
* @param AccountGateway $users
|
|
*/
|
|
public function __construct(TeamGateway $gateway, MemberGateway $members, AccountGateway $users) {
|
|
$this->teams = $gateway;
|
|
$this->members = $members;
|
|
$this->users = $users;
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
* @param string $picture
|
|
* @param string $mainColor
|
|
* @param string $secondColor
|
|
* @return int
|
|
*/
|
|
public function createTeam(string $name, string $picture, string $mainColor, string $secondColor): int {
|
|
return $this->teams->insert($name, $picture, $mainColor, $secondColor);
|
|
}
|
|
|
|
/**
|
|
* adds a member to a team
|
|
* @param string $mail
|
|
* @param int $teamId
|
|
* @param string $role
|
|
* @return void
|
|
*/
|
|
public function addMember(string $mail, int $teamId, string $role): void {
|
|
$userId = $this->users->getAccountFromMail($mail)->getId();
|
|
$this->members->insert($teamId, $userId, $role);
|
|
}
|
|
|
|
/**
|
|
* @param string $name
|
|
* @return TeamInfo[]
|
|
*/
|
|
public function listByName(string $name,int $id): array {
|
|
return $this->teams->listByName($name,$id);
|
|
}
|
|
|
|
/**
|
|
* @param int $id
|
|
* @return Team
|
|
*/
|
|
public function getTeam(int $id): Team {
|
|
$teamInfo = $this->teams->getTeamById($id);
|
|
$members = $this->members->getMembersOfTeam($id);
|
|
return new Team($teamInfo, $members);
|
|
}
|
|
|
|
/**
|
|
* delete a member from given team identifier
|
|
* @param string $mail
|
|
* @param int $teamId
|
|
* @return int
|
|
*/
|
|
public function deleteMember(string $mail, int $teamId): int {
|
|
$userId = $this->users->getAccountFromMail($mail)->getId();
|
|
$this->members->remove($teamId, $userId);
|
|
return $teamId;
|
|
}
|
|
|
|
public function deleteTeam(string $email, int $idTeam): int{
|
|
if($this->teams->isCoach($email,$idTeam) == "Coach" ){
|
|
$this->teams->deleteTeam($idTeam);
|
|
return 0;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
}
|