Stunden ende, einiges fertig, fehlt nicht mehr viel
Took 2 hours 31 minutes
This commit is contained in:
40
model/DefaultModel.class.inc.php
Normal file → Executable file
40
model/DefaultModel.class.inc.php
Normal file → Executable file
@ -3,8 +3,44 @@
|
||||
|
||||
class DefaultModel
|
||||
{
|
||||
public function getTestMessage()
|
||||
public function redirectToStart($string)
|
||||
{
|
||||
return "Rabbits can't fly without Red Bull.";
|
||||
header( "Location: ?c=default&a=index&rsn=$string" );
|
||||
exit();
|
||||
}
|
||||
|
||||
public function checkCode($room_code)
|
||||
{
|
||||
$stmnt = Database::getConnection()->prepare( 'SELECT id FROM rooms WHERE code = :code' );
|
||||
$stmnt->execute( array( 'code' => $room_code ) );
|
||||
|
||||
$result = $stmnt->fetch( PDO::FETCH_ASSOC );
|
||||
if( $result === false || empty( $result ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $result['id'];
|
||||
}
|
||||
|
||||
public function joinRoom($room_id)
|
||||
{
|
||||
$_SESSION['room'] = $room_id;
|
||||
header( 'Location: ?c=faq' );
|
||||
return true;
|
||||
}
|
||||
|
||||
public function createRoom(string $room_name)
|
||||
{
|
||||
$room_owner = session_id();
|
||||
$stmnt = Database::getConnection()->prepare( 'INSERT INTO rooms ( name, owner, code ) VALUES ( :name, :owner, :code )' );
|
||||
$stmnt->execute( array( 'name' => $room_name, 'owner' => $room_owner, 'code' => $this->generateRandomStr() ) );
|
||||
|
||||
}
|
||||
|
||||
public function generateRandomStr( $length = 4 )
|
||||
{
|
||||
return 'U2HA';
|
||||
}
|
||||
|
||||
|
||||
}
|
90
model/FaqModel.class.inc.php
Normal file
90
model/FaqModel.class.inc.php
Normal file
@ -0,0 +1,90 @@
|
||||
<?php
|
||||
|
||||
|
||||
class FaqModel
|
||||
{
|
||||
|
||||
public function redirectToStart($string)
|
||||
{
|
||||
header( "Location: ?c=default&a=index&rsn=$string" );
|
||||
exit();
|
||||
}
|
||||
|
||||
public function getRoom( )
|
||||
{
|
||||
if( !isset( $_SESSION['room'] ) )
|
||||
{
|
||||
$this->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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user