This repository has been archived on 2023-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
web/public/race/configure/reset.php
2022-03-20 22:02:26 +01:00

43 lines
982 B
PHP

<?php $app = require '../../../app/inc.php';
/**
* Resets team counters and removes all time records
*/
use App\Teamtable\Team;
use App\Teamtable\TeamMapper;
use App\Timetable\Time;
use App\Timetable\TimeMapper;
$confirm = filter_input(INPUT_GET, 'confirm', FILTER_VALIDATE_BOOLEAN);
if (!$confirm)
{
$app->view('template/header', ['title' => 'Nullstill runder']);
$app->view('pages/race/configure/reset');
$app->view('template/footer');
die();
}
$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);
}
$app->session->flash("Runder er nullstilt", "success");
$app->redirect("index.php");