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

44 lines
1.2 KiB
PHP
Raw Permalink Normal View History

2022-04-26 19:55:10 +00:00
<?php $app = require '../../../app/inc.php';
2022-04-20 18:42:19 +00:00
/**
* Deletes both team and related times
*/
2022-02-09 15:59:20 +00:00
2022-03-07 06:13:17 +00:00
use App\Teamtable\Team;
2022-03-30 19:11:34 +00:00
use App\Teamtable\TeamMapper;
2022-04-20 18:42:19 +00:00
use App\Timetable\TimeMapper;
2022-02-09 15:59:20 +00:00
2022-03-07 06:13:17 +00:00
$item = filter_input(INPUT_GET, 'item', FILTER_VALIDATE_INT);
2022-03-07 07:24:45 +00:00
$confirm = filter_input(INPUT_GET, 'confirm', FILTER_VALIDATE_BOOLEAN);
2022-03-07 06:13:17 +00:00
2022-04-14 20:59:42 +00:00
$team_mapper = new TeamMapper($app->database->conn);
2022-04-20 18:42:19 +00:00
$time_mapper = new TimeMapper($app->database->conn);
2022-02-09 15:59:20 +00:00
2022-03-07 06:13:17 +00:00
// item is NULL if not set
if ($item === NULL)
2022-02-09 15:59:20 +00:00
{
2022-03-07 06:13:17 +00:00
$app->session->flash('Kunne ikke slette lag: Mangler parameter.', 'danger');
2022-02-09 15:59:20 +00:00
$app->redirect('index.php');
}
2022-04-14 20:59:42 +00:00
$team = $team_mapper->get($item);
2022-03-07 06:13:17 +00:00
if (!$team)
2022-02-09 15:59:20 +00:00
{
2022-03-07 06:13:17 +00:00
// team does not exist
$app->session->flash('Kunne ikke slette lag: Lag eksisterer ikke', 'danger');
2022-02-09 15:59:20 +00:00
$app->redirect('index.php');
}
2022-03-07 06:13:17 +00:00
// show confirmation page
2022-03-20 21:02:26 +00:00
if (!$confirm)
2022-02-14 01:52:59 +00:00
{
$app->view('template/header', ['title' => 'Bekreft sletting']);
2022-04-26 19:55:10 +00:00
$app->view('pages/race/configure/delete', ['team' => $team]);
2022-02-14 01:52:59 +00:00
$app->view('template/footer');
die();
}
2022-04-20 18:42:19 +00:00
// all is good, lets delete the team and related times
$time_mapper->deleteByTeamId($team->id);
2022-04-14 20:59:42 +00:00
$team_mapper->delete($team->id);
2022-03-07 06:13:17 +00:00
$app->session->flash("Slettet lag: {$team->name}", "success");
2022-02-09 15:59:20 +00:00
$app->redirect('index.php');