con = $con; } /** * @param string $name * @param string $picture * @param string $mainColor * @param string $secondColor * @return int the inserted team identifier */ public function insert(string $name, string $picture, string $mainColor, string $secondColor): int { $this->con->exec( "INSERT INTO Team(name, picture, main_color, second_color) VALUES (:team_name , :picture, :main_color, :second_color)", [ ":team_name" => [$name, PDO::PARAM_STR], ":picture" => [$picture, PDO::PARAM_STR], ":main_color" => [$mainColor, PDO::PARAM_STR], ":second_color" => [$secondColor, PDO::PARAM_STR], ] ); return intval($this->con->lastInsertId()); } /** * @param string $name * @return TeamInfo[] */ public function listByName(string $name): array { $result = $this->con->fetch( "SELECT * FROM Team WHERE name LIKE '%' || :name || '%'", [ ":name" => [$name, PDO::PARAM_STR], ] ); return array_map(fn($row) => new TeamInfo($row['id'], $row['name'], $row['picture'], Color::from($row['main_color']), Color::from($row['second_color'])), $result); } /** * @param int $id * @return TeamInfo */ public function getTeamById(int $id): ?TeamInfo { $row = $this->con->fetch( "SELECT * FROM Team WHERE id = :id", [ ":id" => [$id, PDO::PARAM_INT], ] )[0] ?? null; if ($row == null) { return null; } return new TeamInfo($row['id'], $row['name'], $row['picture'], Color::from($row['main_color']), Color::from($row['second_color'])); } /** * @param string $name * @return int|null */ public function getTeamIdByName(string $name): ?int { return $this->con->fetch( "SELECT id FROM Team WHERE name = :name", [ ":name" => [$name, PDO::PARAM_INT], ] )[0]['id'] ?? null; } public function getAll(int $user) : array { return $this->con->fetch("SELECT * FROM Team", []); } }