2022-02-07 10:09:16 +00:00
|
|
|
<?php
|
|
|
|
|
2022-03-02 06:15:12 +00:00
|
|
|
use App\Core\Database as Database;
|
2022-03-02 13:26:02 +00:00
|
|
|
use App\Teamtable\Team as Team;
|
2022-03-07 06:13:17 +00:00
|
|
|
use App\Teamtable\TeamMapper as TeamMapper;
|
2022-03-02 06:15:12 +00:00
|
|
|
|
2022-03-02 13:26:02 +00:00
|
|
|
/**
|
2022-03-07 06:13:17 +00:00
|
|
|
* Does stuffs with the teamtable
|
2022-03-02 13:26:02 +00:00
|
|
|
*/
|
2022-02-07 10:09:16 +00:00
|
|
|
class Teamtable
|
|
|
|
{
|
2022-03-02 13:26:02 +00:00
|
|
|
/**
|
2022-03-07 06:13:17 +00:00
|
|
|
* Database connection
|
2022-03-02 13:26:02 +00:00
|
|
|
*/
|
2022-02-28 04:51:22 +00:00
|
|
|
public PDO $dbh;
|
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
/**
|
|
|
|
* We use a data mapper pattern
|
|
|
|
*/
|
|
|
|
public TeamMapper $teamMapper;
|
|
|
|
|
2022-02-07 10:09:16 +00:00
|
|
|
public function __construct(Database $database)
|
|
|
|
{
|
|
|
|
$this->dbh = $database->conn;
|
2022-03-07 06:13:17 +00:00
|
|
|
$this->teamMapper = new TeamMapper($this->dbh);
|
2022-02-07 10:09:16 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 13:26:02 +00:00
|
|
|
/**
|
|
|
|
* Fetch entire team table
|
|
|
|
*/
|
2022-03-07 06:13:17 +00:00
|
|
|
public function getAll(): array
|
2022-02-09 15:59:20 +00:00
|
|
|
{
|
2022-03-07 06:13:17 +00:00
|
|
|
return $this->teamMapper->getAll();
|
2022-02-09 15:59:20 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 06:24:27 +00:00
|
|
|
/**
|
2022-03-07 06:13:17 +00:00
|
|
|
* Find team with supplied id
|
2022-03-02 06:24:27 +00:00
|
|
|
*/
|
2022-03-07 06:13:17 +00:00
|
|
|
public function get(int $id): ?Team
|
2022-02-09 15:59:20 +00:00
|
|
|
{
|
2022-03-07 06:13:17 +00:00
|
|
|
return $this->teamMapper->get($id);
|
2022-02-09 15:59:20 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 06:24:27 +00:00
|
|
|
/**
|
2022-03-07 06:13:17 +00:00
|
|
|
* Inserts team into database
|
2022-03-02 06:24:27 +00:00
|
|
|
*/
|
2022-03-07 06:13:17 +00:00
|
|
|
public function create(Team $team): Team
|
2022-02-09 15:59:20 +00:00
|
|
|
{
|
2022-03-07 06:13:17 +00:00
|
|
|
return $this->teamMapper->create($team);
|
2022-02-09 15:59:20 +00:00
|
|
|
}
|
|
|
|
|
2022-03-07 06:13:17 +00:00
|
|
|
public function delete(int $id): void
|
2022-02-15 11:26:15 +00:00
|
|
|
{
|
2022-03-07 06:13:17 +00:00
|
|
|
$this->teamMapper->delete($id);
|
2022-02-09 15:59:20 +00:00
|
|
|
}
|
2022-02-15 11:40:57 +00:00
|
|
|
|
2022-03-02 06:24:27 +00:00
|
|
|
/**
|
|
|
|
* Returns TRUE if team exists, FALSE if not
|
|
|
|
*/
|
2022-03-07 06:13:17 +00:00
|
|
|
public function recieveBaton(string $cardnumber): bool
|
2022-02-15 11:40:57 +00:00
|
|
|
{
|
2022-03-07 06:13:17 +00:00
|
|
|
$team = $this->getTeamByCardnumber($cardnumber);
|
|
|
|
if ($team)
|
2022-02-15 11:40:57 +00:00
|
|
|
{
|
2022-03-02 06:24:27 +00:00
|
|
|
// team exists, insert into time table
|
2022-02-15 11:40:57 +00:00
|
|
|
$sth = $this->dbh->prepare('INSERT INTO tidtabell (LagID) VALUES (?)');
|
|
|
|
$sth->execute([$row['LagID']]);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2022-03-07 06:13:17 +00:00
|
|
|
// team does not exist, lets create it
|
|
|
|
$team = new Team();
|
|
|
|
$team->cardnumber = $cardnumber;
|
|
|
|
$this->addTeam($team);
|
2022-02-15 11:40:57 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2022-02-07 10:09:16 +00:00
|
|
|
}
|