From 87c1a0c1c598c49a3c722611bc5a019f26d49430 Mon Sep 17 00:00:00 2001 From: William Date: Mon, 21 Mar 2022 11:39:50 +0100 Subject: [PATCH] Commit --- app/lib/App/Timetable/TimeMapper.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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)