Skip to content

Commit

Permalink
Disabled versioning and re-grading until it is fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
gustav_delius committed May 26, 2005
1 parent fc071f0 commit b942572
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
38 changes: 31 additions & 7 deletions mod/quiz/locallib.php
Expand Up @@ -208,6 +208,25 @@ function save_question_options($question) {
return $result;
}

/**
* Changes all states for a question in a list of attempts over to a new question
*
* This is used by the versioning code if the teacher requests that a question
* gets replaced by the new version. In order for the attempts to be regraded
* properly all data in the states referring to the old question need to be
* changed to refer to the new version instead. In particular for question types
* that use the answers table the answers belonging to the old question have to
* be changed to those belonging to the new version.
*
* @param integer $oldquestionid The id of the old question
* @param object $newquestion The new question
* @param array $attempts An array of all attempt objects in whose states
* replacement should take place
*/
function change_states_question($oldquestionid, $newquestion, $attemtps) {
echo 'Not yet implemented';
return;
}

/**
* Loads the question type specific options for the question.
Expand Down Expand Up @@ -920,6 +939,9 @@ function print_replacement_options($question, $course, $quizid='0') {
// It prints the table of quizzes in which the question is used
// containing checkboxes to allow the teacher to replace the old question version

// Disable until the versioning code has been fixed
return;

// no need to display replacement options if the question is new
if(empty($question->id)) {
return true;
Expand Down Expand Up @@ -1454,23 +1476,25 @@ function quiz_extract_responses($questions, $responses, $defaultevent) {
* @return boolean Indicates success/failure
* @param object $question A question object
* @param array $quizlist An array of quiz ids, in which the question should
* be regraded. If quizlist is the empty array, all
* quizzes are affected.
* be regraded. If quizlist == 'all' all quizzes are affected
*/
function quiz_regrade_question_in_quizzes($question, $quizlist) {

// Disable until tested
return;

if (empty($quizlist)) {
return;
}

if ($quizlist == 'all') { // assume that all quizzes are affected
if (! $instances = get_records('quiz_question_instances',
'question', $question->id)) {
// fetch a list of all the quizzes using this question
if (! $instances = (array)get_records('quiz_question_instances',
'question', $question->id, '', 'id, quiz')) {
// No instances were found, so it successfully regraded all of them
return true;
}
$quizlist = implode(',', array_map(create_function('$val',
'return $val->quiz;'), $instances));
$quizlist = array_map(create_function('$val', 'return $val->quiz;'), $instances);
unset($instances);
}

Expand All @@ -1483,7 +1507,7 @@ function quiz_regrade_question_in_quizzes($question, $quizlist) {
foreach ($quizzes as $quiz) {
// All the attempts that need to be changed
if (! $attempts = get_records('quiz_attempts', 'quiz', $quiz->id)) {
error("Couldn't get question instance for regrading!");
continue;
}
$attempts = array_values($attempts);
if (! $instance = get_record('quiz_question_instances',
Expand Down
32 changes: 27 additions & 5 deletions mod/quiz/question.php
Expand Up @@ -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

Expand Down Expand Up @@ -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!");
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit b942572

Please sign in to comment.