diff --git a/app/lib/App/Timetable/TimeMapper.php b/app/lib/App/Timetable/TimeMapper.php index 54ddecc..2c7624e 100644 --- a/app/lib/App/Timetable/TimeMapper.php +++ b/app/lib/App/Timetable/TimeMapper.php @@ -36,9 +36,21 @@ class TimeMapper return $times; } + public function getLatest(): ?Time + { + $sth = $this->dbh->prepare('SELECT * FROM tidtabell ORDER BY Tidspunkt DESC LIMIT 1'); + $sth->execute(); + $row = $sth->fetch(PDO::FETCH_ASSOC); + if ($row) + { + return $this->mapRowToTime($row); + } + return NULL; + } + public function getLatestByTeamId(int $teamId): ?Time { - $sth = $this->dbh->prepare('SELECT * FROM tidtabell WHERE LagID = ? ORDER BY Tidspunkt DESC'); + $sth = $this->dbh->prepare('SELECT * FROM tidtabell WHERE LagID = ? ORDER BY Tidspunkt DESC LIMIT 1'); $sth->execute([$teamId]); $row = $sth->fetch(PDO::FETCH_ASSOC); if ($row) @@ -50,7 +62,7 @@ class TimeMapper public function get(int $id): ?Time { - $sth = $this->dbh->prepare('SELECT * FROM tidtabell WHERE TidID = ?'); + $sth = $this->dbh->prepare('SELECT * FROM tidtabell WHERE TidID = ? LIMIT 1'); $sth->execute([$id]); $row = $sth->fetch(PDO::FETCH_ASSOC); if ($row)