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;
 }
Example #4
0
 public static function getExamIndex($course_module_id)
 {
     $info = ConnectionInfo::create();
     /** @var MySqlConnection $dbh */
     $dbh = MySqlConnection::create($info);
     /** @var \PDOStatement $statement */
     $statement = $dbh->prepare('SELECT quiz.id FROM mdl_course_modules AS cmi JOIN mdl_quiz AS quiz ON quiz.id = cmi.instance WHERE cmi.id = :id');
     $statement->bindParam(':id', $course_module_id);
     $statement->setFetchMode(PDO::FETCH_ASSOC);
     $statement->execute();
     $result = $statement->fetchAll();
     $result = reset($result);
     return $result['id'];
 }
Example #5
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;
             }
         }
     }
 }
Example #6
0
<?php

use Crayon\Database\ConnectionInfo;
use Crayon\Database\MySqlConnection;
use Crayon\Model\Examen;
include 'vendor/autoload.php';
include 'src/autoloader.php';
$connection_info = ConnectionInfo::create();
/** @var MySqlConnection $db */
$db = MySqlConnection::create($connection_info);
// Obtenemos los exámenes
$query = 'SELECT * FROM mdl_quiz';
$stmnt = $db->prepare($query);
$stmnt->setFetchMode(PDO::FETCH_ASSOC);
$stmnt->execute();
$examenes = $stmnt->fetchAll();
foreach ($examenes as $examen) {
    $examenid = $examen;
    /** @var Examen $_examen */
    $examen = Examen::create($examen);
    $_examen = $examen->json_dump();
    $template = file_get_contents(__DIR__ . '/assets/html/Template.html');
    $_examen = strtr($template, array('@json_data' => $_examen));
    file_put_contents(__DIR__ . '/output/quiz' . $examen->examen['id'] . '.html', $_examen);
}
//// Inicializamos el cliente
//$scapper = new Goutte\Client();
//// Recordar settear COOKIE de autentificación.
//$scapper->setHeader('Cookie', COOKIE);
//$sections = array(3,4,5,6,7,8,9,10,11,12,14,15,16,17,18,19,20,21,22,23,25,26,27,28,29,30,31,32,33,34,36,37,38,39,40,41,42,43,44,45);
//foreach ($sections as $s) {