Skip to content

Commit

Permalink
MDL-20636 Initial pass at converting this code to Moodle 2.0 style.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed May 11, 2011
1 parent cca6d63 commit cd300cf
Show file tree
Hide file tree
Showing 9 changed files with 175 additions and 178 deletions.
52 changes: 25 additions & 27 deletions local/qedatabase/db/upgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function xmldb_local_qedatabase_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2008000704, 'local', 'qedatabase');
}

if ($oldversion < 2008000800) {
if ($oldversion < 2008000799) {
// Define field needsupgradetonewqe to be added to quiz_attempts
$table = new xmldb_table('quiz_attempts');
$field = new xmldb_field('needsupgradetonewqe', XMLDB_TYPE_INTEGER, '3', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'preview');
Expand All @@ -83,30 +83,28 @@ function xmldb_local_qedatabase_upgrade($oldversion) {
upgrade_plugin_savepoint(true, 2008000800, 'local', 'qedatabase');
}

// if ($oldversion < 2008000551) {
// $table = new xmldb_table('question_states');
// if ($dbman->table_exists($table)) {
// // First delete all data from preview attempts.
// delete_records_select('question_states',
// "attempt IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
// delete_records_select('question_sessions',
// "attemptid IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
// delete_records('quiz_attempts', 'preview', 1);
//
// // Now update all the old attempt data.
// $db->debug = false;
// $oldrcachesetting = $CFG->rcache;
// $CFG->rcache = false;
//
// require_once($CFG->dirroot . '/question/engine/upgradefromoldqe/upgrade.php');
// $upgrader = new question_engine_attempt_upgrader();
// $upgrader->convert_all_quiz_attempts();
//
// $CFG->rcache = $oldrcachesetting;
// $db->debug = true;
// }
//
// // quiz savepoint reached
// upgrade_plugin_savepoint(true, 2008000551, 'local', 'qedatabase');
// }
if ($oldversion < 2008000800) {
$table = new xmldb_table('question_states');
if ($dbman->table_exists($table)) {
// First delete all data from preview attempts.
delete_records_select('question_states',
"attempt IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
delete_records_select('question_sessions',
"attemptid IN (SELECT uniqueid FROM {quiz_attempts} WHERE preview = 1)");
delete_records('quiz_attempts', 'preview', 1);

// Now update all the old attempt data.
$oldrcachesetting = $CFG->rcache;
$CFG->rcache = false;

require_once($CFG->dirroot . '/question/engine/upgradefromoldqe/upgrade.php');
$upgrader = new question_engine_attempt_upgrader();
$upgrader->convert_all_quiz_attempts();

$CFG->rcache = $oldrcachesetting;
}

// quiz savepoint reached
upgrade_plugin_savepoint(true, 2008000800, 'local', 'qedatabase');
}
}
8 changes: 2 additions & 6 deletions local/qeupgradehelper/pretendupgrade.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,17 @@ protected function get_quiz_ids() {
"id >= {$this->fromquiz} AND id < {$this->toquiz}", 'id', 'id,1');
}

public function get_attemtps_where($quizid) {
return "quiz = {$quizid} AND preview = 0";
public function get_attempts_where($quizid) {
return '';
}

protected function set_quba_preferred_behaviour($qubaid, $preferredbehaviour) {
return true;
}

protected function set_quiz_attempt_layout($qubaid, $layout) {
return true;
}

protected function delete_quiz_attempt($qubaid) {
return true;
}

protected function insert_record($table, $record, $saveid = true) {
Expand All @@ -76,7 +73,6 @@ protected function insert_record($table, $record, $saveid = true) {
if ($saveid) {
$record->id = 666;
}
return true;
}

protected function convert_quiz_attempt($quiz, $attempt, $questionsessionsrs, $questionsstatesrs) {
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/accessrules.php
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public function time_left($attempt, $timenow) {
}

/**
* A rule imposing the delay between attemtps settings.
* A rule imposing the delay between attempts settings.
*
* @copyright 2009 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Expand Down
2 changes: 1 addition & 1 deletion mod/quiz/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1379,7 +1379,7 @@ function quiz_print_overview($courses, &$htmlarray) {

/**
* Return a textual summary of the number of attempts that have been made at a particular quiz,
* returns '' if no attemtps have been made yet, unless $returnzero is passed as true.
* returns '' if no attempts have been made yet, unless $returnzero is passed as true.
*
* @param object $quiz the quiz object. Only $quiz->id is used at the moment.
* @param object $cm the cm object. Only $cm->course, $cm->groupmode and $cm->groupingid fields are used at the moment.
Expand Down
4 changes: 2 additions & 2 deletions mod/quiz/report/attemptsreport.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ protected function load_relevant_students($cm) {

/**
* Alters $attemptsmode and $pagesize if the current values are inappropriate.
* @param int $attemptsmode what sort of attemtps to display (may be updated)
* @param int $attemptsmode what sort of attempts to display (may be updated)
* @param int $pagesize number of records to display per page (may be updated)
* @param object $course the course settings.
* @param int $currentgroup the currently selected group. 0 for none.
Expand Down Expand Up @@ -138,7 +138,7 @@ protected function validate_common_options(&$attemptsmode, &$pagesize, $course,
* @param object $quiz the quiz settings.
* @param string $qmsubselect SQL fragment from {@link quiz_report_qm_filter_select()}.
* @param bool $qmfilter whether to show all, or only the final grade attempt.
* @param int $attemptsmode which attemtps to show. One of the QUIZ_REPORT_ATTEMPTS_... constants.
* @param int $attemptsmode which attempts to show. One of the QUIZ_REPORT_ATTEMPTS_... constants.
* @param array $reportstudents list if userids of users to include in the report.
* @return array with 4 elements ($fields, $from, $where, $params) that can be used to
* build the actual database query.
Expand Down
35 changes: 32 additions & 3 deletions question/engine/upgrade/behaviourconverters.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,50 @@
defined('MOODLE_INTERNAL') || die();


/**
* Base class for managing the upgrade of a question using a particular behaviour.
*
* This class takes as input:
* 1. Various backgroud data like $quiz, $attempt and $question.
* 2. The data about the question session to upgrade $qsession and $qstates.
* Working through that data, it builds up
* 3. The equivalent new data $qa. This has roughly the same data as a
* question_attempt object belonging to the new question engine would have, but
* $this->qa is built up from stdClass objects.
*
* @copyright 2010 The Open University
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
abstract class question_behaviour_attempt_updater {
/** @var question_qtype_attempt_updater */
protected $qtypeupdater;
/** @var question_engine_assumption_logger */
protected $logger;

/**
* @var object this is the data for the upgraded questions attempt that
* we are building.
*/
protected $qa;

/** @var object the quiz settings. */
protected $quiz;
/** @var object the quiz attempt data. */
protected $attempt;
/** @var object the question definition data. */
protected $question;
/** @var object the question session to be upgraded. */
protected $qsession;
/** @var array the question states for the session to be upgraded. */
protected $qstates;

/**
* @var int counts the question_steps as they are converted to
* question_attempt_steps.
*/
protected $sequencenumber;
/** @var object pointer to the state that has already finished this attempt. */
protected $finishstate;
protected $alreadystarted;

public function __construct($quiz, $attempt, $question, $qsession, $qstates, $logger) {
$this->quiz = $quiz;
Expand Down Expand Up @@ -390,7 +419,8 @@ protected function process8($step, $state) {
}


class qbehaviour_interactive_converter extends question_behaviour_attempt_updater {
// TODO
class qbehaviour_adaptive_converter extends question_behaviour_attempt_updater {
protected $triesleft;

protected function behaviour_name() {
Expand Down Expand Up @@ -506,4 +536,3 @@ protected function process10($step, $state) {
$this->add_step($step);
}
}

10 changes: 4 additions & 6 deletions question/engine/upgrade/logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@

defined('MOODLE_INTERNAL') || die();

global $CFG;
require_once($CFG->libdir . '/questionlib.php');


/**
* This class serves to record all the assumptions that the code had to make
Expand All @@ -45,11 +42,12 @@ class question_engine_assumption_logger {
public function __construct() {
global $CFG;
make_upload_directory('upgradelogs');
$date = date('Ymd-His');
$this->handle = fopen($CFG->dataroot . '/upgradelogs/qe_' .
date('Ymd-Hi') . '.html', 'a');
$date . '.html', 'a');
fwrite($this->handle, '<html><head><title>Question engine upgrade assumptions ' .
date('Ymd-Hi') . '</title></head><body><h2>Question engine upgrade assumptions ' .
date('Ymd-Hi') . "</h2>\n\n");
$date . '</title></head><body><h2>Question engine upgrade assumptions ' .
$date . "</h2>\n\n");
}

public function set_current_attempt_id($id) {
Expand Down
Loading

0 comments on commit cd300cf

Please sign in to comment.