2022-02-07 11:09:16 +01:00
|
|
|
<?php
|
|
|
|
|
2022-03-02 07:15:12 +01:00
|
|
|
use App\Core\Database as Database;
|
2022-03-02 14:26:02 +01:00
|
|
|
use App\Teamtable\Team as Team;
|
2022-03-07 07:13:17 +01:00
|
|
|
use App\Teamtable\TeamMapper as TeamMapper;
|
2022-03-02 07:15:12 +01:00
|
|
|
|
2022-03-02 14:26:02 +01:00
|
|
|
/**
|
2022-03-07 07:13:17 +01:00
|
|
|
* Does stuffs with the teamtable
|
2022-03-02 14:26:02 +01:00
|
|
|
*/
|
2022-02-07 11:09:16 +01:00
|
|
|
class Teamtable
|
|
|
|
{
|
2022-02-28 05:51:22 +01:00
|
|
|
public PDO $dbh;
|
|
|
|
|
2022-03-07 07:13:17 +01:00
|
|
|
/**
|
|
|
|
* We use a data mapper pattern
|
|
|
|
*/
|
|
|
|
public TeamMapper $teamMapper;
|
|
|
|
|
2022-02-07 11:09:16 +01:00
|
|
|
public function __construct(Database $database)
|
|
|
|
{
|
|
|
|
$this->dbh = $database->conn;
|
2022-03-07 07:13:17 +01:00
|
|
|
$this->teamMapper = new TeamMapper($this->dbh);
|
2022-02-07 11:09:16 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 14:26:02 +01:00
|
|
|
/**
|
|
|
|
* Fetch entire team table
|
|
|
|
*/
|
2022-03-07 07:13:17 +01:00
|
|
|
public function getAll(): array
|
2022-02-09 16:59:20 +01:00
|
|
|
{
|
2022-03-07 07:13:17 +01:00
|
|
|
return $this->teamMapper->getAll();
|
2022-02-09 16:59:20 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 07:24:27 +01:00
|
|
|
/**
|
2022-03-07 07:13:17 +01:00
|
|
|
* Find team with supplied id
|
2022-03-02 07:24:27 +01:00
|
|
|
*/
|
2022-03-07 07:13:17 +01:00
|
|
|
public function get(int $id): ?Team
|
2022-02-09 16:59:20 +01:00
|
|
|
{
|
2022-03-07 07:13:17 +01:00
|
|
|
return $this->teamMapper->get($id);
|
2022-02-09 16:59:20 +01:00
|
|
|
}
|
|
|
|
|
2022-03-02 07:24:27 +01:00
|
|
|
/**
|
2022-03-07 07:13:17 +01:00
|
|
|
* Inserts team into database
|
2022-03-02 07:24:27 +01:00
|
|
|
*/
|
2022-03-07 07:13:17 +01:00
|
|
|
public function create(Team $team): Team
|
2022-02-09 16:59:20 +01:00
|
|
|
{
|
2022-03-07 07:13:17 +01:00
|
|
|
return $this->teamMapper->create($team);
|
2022-02-09 16:59:20 +01:00
|
|
|
}
|
|
|
|
|
2022-03-07 07:13:17 +01:00
|
|
|
public function delete(int $id): void
|
2022-02-15 12:26:15 +01:00
|
|
|
{
|
2022-03-07 07:13:17 +01:00
|
|
|
$this->teamMapper->delete($id);
|
2022-02-09 16:59:20 +01:00
|
|
|
}
|
2022-02-15 12:40:57 +01:00
|
|
|
|
2022-03-07 11:11:33 +01:00
|
|
|
public function update(Team $team): Team
|
|
|
|
{
|
|
|
|
return $this->teamMapper->update($team);
|
|
|
|
}
|
2022-02-07 11:09:16 +01:00
|
|
|
}
|