TODO commit

This commit is contained in:
William 2022-03-02 14:26:02 +01:00
parent 061947f9a5
commit 9af3df155b
3 changed files with 108 additions and 12 deletions

View File

@ -3,9 +3,96 @@
namespace App\Teamtable; namespace App\Teamtable;
/** /**
* Represents a team in the teamtable * Represents a team in the teamtable database
*/ */
class Team 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;
}
}
} }

View File

@ -1,19 +1,16 @@
<?php <?php
use App\Core\Database as Database; use App\Core\Database as Database;
use App\Teamtable\Team as Team;
/**
* Do stuff with the teamtable
*/
class Teamtable class Teamtable
{ {
public array $template = [ /**
'LagNavn' => 'NN', * Database handler
'Bedrift' => 'NN', */
'Kortnummer' => 'NN',
'Lagleder' => 'NN',
'Telefon' => 0,
'Deltagere' => 0,
'Runder' => 0
];
public PDO $dbh; public PDO $dbh;
public function __construct(Database $database) public function __construct(Database $database)
@ -21,12 +18,18 @@ class Teamtable
$this->dbh = $database->conn; $this->dbh = $database->conn;
} }
/**
* Fetch entire team table
*/
public function getTable(): array public function getTable(): array
{ {
$sth = $this->dbh->query('SELECT * FROM lagtabell'); $sth = $this->dbh->query('SELECT * FROM lagtabell');
return $sth->fetchAll(PDO::FETCH_ASSOC); return $sth->fetchAll(PDO::FETCH_ASSOC);
} }
/**
* Delete team with supplied id
*/
public function deleteTeamByID(int $LagID): void public function deleteTeamByID(int $LagID): void
{ {
$sth = $this->dbh->prepare('DELETE FROM lagtabell WHERE LagID = ?'); $sth = $this->dbh->prepare('DELETE FROM lagtabell WHERE LagID = ?');

6
public/testing.php Normal file
View File

@ -0,0 +1,6 @@
<?php
$app = require '../app/inc.php';
$team = new App\Teamtable\Team;
var_dump($team);