This repository has been archived on 2023-01-06. You can view files and clone it, but cannot push or open issues or pull requests.
web/app/model/Cardreader.php
2022-03-10 16:52:59 +01:00

38 lines
970 B
PHP

<?php
use App\Core\Database as Database;
use App\Teamtable\TeamMapper as TeamMapper;
use App\Teamtable\Team as Team;
class Cardreader
{
public PDO $dbh;
public TeamMapper $teamMapper;
public function __construct(Database $database)
{
$this->dbh = $database->conn;
$this->teamMapper = new TeamMapper($this->dbh);
}
/**
* Returns TRUE if team exists, FALSE if not
*/
public function recieve(string $cardnumber): 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;
}
}