Commit
This commit is contained in:
parent
9eab1bafaf
commit
136b7b2e4b
@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
class Simulator
|
||||
{
|
||||
public PDO $dbh;
|
||||
|
||||
public function __construct(Database $database)
|
||||
{
|
||||
$this->dbh = $database->conn;
|
||||
}
|
||||
|
||||
// Return true if team exists, false if not
|
||||
public function insert(string $cardnumber): bool
|
||||
{
|
||||
$sth = $this->dbh->prepare('SELECT * FROM lagtabell WHERE Kortnummer = ?');
|
||||
$sth->execute([$cardnumber]);
|
||||
|
||||
$row = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row)
|
||||
{
|
||||
// Team exists, insert into time table
|
||||
$sth = $this->dbh->prepare('INSERT INTO tidtabell (LagID) VALUES (?)');
|
||||
$sth->execute([$row['LagID']]);
|
||||
return TRUE;
|
||||
}
|
||||
// Team does not exist, lets create it
|
||||
$sth = $this->dbh->prepare(
|
||||
"INSERT INTO `lagtabell` (`LagID`, `LagNavn`, `Bedrift`, `Kortnummer`, `Lagleder`, `Telefon`, `Deltagere`, `Runder`, `Bestetid`) VALUES (NULL, 'NN', 'NN', ?, 'NN', '0', '0', '0', now())"
|
||||
);
|
||||
$sth->execute([$cardnumber]);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
@ -93,4 +93,36 @@ class Teamtable
|
||||
}
|
||||
return $equal;
|
||||
}
|
||||
|
||||
// Return true if team exists, false if not
|
||||
public function insert(string $cardnumber): bool
|
||||
{
|
||||
$sth = $this->dbh->prepare('SELECT * FROM lagtabell WHERE Kortnummer = ?');
|
||||
$sth->execute([$cardnumber]);
|
||||
|
||||
$row = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
if ($row)
|
||||
{
|
||||
// Team exists, insert into time table
|
||||
$sth = $this->dbh->prepare('INSERT INTO tidtabell (LagID) VALUES (?)');
|
||||
$sth->execute([$row['LagID']]);
|
||||
return TRUE;
|
||||
}
|
||||
// Team does not exist, lets create it
|
||||
$sth = $this->dbh->prepare(
|
||||
"INSERT INTO `lagtabell` (`LagNavn`, `Bedrift`, `Kortnummer`, `Lagleder`, `Telefon`, `Deltagere`, `Runder`) VALUES (?, ?, ?, ?, ?, ?, ?)"
|
||||
);
|
||||
$template = $this->emptyTeamTemplate;
|
||||
$template = [
|
||||
$template['LagNavn'],
|
||||
$template['Bedrift'],
|
||||
$cardnumber,
|
||||
$template['Lagleder'],
|
||||
$template['Telefon'],
|
||||
$template['Deltagere'],
|
||||
$template['Runder'],
|
||||
];
|
||||
$sth->execute($template);
|
||||
return FALSE;
|
||||
}
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
$app = require '../app/inc.php';
|
||||
$model = $app->model('Simulator');
|
||||
$model = $app->model('Teamtable');
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST')
|
||||
{
|
||||
|
Reference in New Issue
Block a user