Exemplo n.º 1
0
 public static function GetQuestion($category)
 {
     $dbh = MySqlConnection::getInstance();
     /** @var \PDOStatement $statement */
     $statement = $dbh->prepare('SELECT * FROM mdl_question WHERE category = :cat AND qtype != "random" ORDER BY RAND() LIMIT 1');
     $statement->bindParam(':quizid', $category);
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     $statement->execute();
     $question = $statement->fetch();
     return Examen::instanceQuestion($question);
 }
 public function setAnswers($id)
 {
     $dbh = MySqlConnection::getInstance();
     $query = "SELECT * FROM mdl_question_answers WHERE question = :id";
     $statement = $dbh->prepare($query);
     $statement->bindParam(':id', $id);
     $statement->execute();
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     $answers = $statement->fetchAll();
     foreach ($answers as $answer) {
         $this->answers[] = static::processAnswer($answer);
     }
 }
 private static function getQuestion($id)
 {
     /** @var MySqlConnection $dbh */
     $dbh = MySqlConnection::getInstance();
     /** @var \PDOStatement $statement */
     $statement = $dbh->prepare('SELECT * FROM mdl_question WHERE id = :id');
     $statement->bindParam(':id', $id);
     $statement->execute();
     $_question = $statement->fetch();
     if (is_array($_question)) {
         return Examen::instanceQuestion($_question);
     }
     return null;
 }
Exemplo n.º 4
0
 private function getQuestions()
 {
     /** @var MySqlConnection $dbh */
     $dbh = MySqlConnection::getInstance();
     /** @var \PDOStatement $statement */
     $statement = $dbh->prepare('SELECT questionid FROM ingles.mdl_quiz_slots WHERE quizid = :quizid');
     $statement->bindParam(':quizid', $this->examen['id']);
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     $statement->execute();
     $_questions = $statement->fetchAll();
     foreach ($_questions as $_question) {
         $statement = $dbh->prepare('SELECT * FROM mdl_question WHERE id = :id');
         $statement->bindParam(':id', $_question['questionid']);
         $statement->execute();
         $_question = $statement->fetch();
         if (is_array($_question)) {
             $_question = static::instanceQuestion($_question);
             if ($_question instanceof QuestionInterface) {
                 $this->questions[] = $_question;
             }
         }
     }
 }