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/teams/delete.php

44 lines
1.2 KiB
PHP

<?php $app = require '../../../../app/inc.php';
/**
* Deletes both team and related times
*/
use App\Teamtable\Team;
use App\Teamtable\TeamMapper;
use App\Timetable\TimeMapper;
$item = filter_input(INPUT_GET, 'item', FILTER_VALIDATE_INT);
$confirm = filter_input(INPUT_GET, 'confirm', FILTER_VALIDATE_BOOLEAN);
$team_mapper = new TeamMapper($app->database->conn);
$time_mapper = new TimeMapper($app->database->conn);
// item is NULL if not set
if ($item === NULL)
{
$app->session->flash('Kunne ikke slette lag: Mangler parameter.', 'danger');
$app->redirect('index.php');
}
$team = $team_mapper->get($item);
if (!$team)
{
// team does not exist
$app->session->flash('Kunne ikke slette lag: Lag eksisterer ikke', 'danger');
$app->redirect('index.php');
}
// show confirmation page
if (!$confirm)
{
$app->view('template/header', ['title' => 'Bekreft sletting']);
$app->view('pages/race/configure/teams/delete', ['team' => $team]);
$app->view('template/footer');
die();
}
// all is good, lets delete the team and related times
$time_mapper->deleteByTeamId($team->id);
$team_mapper->delete($team->id);
$app->session->flash("Slettet lag: {$team->name}", "success");
$app->redirect('index.php');