Skip to content

Commit

Permalink
MDL-20636 listpreupgrade done.
Browse files Browse the repository at this point in the history
  • Loading branch information
timhunt committed May 11, 2011
1 parent 22cd62c commit 5ab62d9
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 19 deletions.
5 changes: 4 additions & 1 deletion local/qeupgradehelper/lang/en/local_qeupgradehelper.php
Expand Up @@ -43,6 +43,7 @@
$string['invalidquizid'] = 'Invaid quiz id. Either the quiz does not exist, or it has no attempts to convert.';
$string['listpreupgrade'] = 'List quizzes and attempts';
$string['listpreupgrade_desc'] = 'This will show a report of all the quizzes on the system and how many attempts they have. This will give you an idea of the scope of the upgrade you have to do.';
$string['listpreupgradeintro'] = 'These are the number of quiz attempts that will need to be processed when you upgrade your site. A few tens of thousands is no worry. Much beyond that and you need to think carefully.';
$string['listtodo'] = 'List quizzes still to upgrade';
$string['listtodo_desc'] = 'This will show a report of all the quizzes on the system (if any) that have attempts that still need to be upgraded to the new question engine.';
$string['listtodointro'] = 'These are all the quizzes with attempt data that still needs to be converted. You can convert the attempts by clicking the link.';
Expand All @@ -51,12 +52,14 @@
$string['noquizattempts'] = 'Your site does not have any quiz attempts at all!';
$string['nothingupgradedyet'] = 'No upgraded attempts that can be reset';
$string['notupgradedsiterequired'] = 'This script can only work before the site has been upgraded.';
$string['numberofattempts'] = 'Number of quiz attempts';
$string['oldsitedetected'] = 'This appears to be a site that has not yet been upgraded to include the new question engine.';
$string['pluginname'] = 'Question engine upgrade helper';
$string['quizid'] = 'Quiz id';
$string['quizupgrade'] = 'Quiz upgrade status';
$string['quizzeswithunconverted'] = 'The following quizzes have attempts that need to be converted';
$string['quizzesthatcanbereset'] = 'The following quizzes have converted attempts that you may be able to reset';
$string['quizzestobeupgraded'] = 'All quizzes with attempts';
$string['quizzeswithunconverted'] = 'The following quizzes have attempts that need to be converted';
$string['resetquiz'] = 'Reset attempts...';
$string['resetcomplete'] = 'Reset complete';
$string['resettingquizattempts'] = 'Resetting quiz attempts';
Expand Down
6 changes: 4 additions & 2 deletions local/qeupgradehelper/listpreupgrade.php
Expand Up @@ -34,16 +34,18 @@
local_qeupgradehelper_require_not_upgraded();

admin_externalpage_setup('qeupgradehelper', '', array(),
local_qeupgradehelper_url('listpreupgrade'));
local_qeupgradehelper_url(''));
$PAGE->navbar->add(get_string('listpreupgrade', 'local_qeupgradehelper'));

$renderer = $PAGE->get_renderer('local_qeupgradehelper');

$quizzes = local_qeupgradehelper_get_upgradable_quizzes();
$quizzes = local_qeupgradehelper_get_pre_upgrade_quizzes();

