redirectToStart( 'no-code' ); } if( ( $id = $this->checkID( $_SESSION['room'] ) ) === false ) { $this->redirectToStart( 'invalid' ); } $stmnt = Database::getConnection()->prepare( 'SELECT * FROM rooms WHERE id = :id' ); $stmnt->execute( array( 'id' => $id ) ); return $stmnt->fetch( PDO::FETCH_ASSOC ); } public function getQuestions( $room_id ) { $stmnt = Database::getConnection()->prepare( 'SELECT * FROM questions WHERE room_id = :id' ); $stmnt->execute( array( 'id' => $room_id ) ); $result = $stmnt->fetchAll( PDO::FETCH_ASSOC ); if( $result === false || empty( $result ) ) { return false; } return $result; } private function checkID($room_id) { $stmnt = Database::getConnection()->prepare( 'SELECT id FROM rooms WHERE id = :id' ); $stmnt->execute( array( 'id' => $room_id ) ); $result = $stmnt->fetch( PDO::FETCH_ASSOC ); if( $result === false || empty( $result ) ) { return false; } return $result['id']; } public function addQuestion(int $room_id, bool $question) { $stmnt = Database::getConnection()->prepare( 'INSERT INTO questions ( room_id, question, created_by ) VALUES ( :room_id, :question, :created_by )' ); $stmnt->execute( array( 'room_id' => $room_id, $question, 'Anonymous' ) ); } public function addAnswer(int $question_id, bool $answer) { $stmnt = Database::getConnection()->prepare( 'UPDATE questions SET answer = :answer WHERE id = :id' ); $stmnt->execute( array( 'answer' => $answer, 'id' => $question_id ) ); } public function checkUserIsRoomOwner( array $a_room ) { $stmnt = Database::getConnection()->prepare( 'SELECT owner_sid FROM rooms WHERE id = :id' ); $stmnt->execute( array( 'id' => $a_room['id'] ) ); $result = $stmnt->fetchAll( PDO::FETCH_ASSOC ); if( $result === false || empty( $result ) ) { return false; } if( $result['owner_sid'] === session_id() ) { return true; } return false; } }