Commit
This commit is contained in:
parent
83a647cc26
commit
24df7e272e
38
app/model/Cardreader.php
Normal file
38
app/model/Cardreader.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?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;
|
||||||
|
}
|
||||||
|
}
|
@ -9,9 +9,6 @@ use App\Teamtable\TeamMapper as TeamMapper;
|
|||||||
*/
|
*/
|
||||||
class Teamtable
|
class Teamtable
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Database connection
|
|
||||||
*/
|
|
||||||
public PDO $dbh;
|
public PDO $dbh;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -41,11 +38,6 @@ class Teamtable
|
|||||||
return $this->teamMapper->get($id);
|
return $this->teamMapper->get($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getByCardnumber(string $cardnumber): ?Team
|
|
||||||
{
|
|
||||||
return $this->teamMapper->getByCardnumber($cardnumber);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inserts team into database
|
* Inserts team into database
|
||||||
*/
|
*/
|
||||||
@ -63,25 +55,4 @@ class Teamtable
|
|||||||
{
|
{
|
||||||
return $this->teamMapper->update($team);
|
return $this->teamMapper->update($team);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns TRUE if team exists, FALSE if not
|
|
||||||
* TODO: maybe use integers instead of booleans for codes
|
|
||||||
*/
|
|
||||||
public function recieveBaton(string $cardnumber): bool
|
|
||||||
{
|
|
||||||
$team = $this->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->create($team);
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
// TODO: refactor
|
// TODO: refactor
|
||||||
|
|
||||||
$model = $app->model('Teamtable');
|
$cardreader = $app->model('Cardreader');
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST')
|
if ($_SERVER['REQUEST_METHOD'] === 'POST')
|
||||||
{
|
{
|
||||||
@ -11,7 +11,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST')
|
|||||||
$cardnumber = $_POST['cardnumber'];
|
$cardnumber = $_POST['cardnumber'];
|
||||||
|
|
||||||
if (!(strlen($cardnumber) > 32)) {
|
if (!(strlen($cardnumber) > 32)) {
|
||||||
if ($model->recieveBaton($cardnumber))
|
if ($cardreader->recieve($cardnumber))
|
||||||
{
|
{
|
||||||
$app->session->flash("Lag funnet for \"{$cardnumber}\"", "success");
|
$app->session->flash("Lag funnet for \"{$cardnumber}\"", "success");
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user