if (empty($quizzes)) {
echo $renderer->simple_message_page(get_string('noquizattempts', 'local_qeupgradehelper'));

} else {
// TODO, once we have a way to limit which quizzes will be included in the upgrade,
// display that information too.
echo $renderer->list_quizzes_pre_upgrade($quizzes);
}
41 changes: 30 additions & 11 deletions local/qeupgradehelper/locallib.php
Expand Up @@ -52,7 +52,7 @@ function local_qeupgradehelper_require_upgraded() {
* If the site has been upgraded, display an error.
*/
function local_qeupgradehelper_require_not_upgraded() {
if (!local_qeupgradehelper_is_upgraded()) {
if (local_qeupgradehelper_is_upgraded()) {
throw new moodle_exception('notupgradedsiterequired', 'local_qeupgradehelper',
local_qeupgradehelper_url('index'));
}
Expand Down Expand Up @@ -199,8 +199,8 @@ function local_qeupgradehelper_get_resettable_quizzes() {
* totalattempts and resettableattempts.
*/
function local_qeupgradehelper_get_resettable_quiz($quizid) {
global $CFG;
return get_record_sql("
global $DB;
return $DB->get_record_sql("
SELECT
quiz.id,
quiz.name,
Expand All @@ -212,25 +212,44 @@ function local_qeupgradehelper_get_resettable_quiz($quizid) {
SUM(CASE WHEN quiza.needsupgradetonewqe = 0 AND
oldtimemodified.time >= newtimemodified.time THEN 1 ELSE 0 END) AS resettableattempts
FROM {$CFG->prefix}quiz_attempts quiza
JOIN {$CFG->prefix}quiz quiz ON quiz.id = quiza.quiz
JOIN {$CFG->prefix}course c ON c.id = quiz.course
FROM {quiz_attempts} quiza
JOIN {quiz} quiz ON quiz.id = quiza.quiz
JOIN {course} c ON c.id = quiz.course
LEFT JOIN (
SELECT attempt, MAX(timestamp) AS time
FROM {$CFG->prefix}question_states
FROM {question_states}
GROUP BY attempt
) AS oldtimemodified ON oldtimemodified.attempt = quiza.uniqueid
LEFT JOIN (
SELECT qa.questionusageid, MAX(qas.timecreated) AS time
FROM {$CFG->prefix}question_attempts qa
JOIN {$CFG->prefix}question_attempt_steps qas ON qas.questionattemptid = qa.id
FROM {question_attempts} qa
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
GROUP BY qa.questionusageid
) AS newtimemodified ON newtimemodified.questionusageid = quiza.uniqueid
WHERE quiza.preview = 0
AND quiz.id = {$quizid}
AND quiz.id = ?
GROUP BY quiz.id, quiz.name, c.shortname, c.id");
GROUP BY quiz.id, quiz.name, c.shortname, c.id", array($quizid));
}

function local_qeupgradehelper_get_pre_upgrade_quizzes() {
global $DB;
return $DB->get_records_sql("
SELECT
quiz.id,
quiz.name,
c.shortname,
c.id AS courseid,
COUNT(1) AS attemptcount
FROM {quiz_attempts} quiza
JOIN {quiz} quiz ON quiz.id = quiza.quiz
JOIN {course} c ON c.id = quiz.course
WHERE quiza.preview = 0
GROUP BY quiz.id, quiz.name, c.shortname, c.id
ORDER BY c.shortname, quiz.name, quiz.id");
}

34 changes: 29 additions & 5 deletions local/qeupgradehelper/renderer.php
Expand Up @@ -78,27 +78,32 @@ public function simple_message_page($message) {
* @param unknown_type $actionscript
* @return string
*/
public function quizzes_table($quizzes, $countheader, $actionscript) {
public function quizzes_table($quizzes, $countheader, $actionscript = null) {
$table = new html_table();
$table->head = array(
get_string('quizid', 'local_qeupgradehelper'),
get_string('course'),
get_string('pluginname', 'quiz'),
$countheader,
get_string('actions', 'local_qeupgradehelper'),
);
if ($actionscript) {
$table->head[] = get_string('actions', 'local_qeupgradehelper');
}

foreach ($quizzes as $quiz) {
$table->data[] = array(
$row = array(
$quiz->id,
html_writer::link(new moodle_url('/course/view.php',
array('id' => $quiz->courseid)), format_string($quiz->shortname)),
html_writer::link(new moodle_url('/mod/quiz/view.php',
array('id' => $quiz->name)), format_string($quiz->name)),
$quiz->attemptcount,
html_writer::link(local_qeupgradehelper_url($actionscript, array('quizid' => $quiz->id)),
get_string($actionscript, 'local_qeupgradehelper')),
);
if ($actionscript) {
$row[] = html_writer::link(local_qeupgradehelper_url($actionscript, array('quizid' => $quiz->id)),
get_string($actionscript, 'local_qeupgradehelper'));
}
$table->data[] = $row;
}

return html_writer::table($table);
Expand Down Expand Up @@ -142,6 +147,25 @@ public function list_quizzes_upgraded($quizzes) {
return $output;
}

/**
* Render the list of quizzes that will need to be processed during the upgrade.
* @param array $quizzes of data about quizzes.
* @return string html to output.
*/
public function list_quizzes_pre_upgrade($quizzes) {
$output = '';
$output .= $this->header();
$output .= $this->heading(get_string('quizzestobeupgraded', 'local_qeupgradehelper'));
$output .= $this->box(get_string('listpreupgradeintro', 'local_qeupgradehelper'));

$output .= $this->quizzes_table($quizzes,
get_string('numberofattempts', 'local_qeupgradehelper'));

$output .= $this->back_to_index();
$output .= $this->footer();
return $output;
}

/**
* Render the are-you-sure page to confirm a manual upgrade.
* @param object $quizsummary data about the quiz to upgrade.
Expand Down

0 comments on commit 5ab62d9

Please sign in to comment.