T201704031352
This commit is contained in:
13
Question.php
13
Question.php
@@ -13,13 +13,12 @@ class Question
|
|||||||
{
|
{
|
||||||
private $question;
|
private $question;
|
||||||
private $answers;
|
private $answers;
|
||||||
private $correct_answer_position;
|
|
||||||
private $category_id;
|
private $category_id;
|
||||||
private $category;
|
private $category;
|
||||||
|
|
||||||
function __construct($db, $id) {
|
function __construct($db, $uid, $qid) {
|
||||||
$question_details = $db->query('SELECT "question", "answer0", "answer1", "answer2", "answer3", "Categories_ID"
|
$question_details = $db->query('SELECT "question", "answer0", "answer1", "answer2", "answer3", "Categories_ID"
|
||||||
FROM "Questions" WHERE "ID" = $1', array($id))['data'][0];
|
FROM "Questions" WHERE "ID" = $1', array($qid))['data'][0];
|
||||||
$q = $question_details['question'];
|
$q = $question_details['question'];
|
||||||
$a0 = $question_details['answer0'];
|
$a0 = $question_details['answer0'];
|
||||||
$a1 = $question_details['answer1'];
|
$a1 = $question_details['answer1'];
|
||||||
@@ -29,19 +28,17 @@ class Question
|
|||||||
$c = $db->query('SELECT "name" FROM "Categories" WHERE "ID" = $1', array($cid))['data'][0]['name'];
|
$c = $db->query('SELECT "name" FROM "Categories" WHERE "ID" = $1', array($cid))['data'][0]['name'];
|
||||||
$this->question = $q;
|
$this->question = $q;
|
||||||
$this->answers = array($a0, $a1, $a2, $a3);
|
$this->answers = array($a0, $a1, $a2, $a3);
|
||||||
print_r($this->answers);
|
|
||||||
shuffle($this->answers);
|
shuffle($this->answers);
|
||||||
print_r($this->answers);
|
$ca_position = array_search($a0, $this->answers);
|
||||||
$this->correct_answer_position = array_search($a0, $this->answers);
|
|
||||||
print_r($this->correct_answer_position);
|
|
||||||
$this->category_id = $cid;
|
$this->category_id = $cid;
|
||||||
$this->category = $c;
|
$this->category = $c;
|
||||||
|
$db->query('UPDATE "Games" SET "current_right_answer" = $1 WHERE "ID" = $2', array($ca_position, $uid));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function get_next_question($db, $uid) {
|
public static function get_next_question($db, $uid) {
|
||||||
$qid = $db->query('SELECT "Questions_ID" FROM "GamesQuestions" WHERE "Games_ID" = $1 LIMIT 1', array($uid))
|
$qid = $db->query('SELECT "Questions_ID" FROM "GamesQuestions" WHERE "Games_ID" = $1 LIMIT 1', array($uid))
|
||||||
['data'][0]['Questions_ID'];
|
['data'][0]['Questions_ID'];
|
||||||
$question = new Question($db, $qid);
|
$question = new Question($db, $uid, $qid);
|
||||||
$db->query('DELETE FROM "GamesQuestions" WHERE "Games_ID" = $1 AND "Questions_ID" = $2', array($uid, $qid));
|
$db->query('DELETE FROM "GamesQuestions" WHERE "Games_ID" = $1 AND "Questions_ID" = $2', array($uid, $qid));
|
||||||
$question_object = $question->get_question_object();
|
$question_object = $question->get_question_object();
|
||||||
return $question_object;
|
return $question_object;
|
||||||
|
|||||||
Reference in New Issue
Block a user