Commit
This commit is contained in:
parent
635ec094d1
commit
2cfbd9c557
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
|
||||
use App\Core\Database;
|
||||
use App\Teamtable\Team;
|
||||
use App\Teamtable\TeamMapper;
|
||||
|
||||
/**
|
||||
* Does stuffs with the teamtable
|
||||
*/
|
||||
class Teamtable
|
||||
{
|
||||
public PDO $dbh;
|
||||
|
||||
public TeamMapper $teamMapper;
|
||||
|
||||
public function __construct(Database $database)
|
||||
{
|
||||
$this->dbh = $database->conn;
|
||||
$this->teamMapper = new TeamMapper($this->dbh);
|
||||
}
|
||||
|
||||
public function getAll(): array
|
||||
{
|
||||
return $this->teamMapper->getAll();
|
||||
}
|
||||
|
||||
public function get(int $id): ?Team
|
||||
{
|
||||
return $this->teamMapper->get($id);
|
||||
}
|
||||
|
||||
public function create(Team $team): Team
|
||||
{
|
||||
return $this->teamMapper->create($team);
|
||||
}
|
||||
|
||||
public function delete(int $id): void
|
||||
{
|
||||
$this->teamMapper->delete($id);
|
||||
}
|
||||
|
||||
public function update(Team $team): Team
|
||||
{
|
||||
return $this->teamMapper->update($team);
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
<?php $app = require '../../../../app/inc.php';
|
||||
|
||||
use App\Teamtable\Team;
|
||||
use App\Teamtable\TeamMapper;
|
||||
|
||||
$item = filter_input(INPUT_GET, 'item', FILTER_VALIDATE_INT);
|
||||
$confirm = filter_input(INPUT_GET, 'confirm', FILTER_VALIDATE_BOOLEAN);
|
||||
|
||||
$model = $app->model('Teamtable');
|
||||
$teamMapper = new TeamMapper($app->database->conn);
|
||||
|
||||
// item is NULL if not set
|
||||
if ($item === NULL)
|
||||
@ -14,7 +15,7 @@ if ($item === NULL)
|
||||
$app->redirect('index.php');
|
||||
}
|
||||
|
||||
$team = $model->get($item);
|
||||
$team = $teamMapper->get($item);
|
||||
if (!$team)
|
||||
{
|
||||
// team does not exist
|
||||
@ -32,6 +33,6 @@ if (!$confirm)
|
||||
}
|
||||
|
||||
// all is good, lets delete the team
|
||||
$model->delete($team->id);
|
||||
$teamMapper->delete($team->id);
|
||||
$app->session->flash("Slettet lag: {$team->name}", "success");
|
||||
$app->redirect('index.php');
|
@ -1,8 +1,10 @@
|
||||
<?php $app = require '../../../../app/inc.php';
|
||||
|
||||
$model = $app->model('Teamtable');
|
||||
use App\Teamtable\TeamMapper;
|
||||
|
||||
$teams = $model->getAll();
|
||||
$teamMapper = new TeamMapper($app->database->conn);
|
||||
|
||||
$teams = $teamMapper->getAll();
|
||||
|
||||
$app->view('template/header', ['title' => 'Endre lagtabell']);
|
||||
$app->view('pages/race/configure/teams/index', ["teams" => $teams]);
|
||||
|
@ -4,15 +4,16 @@
|
||||
*/
|
||||
|
||||
use App\Teamtable\Team;
|
||||
use App\Teamtable\TeamMapper;
|
||||
|
||||
$item = filter_input(INPUT_GET, 'item', FILTER_VALIDATE_INT);
|
||||
|
||||
$model = $app->model('Teamtable');
|
||||
$teamMapper = new TeamMapper($app->database->conn);
|
||||
|
||||
$team;
|
||||
if ($item !== NULL)
|
||||
{
|
||||
$team = $model->get($item);
|
||||
$team = $teamMapper->get($item);
|
||||
if (!$team)
|
||||
{
|
||||
// team does not exist
|
||||
@ -47,12 +48,12 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST')
|
||||
{
|
||||
// team exists, lets update it
|
||||
$team->id = $item;
|
||||
$model->update($team);
|
||||
$teamMapper->update($team);
|
||||
$app->session->flash('Oppdaterte lag', 'success');
|
||||
$app->redirect('index.php');
|
||||
}
|
||||
// no team was specified, lets create one
|
||||
$model->create($team);
|
||||
$teamMapper->create($team);
|
||||
$app->session->flash('Opprettet nytt lag', 'success');
|
||||
$app->redirect('index.php');
|
||||
}
|
||||
|
Reference in New Issue
Block a user