43 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			43 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
| <?php
 | |
| 
 | |
| use App\Core\Database;
 | |
| use App\Teamtable\Team;
 | |
| use App\Teamtable\TeamMapper;
 | |
| use App\Timetable\Time;
 | |
| use App\Timetable\TimeMapper;
 | |
| 
 | |
| class Cardreader
 | |
| {
 | |
|     public PDO $dbh;
 | |
| 
 | |
|     public TeamMapper $teamMapper;
 | |
| 
 | |
|     public TimeMapper $timeMapper;
 | |
| 
 | |
|     public function __construct(Database $database)
 | |
|     {
 | |
|         $this->dbh = $database->conn;
 | |
|         $this->teamMapper = new TeamMapper($this->dbh);
 | |
|         $this->timeMapper = new TimeMapper($this->dbh);
 | |
|     }
 | |
| 
 | |
|     /**
 | |
|      * Returns TRUE if team exists, FALSE if not
 | |
|      */
 | |
|     public function receive(string $cardnumber, int $timeout): bool 
 | |
|     {
 | |
|         $team = $this->teamMapper->getByCardnumber($cardnumber);
 | |
|         if ($team)
 | |
|         {
 | |
|             // team exists, insert into time table
 | |
|             $sth = $this->dbh->prepare('INSERT INTO tidtabell (LagID) VALUES (?)');
 | |
|             $sth->execute([$team->id]);
 | |
|             return TRUE;
 | |
|         }
 | |
|         // team does not exist, lets create it
 | |
|         $team = new Team;
 | |
|         $team->cardnumber = $cardnumber;
 | |
|         $this->teamMapper->create($team);
 | |
|         return FALSE;
 | |
|     }
 | |
| } |