From 9af3df155b6d3c61403e579e9a3bc071b7bf0fd5 Mon Sep 17 00:00:00 2001 From: William Date: Wed, 2 Mar 2022 14:26:02 +0100 Subject: [PATCH] TODO commit --- app/lib/App/Teamtable/Team.php | 91 +++++++++++++++++++++++++++++++++- app/model/Teamtable.php | 23 +++++---- public/testing.php | 6 +++ 3 files changed, 108 insertions(+), 12 deletions(-) create mode 100644 public/testing.php diff --git a/app/lib/App/Teamtable/Team.php b/app/lib/App/Teamtable/Team.php index 2a74912..62a1f16 100644 --- a/app/lib/App/Teamtable/Team.php +++ b/app/lib/App/Teamtable/Team.php @@ -3,9 +3,96 @@ namespace App\Teamtable; /** - * Represents a team in the teamtable + * Represents a team in the teamtable database */ class Team { - // TODO... + public string $name; + public string $company; + public string $cardnumber; + public int $phone; + public int $participants; + public int $rounds; + + public function __construct( + string $name = 'NN', + string $company = 'NN', + string $cardnumber = 'NN', + int $phone = 0, + int $participants = 0, + int $rounds = 0 + ) + { + $this->name = $name; + $this->company = $company; + $this->cardnumber = $cardnumber; + $this->phone = $phone; + $this->participants = $participants; + $this->rounds = $rounds; + } + + /** + * Check if all current values are valid + */ + public function validate(): bool + { + $validationError = FALSE; + $template = $model->template; + + // LagNavn + if (!strlen($LagNavn)) { + $LagNavn = $template['LagNavn']; + } + if (strlen($LagNavn) > 32) { + $validationError = TRUE; + } + + // Bedrift + if (!strlen($Bedrift)) { + $Bedrift = $template['Bedrift']; + } + if (strlen($Bedrift) > 32) { + $validationError = TRUE; + } + + // Kortnummer + if (!strlen($Kortnummer)) { + $Kortnummer = $template['Kortnummer']; + } + if (strlen($Kortnummer) > 32) { + $validationError = TRUE; + } + + // Lagleder + if (!strlen($Lagleder)) { + $Lagleder = $template['Lagleder']; + } + if (strlen($Lagleder) > 32) { + $validationError = TRUE; + } + + // Telefon + if (!strlen($Telefon)) { + $Telefon = $template['Telefon']; + } + if (strlen((string) $Telefon) > 32) { + $validationError = TRUE; + } + + // Deltagere + if (!strlen($Deltagere)) { + $Deltagere = $template['Deltagere']; + } + if (strlen((string) $Deltagere) > 32) { + $validationError = TRUE; + } + + // Runder + if (!strlen($Runder)) { + $Runder = $template['Runder']; + } + if (strlen((string) $Runder) > 32) { + $validationError = TRUE; + } + } } \ No newline at end of file diff --git a/app/model/Teamtable.php b/app/model/Teamtable.php index 33a5d04..c21ceee 100644 --- a/app/model/Teamtable.php +++ b/app/model/Teamtable.php @@ -1,19 +1,16 @@ 'NN', - 'Bedrift' => 'NN', - 'Kortnummer' => 'NN', - 'Lagleder' => 'NN', - 'Telefon' => 0, - 'Deltagere' => 0, - 'Runder' => 0 - ]; - + /** + * Database handler + */ public PDO $dbh; public function __construct(Database $database) @@ -21,12 +18,18 @@ class Teamtable $this->dbh = $database->conn; } + /** + * Fetch entire team table + */ public function getTable(): array { $sth = $this->dbh->query('SELECT * FROM lagtabell'); return $sth->fetchAll(PDO::FETCH_ASSOC); } + /** + * Delete team with supplied id + */ public function deleteTeamByID(int $LagID): void { $sth = $this->dbh->prepare('DELETE FROM lagtabell WHERE LagID = ?'); diff --git a/public/testing.php b/public/testing.php new file mode 100644 index 0000000..6cee1da --- /dev/null +++ b/public/testing.php @@ -0,0 +1,6 @@ +