Commit
This commit is contained in:
parent
cdd1fa0575
commit
1144fc16f6
@ -54,4 +54,10 @@ class TimeMapper
|
|||||||
$lastId = $this->dbh->lastInsertId();
|
$lastId = $this->dbh->lastInsertId();
|
||||||
return $this->get($lastId);
|
return $this->get($lastId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function delete(int $id): void
|
||||||
|
{
|
||||||
|
$sth = $this->dbh->prepare('DELETE FROM tidtabell WHERE TidID = ?');
|
||||||
|
$sth->execute([$id]);
|
||||||
|
}
|
||||||
}
|
}
|
@ -22,35 +22,43 @@ class Cardreader
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: yeah this sucks but it werks!
|
|
||||||
* Returns:
|
* Returns:
|
||||||
* 0 created team
|
* 0 created team
|
||||||
* 1 started counting
|
* 1 started counting
|
||||||
* 2 counted round
|
* 2 counted too fast!
|
||||||
* 3 counted too fast
|
* 3 counted round
|
||||||
|
* 4 counted round, new best!
|
||||||
*/
|
*/
|
||||||
public function receive(string $cardnumber, int $timeout): int
|
public function receive(string $cardnumber, int $timeout): int
|
||||||
{
|
{
|
||||||
$team = $this->teamMapper->getByCardnumber($cardnumber);
|
$team = $this->teamMapper->getByCardnumber($cardnumber);
|
||||||
if ($team)
|
if (!$team)
|
||||||
{
|
{
|
||||||
// team exists, insert into time table
|
// team does not exist, lets create it
|
||||||
// and update team table best time
|
$team = new Team;
|
||||||
$prev_time = $this->timeMapper->getLatestByTeamId($team->id);
|
$team->setCardnumber($cardnumber);
|
||||||
|
$this->teamMapper->create($team);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// team exists, insert into time table
|
||||||
|
// and update team best time
|
||||||
|
$prev_time = $this->timeMapper->getLatestByTeamId($team->id);
|
||||||
$new_time = new Time;
|
$new_time = new Time;
|
||||||
$new_time->setTeamId($team->id);
|
$new_time->setTeamId($team->id);
|
||||||
// TODO: have this happen later so that it does not count when timeout
|
|
||||||
$new_time = $this->timeMapper->create($new_time);
|
$new_time = $this->timeMapper->create($new_time);
|
||||||
|
|
||||||
// calculate best time for this team
|
if ($prev_time === NULL)
|
||||||
if ($prev_time !== NULL)
|
|
||||||
{
|
{
|
||||||
$diff = $new_time->date->getTimestamp() - $prev_time->date->getTimestamp();
|
// team has not ran previously
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
$diff = $new_time->date->getTimestamp() - $prev_time->date->getTimestamp();
|
||||||
if ($diff <= $timeout)
|
if ($diff <= $timeout)
|
||||||
{
|
{
|
||||||
return 3;
|
$this->timeMapper->delete($new_time->id); // i mean... it works?
|
||||||
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
$team->rounds += 1;
|
$team->rounds += 1;
|
||||||
@ -66,16 +74,8 @@ class Cardreader
|
|||||||
{
|
{
|
||||||
$team->bestTime = $diff;
|
$team->bestTime = $diff;
|
||||||
$this->teamMapper->update($team);
|
$this->teamMapper->update($team);
|
||||||
|
return 4;
|
||||||
}
|
}
|
||||||
return 2;
|
return 3;
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
// team does not exist, lets create it
|
|
||||||
$team = new Team;
|
|
||||||
$team->setCardnumber($cardnumber);
|
|
||||||
$this->teamMapper->create($team);
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -19,15 +19,19 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST')
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
$app->session->flash('Startet telling', 'success');
|
$app->session->flash('Startet telling', 'info');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
$app->session->flash('Passerte en runde', 'success');
|
$app->session->flash('Runde gikk for fort!', 'danger');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
$app->session->flash('Runde gikk for fort!', 'danger');
|
$app->session->flash('Passerte en runde', 'info');
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 4:
|
||||||
|
$app->session->flash('Passerte en runde, ny rekord!', 'success');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
Reference in New Issue
Block a user