TODO commit
This commit is contained in:
		
							parent
							
								
									061947f9a5
								
							
						
					
					
						commit
						9af3df155b
					
				| @ -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; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -1,19 +1,16 @@ | ||||
| <?php | ||||
| 
 | ||||
| use App\Core\Database as Database; | ||||
| use App\Teamtable\Team as Team; | ||||
| 
 | ||||
| /** | ||||
|  * Do stuff with the teamtable | ||||
|  */ | ||||
| class Teamtable | ||||
| { | ||||
|     public array $template = [ | ||||
|         'LagNavn'    => '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 = ?'); | ||||
|  | ||||
							
								
								
									
										6
									
								
								public/testing.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								public/testing.php
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,6 @@ | ||||
| <?php | ||||
| $app = require '../app/inc.php'; | ||||
| 
 | ||||
| $team = new App\Teamtable\Team; | ||||
| 
 | ||||
| var_dump($team); | ||||
		Reference in New Issue
	
	Block a user