From 136b7b2e4b1d8b4b7733b06a85088cd1a4648900 Mon Sep 17 00:00:00 2001 From: William Date: Tue, 15 Feb 2022 12:40:57 +0100 Subject: [PATCH] Commit --- app/model/Simulator.php | 33 --------------------------------- app/model/Teamtable.php | 32 ++++++++++++++++++++++++++++++++ public/simulator.php | 2 +- 3 files changed, 33 insertions(+), 34 deletions(-) delete mode 100644 app/model/Simulator.php diff --git a/app/model/Simulator.php b/app/model/Simulator.php deleted file mode 100644 index b4d63f1..0000000 --- a/app/model/Simulator.php +++ /dev/null @@ -1,33 +0,0 @@ -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; - } -} \ No newline at end of file diff --git a/app/model/Teamtable.php b/app/model/Teamtable.php index 1247076..741d15a 100644 --- a/app/model/Teamtable.php +++ b/app/model/Teamtable.php @@ -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; + } } \ No newline at end of file diff --git a/public/simulator.php b/public/simulator.php index 9ff35c3..60034e5 100644 --- a/public/simulator.php +++ b/public/simulator.php @@ -1,6 +1,6 @@ model('Simulator'); +$model = $app->model('Teamtable'); if ($_SERVER['REQUEST_METHOD'] === 'POST') {