diff --git a/app/lib/App/Teamtable/TeamMapper.php b/app/lib/App/Teamtable/TeamMapper.php index 19732f0..ada2743 100644 --- a/app/lib/App/Teamtable/TeamMapper.php +++ b/app/lib/App/Teamtable/TeamMapper.php @@ -54,6 +54,18 @@ class TeamMapper #return $teams; } + public function getByCardnumber(string $cardnumber): ?Team + { + $sth = $this->dbh->prepare('SELECT * FROM lagtabell WHERE Kortnummer = ?'); + $sth->execute([$cardnumber]); + $row = $sth->fetch(PDO::FETCH_ASSOC); + if ($row) + { + return $this->mapRowToTeam($row); + } + return NULL; + } + public function get(int $id): ?Team { $sth = $this->dbh->prepare('SELECT * FROM lagtabell WHERE LagID = ?'); diff --git a/app/model/Teamtable.php b/app/model/Teamtable.php index 73dd1a5..71314a2 100644 --- a/app/model/Teamtable.php +++ b/app/model/Teamtable.php @@ -41,6 +41,11 @@ class Teamtable return $this->teamMapper->get($id); } + public function getByCardnumber(string $cardnumber): ?Team + { + return $this->teamMapper->getByCardnumber($cardnumber); + } + /** * Inserts team into database */ @@ -54,23 +59,29 @@ class Teamtable $this->teamMapper->delete($id); } + public function update(Team $team): 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->getTeamByCardnumber($cardnumber); + $team = $this->getByCardnumber($cardnumber); if ($team) { // team exists, insert into time table $sth = $this->dbh->prepare('INSERT INTO tidtabell (LagID) VALUES (?)'); - $sth->execute([$row['LagID']]); + $sth->execute([$team->id]); return TRUE; } // team does not exist, lets create it - $team = new Team(); + $team = new Team; $team->cardnumber = $cardnumber; - $this->addTeam($team); + $this->create($team); return FALSE; } } \ No newline at end of file diff --git a/app/view/pages/teamtable/edit/index.php b/app/view/pages/teamtable/edit/index.php index 5a0acf0..b299163 100644 --- a/app/view/pages/teamtable/edit/index.php +++ b/app/view/pages/teamtable/edit/index.php @@ -1,5 +1,5 @@