Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
gustav_delius committed May 10, 2005
1 parent 30e99c8 commit c4aff65
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 38 deletions.
12 changes: 9 additions & 3 deletions mod/quiz/editlib.php
Expand Up @@ -486,6 +486,14 @@ function quiz_print_cat_question_list($course, $categoryid, $quizselected=true,


// hide-feature // hide-feature
$showhidden = $showhidden ? '' : " AND hidden = '0'"; $showhidden = $showhidden ? '' : " AND hidden = '0'";

if (!$totalnumber = count_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden")) {
echo "<p align=\"center\">";
print_string("noquestions", "quiz");
echo "</p>";
return;
}

if (!$questions = get_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden", 'qtype, name ASC', '*', $page*$perpage, $perpage)) { if (!$questions = get_records_select('quiz_questions', "category IN ($categorylist) AND parent = '0' $showhidden", 'qtype, name ASC', '*', $page*$perpage, $perpage)) {
echo "<p align=\"center\">"; echo "<p align=\"center\">";
print_string("noquestions", "quiz"); print_string("noquestions", "quiz");
Expand Down Expand Up @@ -557,9 +565,7 @@ function quiz_print_cat_question_list($course, $categoryid, $quizselected=true,
quiz_category_select_menu($course->id, false, true, $category->id); quiz_category_select_menu($course->id, false, true, $category->id);
echo "</td></tr></table>"; echo "</td></tr></table>";


$numquestions = count($questions); print_paging_bar($totalnumber, $page, $perpage,

print_paging_bar($numquestions, $page, $perpage,
"edit.php?perpage=$perpage&amp;"); "edit.php?perpage=$perpage&amp;");


if ($quizselected) { if ($quizselected) {
Expand Down
6 changes: 5 additions & 1 deletion mod/quiz/locallib.php
Expand Up @@ -1420,8 +1420,12 @@ function quiz_extract_responses($questions, $responses, $defaultevent) {
*/ */
function quiz_regrade_question_in_quizzes($question, $quizlist) { function quiz_regrade_question_in_quizzes($question, $quizlist) {


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

$quizlist = implode(',', $quizlist); $quizlist = implode(',', $quizlist);
if (empty($quizlist)) { // assume that all quizzes are affected if ($quizlist == 'all') { // assume that all quizzes are affected
if (! $instances = get_records('quiz_question_instances', if (! $instances = get_records('quiz_question_instances',
'question', $question->id)) { 'question', $question->id)) {
// No instances were found, so it successfully regraded all of them // No instances were found, so it successfully regraded all of them
Expand Down
68 changes: 34 additions & 34 deletions mod/quiz/question.php
Expand Up @@ -207,48 +207,48 @@
} }


/// now update the question references in the quizzes /// now update the question references in the quizzes
if (empty($replaceinquiz) || !$quizzes = get_records_list("quiz", "id", implode(',', $replaceinquiz))) { if (!empty($replaceinquiz) and $quizzes = get_records_list("quiz", "id", implode(',', $replaceinquiz))) {
$quizzes = array();
} foreach($quizzes as $quiz) {

$questionlist = ",$quiz->questions,"; // a little hack with the commas here. not nice but effective
foreach($quizzes as $quiz) { $questionlist = str_replace(",$oldquestionid,", ",$question->id,", $questionlist);
$questionlist = ",$quiz->questions,"; // a little hack with the commas here. not nice but effective $questionlist = substr($questionlist, 1, -1); // and get rid of the surrounding commas again
$questionlist = str_replace(",$oldquestionid,", ",$question->id,", $questionlist); if (!set_field("quiz", 'questions', $questionlist, 'id', $quiz->id)) {
$questionlist = substr($questionlist, 1, -1); // and get rid of the surrounding commas again error("Could not update questionlist in quiz $quiz->id!");
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)) {
// the quiz_question_instances table needs to be updated too (aah, the joys of duplication :) error("Could not update question instance!");
if (!set_field('quiz_question_instances', 'question', $question->id, 'quiz', $quiz->id, 'question', $oldquestionid)) { }
error("Could not update question instance!"); if (isset($SESSION->modform) && (int)$SESSION->modform->instance === (int)$quiz->id) {
} $SESSION->modform->questions = $questionlist;
if (isset($SESSION->modform) && (int)$SESSION->modform->instance === (int)$quiz->id) { $SESSION->modform->grades[$question->id] = $SESSION->modform->grades[$oldquestionid];
$SESSION->modform->questions = $questionlist; unset($SESSION->modform->grades[$oldquestionid]);
$SESSION->modform->grades[$question->id] = $SESSION->modform->grades[$oldquestionid]; }
unset($SESSION->modform->grades[$oldquestionid]); }
}
} // set originalquestion in states

if ($attempts = get_records_list('quiz_attempts', 'quiz', implode(',', $replaceinquiz))) {
// set originalquestion in states foreach ($attempts as $attempt) {
if ($attempts = get_records_list('quiz_attempts', 'quiz', implode(',', $replaceinquiz))) { set_field('quiz_states', 'originalquestion', $oldquestionid, 'attempt', $attempt->id, 'question', $question->id, 'originalquestion', '0');
foreach ($attempts as $attempt) { }
set_field('quiz_states', 'originalquestion', $oldquestionid, 'attempt', $attempt->id, 'question', $question->id, 'originalquestion', '0'); }
} }
}
} }
} else { } else {
// use the old code which simply overwrites old versions // use the old code which simply overwrites old versions
// it is also used for creating new questions // it is also used for creating new questions
$question = $QUIZ_QTYPES[$qtype]->save_question($question, $form, $course); $question = $QUIZ_QTYPES[$qtype]->save_question($question, $form, $course);
$quizlist = array(); $replaceinquiz = 'all';
} }


if (empty($question->errors) && if (empty($question->errors) && $QUIZ_QTYPES[$qtype]->finished_edit_wizard($form)) {
$QUIZ_QTYPES[$qtype]->finished_edit_wizard($form)) {
$QUIZ_QTYPES[$question->qtype]->get_question_options($question);
// Automagically regrade all attempts (and states) in the affected quizzes // Automagically regrade all attempts (and states) in the affected quizzes
quiz_regrade_question_in_quizzes($question, $quizlist); if (!empty($replaceinquiz)) {
$QUIZ_QTYPES[$question->qtype]->get_question_options($question);
quiz_regrade_question_in_quizzes($question, $replaceinquiz);
}
redirect("edit.php"); redirect("edit.php");
} }
} }
Expand Down

0 comments on commit c4aff65

Please sign in to comment.