Merging fixes from MOODLE_15_STABLE
This commit is contained in:
@@ -234,7 +234,7 @@
|
||||
|
||||
$select = 'SELECT '.$db->Concat('u.id', '\'#\'', $db->IfNull('qa.attempt', '0')).' AS uniqueid, qa.id AS attempt, u.id AS userid, u.firstname, u.lastname, u.picture, '.
|
||||
'qa.sumgrades, qa.timefinish, qa.timestart, qa.timefinish - qa.timestart AS duration ';
|
||||
$from = 'FROM mdl_user u LEFT JOIN mdl_quiz_attempts qa ON (u.id = qa.userid AND qa.quiz = '.$quiz->id.') ';
|
||||
$from = 'FROM '.$CFG->prefix.'user u LEFT JOIN '.$CFG->prefix.'quiz_attempts qa ON (u.id = qa.userid AND qa.quiz = '.$quiz->id.') ';
|
||||
$where = 'WHERE u.id IN ('.implode(',', array_keys($users)).') ';
|
||||
|
||||
// Add extra limits if we 're not interested in students without attempts
|
||||
@@ -261,8 +261,8 @@
|
||||
if(!$questionsort) {
|
||||
$qid = intval(substr($sortpart, 1));
|
||||
$select .= ', grade ';
|
||||
$from .= 'LEFT JOIN mdl_quiz_newest_states qns ON qns.attemptid = qa.id '.
|
||||
'LEFT JOIN mdl_quiz_states qs ON qs.id = qns.newgraded ';
|
||||
$from .= 'LEFT JOIN '.$CFG->prefix.'quiz_newest_states qns ON qns.attemptid = qa.id '.
|
||||
'LEFT JOIN '.$CFG->prefix.'quiz_states qs ON qs.id = qns.newgraded ';
|
||||
$where .= ' AND ('.sql_isnull('qns.questionid').' OR qns.questionid = '.$qid.')';
|
||||
$newsort[] = 'grade '.(strpos($sortpart, 'ASC')? 'ASC' : 'DESC');
|
||||
$questionsort = true;
|
||||
|
||||
+27
-5
@@ -141,7 +141,7 @@
|
||||
|
||||
if ($form = data_submitted() and confirm_sesskey()) {
|
||||
|
||||
if (isset($form->versioning) && isset($question->id)) {
|
||||
if (isset($form->versioning) && isset($question->id) and false) { // disable versioning until it is fixed.
|
||||
// use new code that handles whether to overwrite or copy a question
|
||||
// and keeps track of the versions in the quiz_question_version table
|
||||
|
||||
@@ -222,7 +222,7 @@
|
||||
if (!set_field("quiz", 'questions', $questionlist, 'id', $quiz->id)) {
|
||||
error("Could not update questionlist in quiz $quiz->id!");
|
||||
}
|
||||
|
||||
|
||||
// the quiz_question_instances table needs to be updated too (aah, the joys of duplication :)
|
||||
if (!set_field('quiz_question_instances', 'question', $question->id, 'quiz', $quiz->id, 'question', $oldquestionid)) {
|
||||
error("Could not update question instance!");
|
||||
@@ -233,12 +233,34 @@
|
||||
unset($SESSION->modform->grades[$oldquestionid]);
|
||||
}
|
||||
}
|
||||
|
||||
// set originalquestion in states
|
||||
|
||||
// change question in attempts
|
||||
if ($attempts = get_records_list('quiz_attempts', 'quiz', implode(',', $replaceinquiz))) {
|
||||
foreach ($attempts as $attempt) {
|
||||
set_field('quiz_states', 'originalquestion', $oldquestionid, 'attempt', $attempt->id, 'question', $question->id, 'originalquestion', '0');
|
||||
|
||||
// replace question id in $attempt->layout
|
||||
$questionlist = ",$attempt->layout,"; // a little hack with the commas here. not nice but effective
|
||||
$questionlist = str_replace(",$oldquestionid,", ",$question->id,", $questionlist);
|
||||
$questionlist = substr($questionlist, 1, -1); // and get rid of the surrounding commas again
|
||||
if (!set_field('quiz_attempts', 'layout', $questionlist, 'id', $attempt->id)) {
|
||||
error("Could not update layout in attempt $attempt->id!");
|
||||
}
|
||||
|
||||
// set originalquestion in states
|
||||
set_field('quiz_states', 'originalquestion', $oldquestionid, 'attempt', $attempt->id, 'question', $question->id, 'originalquestion', '0');
|
||||
|
||||
// replace question id in states
|
||||
set_field('quiz_states', 'question', $question->id, 'attempt', $attempt->id, 'question', $oldquestionid);
|
||||
|
||||
// replace question id in newest_states
|
||||
set_field('quiz_newest_states', 'questionid', $question->id, 'attemptid', $attempt->id, 'questionid', $oldquestionid);
|
||||
|
||||
}
|
||||
|
||||
// Now do anything question-type specific that is required to replace the question
|
||||
// For example questions that use the quiz_answers table to hold part of their question will
|
||||
// have to recode the answer ids in the states
|
||||
$QUIZ_QTYPES[$question->qtype]->change_states_question($oldquestionid, $question, $attempts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
-13
@@ -103,22 +103,15 @@
|
||||
|
||||
// load the questions needed by page
|
||||
$pagelist = $showall ? quiz_questions_in_quiz($attempt->layout) : quiz_questions_on_page($attempt->layout, $page);
|
||||
if (!$questions = get_records_list('quiz_questions', 'id', $pagelist)) {
|
||||
$sql = "SELECT q.*, i.grade AS maxgrade, i.id AS instance".
|
||||
" FROM {$CFG->prefix}quiz_questions q,".
|
||||
" {$CFG->prefix}quiz_question_instances i".
|
||||
" WHERE i.quiz = '$quiz->id' AND q.id = i.question".
|
||||
" AND q.id IN ($pagelist)";
|
||||
if (!$questions = get_records_sql($sql)) {
|
||||
error('No questions found');
|
||||
}
|
||||
|
||||
// Get instance information for versioned and unversioned questions (fixes bug 3311)
|
||||
foreach ($questions as $question) {
|
||||
$qid = $question->id;
|
||||
while (!$instance = get_record('quiz_question_instances', 'quiz', $quiz->id, 'question', $qid)) {
|
||||
if (!$qid = get_field('quiz_question_versions', 'newquestion', 'oldquestion', $qid)) {
|
||||
error("No instance of question #$question->id could be found!");
|
||||
}
|
||||
}
|
||||
$question->maxgrade = $instance->grade;
|
||||
$question->instance = $instance->id;
|
||||
}
|
||||
|
||||
// Load the question type specific information
|
||||
if (!quiz_get_question_options($questions)) {
|
||||
error('Could not load question options');
|
||||
|
||||
Reference in New Issue
Block a user