Exemplo n.º 1
0
/**
 * This function does the cron process within the time range according to settings.
 */
function tool_qeupgradehelper_process($settings)
{
    global $CFG;
    require_once dirname(__FILE__) . '/locallib.php';
    if (!tool_qeupgradehelper_is_upgraded()) {
        mtrace('qeupgradehelper: site not yet upgraded. Doing nothing.');
        return;
    }
    require_once dirname(__FILE__) . '/afterupgradelib.php';
    $hour = (int) date('H');
    if ($hour < $settings->starthour || $hour >= $settings->stophour) {
        mtrace('qeupgradehelper: not between starthour and stophour, so doing nothing (hour = ' . $hour . ').');
        return;
    }
    $stoptime = time() + $settings->procesingtime;
    mtrace('qeupgradehelper: processing ...');
    while (time() < $stoptime) {
        $quiz = tool_qeupgradehelper_get_quiz_for_upgrade();
        if (!$quiz) {
            mtrace('qeupgradehelper: No more quizzes to process. You should probably disable the qeupgradehelper cron settings now.');
            break;
            // No more to do;
        }
        $quizid = $quiz->id;
        $quizsummary = tool_qeupgradehelper_get_quiz($quizid);
        if ($quizsummary) {
            mtrace('  starting upgrade of attempts at quiz ' . $quizid);
            $upgrader = new tool_qeupgradehelper_attempt_upgrader($quizsummary->id, $quizsummary->numtoconvert);
            $upgrader->convert_all_quiz_attempts();
            mtrace('  upgrade of quiz ' . $quizid . ' complete.');
        }
    }
    mtrace('qeupgradehelper: Done.');
    return;
}
Exemplo n.º 2
0
 * from Moodle 2.0 to 2.1.
 *
 * This screen is the main entry-point to the plugin, it gives the admin a list
 * of options available to them.
 *
 * @package    tool
 * @subpackage qeupgradehelper
 * @copyright  2010 The Open University
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
 */
require_once dirname(__FILE__) . '/../../../config.php';
require_once dirname(__FILE__) . '/locallib.php';
require_once $CFG->libdir . '/adminlib.php';
require_login();
require_capability('moodle/site:config', context_system::instance());
admin_externalpage_setup('qeupgradehelper');
$renderer = $PAGE->get_renderer('tool_qeupgradehelper');
$actions = array();
if (tool_qeupgradehelper_is_upgraded()) {
    $detected = get_string('upgradedsitedetected', 'tool_qeupgradehelper');
    $actions[] = tool_qeupgradehelper_action::make('listtodo');
    $actions[] = tool_qeupgradehelper_action::make('listupgraded');
    $actions[] = tool_qeupgradehelper_action::make('extracttestcase');
    $actions[] = tool_qeupgradehelper_action::make('cronsetup');
} else {
    $detected = get_string('oldsitedetected', 'tool_qeupgradehelper');
    $actions[] = tool_qeupgradehelper_action::make('listpreupgrade');
    $actions[] = tool_qeupgradehelper_action::make('extracttestcase');
    $actions[] = tool_qeupgradehelper_action::make('cronsetup');
}
echo $renderer->index_page($detected, $actions);
Exemplo n.º 3
0
function tool_qeupgradehelper_load_question($questionid, $quizid)
{
    global $CFG, $DB;
    $question = $DB->get_record_sql('
            SELECT q.*, qqi.grade AS maxmark
            FROM {question} q
            JOIN {quiz_question_instances} qqi ON qqi.question = q.id
            WHERE q.id = :questionid AND qqi.quiz = :quizid', array('questionid' => $questionid, 'quizid' => $quizid));
    if (tool_qeupgradehelper_is_upgraded()) {
        require_once $CFG->dirroot . '/question/engine/bank.php';
        $qtype = question_bank::get_qtype($question->qtype, false);
    } else {
        global $QTYPES;
        if (!array_key_exists($question->qtype, $QTYPES)) {
            $question->qtype = 'missingtype';
            $question->questiontext = '<p>' . get_string('warningmissingtype', 'quiz') . '</p>' . $question->questiontext;
        }
        $qtype = $QTYPES[$question->qtype];
    }
    $qtype->get_question_options($question);
    return $question;
}