From 14820d90fdeb6d46c5dfb6163c6626ae0a36a800 Mon Sep 17 00:00:00 2001 From: William Date: Sun, 20 Mar 2022 21:36:35 +0100 Subject: [PATCH] Commit --- app/lib/App/Timetable/TimeMapper.php | 23 ++++++++++++++++----- public/race/configure/reset.php | 30 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 5 deletions(-) create mode 100644 public/race/configure/reset.php diff --git a/app/lib/App/Timetable/TimeMapper.php b/app/lib/App/Timetable/TimeMapper.php index 8769ea9..54ddecc 100644 --- a/app/lib/App/Timetable/TimeMapper.php +++ b/app/lib/App/Timetable/TimeMapper.php @@ -16,11 +16,24 @@ class TimeMapper private function mapRowToTime(array $row): Time { - $team = new Time(); - $team->id = $row['TidID']; - $team->setTeamId($row['LagID']); - $team->setDate(new DateTime($row['Tidspunkt'])); - return $team; + $time= new Time(); + $time->id = $row['TidID']; + $time->setTeamId($row['LagID']); + $time->setDate(new DateTime($row['Tidspunkt'])); + return $time; + } + + public function getAll(): array + { + $sth = $this->dbh->query('SELECT * FROM tidtabell'); + $assoc_array = $sth->fetchAll(PDO::FETCH_ASSOC); + + $times = []; + foreach ($assoc_array as $key => $row) + { + array_push($times, $this->mapRowToTime($row)); + } + return $times; } public function getLatestByTeamId(int $teamId): ?Time diff --git a/public/race/configure/reset.php b/public/race/configure/reset.php new file mode 100644 index 0000000..3cfdd12 --- /dev/null +++ b/public/race/configure/reset.php @@ -0,0 +1,30 @@ +database->conn); +$timeMapper = new TimeMapper($app->database->conn); + +// reset counters for all teams +$teams = $teamMapper->getAll(); + +foreach ($teams as $key => $team) +{ + $team->setRounds(0); + $team->bestTime = NULL; + $teamMapper->update($team); +} + +// delete all time records +$times = $timeMapper->getAll(); + +foreach ($times as $key => $time) +{ + $timeMapper->delete($time->id); +} \ No newline at end of file