Almost done, just the answer system and query is missing
Took 4 hours 10 minutes
This commit is contained in:
@ -32,14 +32,26 @@ class DefaultModel
|
||||
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() ) );
|
||||
$stmnt = Database::getConnection()->prepare( 'INSERT INTO rooms ( name, owner_sid, code ) VALUES ( :name, :owner, :code )' );
|
||||
$stmnt->execute( array( 'name' => $room_name, 'owner' => $room_owner, 'code' => $this->generateRandomStr( CODE_LENGTH ) ) );
|
||||
|
||||
$id = Database::getConnection()->lastInsertId( );
|
||||
if( empty( $id ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function generateRandomStr( $length = 4 )
|
||||
{
|
||||
return 'U2HA';
|
||||
$characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
|
||||
|
@ -56,14 +56,14 @@ class FaqModel
|
||||
return $result['id'];
|
||||
}
|
||||
|
||||
public function addQuestion(int $room_id, bool $question)
|
||||
public function addQuestion(int $room_id, string $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' ) );
|
||||
$stmnt->execute( array( 'room_id' => $room_id, 'question' => $question, 'created_by' => 'Anonymous' ) );
|
||||
|
||||
}
|
||||
|
||||
public function addAnswer(int $question_id, bool $answer)
|
||||
public function addAnswer(int $question_id, string $answer)
|
||||
{
|
||||
$stmnt = Database::getConnection()->prepare( 'UPDATE questions SET answer = :answer WHERE id = :id' );
|
||||
$stmnt->execute( array( 'answer' => $answer, 'id' => $question_id ) );
|
||||
|
Reference in New Issue
Block a user