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/app/model/Simulator.php
2022-01-26 14:38:22 +01:00

33 lines
1.0 KiB
PHP

<?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;
}
}