This commit is contained in:
William 2022-03-20 21:36:35 +01:00
parent cb28dbaaba
commit 14820d90fd
2 changed files with 48 additions and 5 deletions

View File

@ -16,11 +16,24 @@ class TimeMapper
private function mapRowToTime(array $row): Time private function mapRowToTime(array $row): Time
{ {
$team = new Time(); $time= new Time();
$team->id = $row['TidID']; $time->id = $row['TidID'];
$team->setTeamId($row['LagID']); $time->setTeamId($row['LagID']);
$team->setDate(new DateTime($row['Tidspunkt'])); $time->setDate(new DateTime($row['Tidspunkt']));
return $team; 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 public function getLatestByTeamId(int $teamId): ?Time

View File

@ -0,0 +1,30 @@
<?php $app = require '../../../app/inc.php';
/**
* Remove times from timetable and update teamtable with new times
*/
use App\Teamtable\Team;
use App\Teamtable\TeamMapper;
use App\Timetable\Time;
use App\Timetable\TimeMapper;
$teamMapper = new TeamMapper($app->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);
}