diff options
author | Joas Schilling <coding@schilljs.com> | 2020-10-27 18:49:16 +0300 |
---|---|---|
committer | Joas Schilling <coding@schilljs.com> | 2020-10-30 12:38:52 +0300 |
commit | d907221b601029b1db4420bc2dd7a811d937326e (patch) | |
tree | 3dd4433b8bdd8b37f2b419555ab8166ce65282bc /lib/Room.php | |
parent | 2891f29afcd83220aa4c0d4a00930dbad4aaa7af (diff) |
Add an endpoint to validate a PIN for a given conversation
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib/Room.php')
-rw-r--r-- | lib/Room.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/Room.php b/lib/Room.php index 932edcfcf..16a267a85 100644 --- a/lib/Room.php +++ b/lib/Room.php @@ -402,6 +402,32 @@ class Room { return $this->manager->createParticipantObject($this, $row); } + /** + * @param string $pin + * @return Participant + * @throws ParticipantNotFoundException When the pin is not valid (has no participant assigned) + */ + public function getParticipantByPin(string $pin): Participant { + $query = $this->db->getQueryBuilder(); + $query->select('*') + ->selectAlias('a.id', 'a_id') + ->selectAlias('s.id', 's_id') + ->from('talk_attendees', 'a') + ->leftJoin('a', 'talk_sessions', 's', $query->expr()->eq('a.id', 's.attendee_id')) + ->andWhere($query->expr()->eq('a.pin', $query->createNamedParameter($pin))) + ->andWhere($query->expr()->eq('a.room_id', $query->createNamedParameter($this->getId()))) + ->setMaxResults(1); + $result = $query->execute(); + $row = $result->fetch(); + $result->closeCursor(); + + if ($row === false) { + throw new ParticipantNotFoundException('User is not a participant'); + } + + return $this->manager->createParticipantObject($this, $row); + } + public function deleteRoom(): void { $event = new RoomEvent($this); $this->dispatcher->dispatch(self::EVENT_BEFORE_ROOM_DELETE, $event); |