teams = $gateway; $this->members = $members; $this->users = $users; } /** * Create a team * @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); } /** * add a member to a team * @param string $mail * @param int $teamId * @param string $role * @return int */ public function addMember(string $mail, int $teamId, string $role): int { $user = $this->users->getAccountFromMail($mail); if($user == null) { return -1; } if(!$this->members->isMemberOfTeam($teamId, $user->getUser()->getId())) { $this->members->insert($teamId, $user->getUser()->getId(), $role); return 1; } return -2; } /** * @param string $name * @param int $id * @return TeamInfo[] */ public function listByName(string $name, int $id): array { return $this->teams->listByName($name, $id); } /** * @param int $idTeam * @param int $idCurrentUser * @return Team|null */ public function getTeam(int $idTeam, int $idCurrentUser): ?Team { if(!$this->members->isMemberOfTeam($idTeam, $idCurrentUser)) { return null; } $teamInfo = $this->teams->getTeamById($idTeam); $members = $this->members->getMembersOfTeam($idTeam); return new Team($teamInfo, $members); } /** * delete a member from given team identifier * @param int $idMember * @param int $teamId * @return int */ public function deleteMember(int $idMember, int $teamId): int { $this->members->remove($teamId, $idMember); if(empty($this->members->getMembersOfTeam($teamId))) { $this->teams->deleteTeam($teamId); return -1; } return $teamId; } /** * Delete a team * @param string $email * @param int $idTeam * @return int */ public function deleteTeam(string $email, int $idTeam): int { if($this->members->isCoach($email, $idTeam)) { $this->teams->deleteTeam($idTeam); return 0; } return -1; } /** * Verify if the account associated to an email is in a specific team indicated with its id * @param int $idTeam * @param string $email * @return bool */ public function isCoach(int $idTeam, string $email): bool { return $this->members->isCoach($email, $idTeam); } /** * Edit a team with its id, and replace the current attributes with the new ones * @param int $idTeam * @param string $newName * @param string $newPicture * @param string $newMainColor * @param string $newSecondColor * @return void */ public function editTeam(int $idTeam, string $newName, string $newPicture, string $newMainColor, string $newSecondColor) { $this->teams->editTeam($idTeam, $newName, $newPicture, $newMainColor, $newSecondColor); } /** * Get all user's teams * * @param integer $user * @return array> */ public function getAll(int $user): array { return $this->teams->getAll($user); } }