mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
Questions that are in use are now only deleted from the category list but not from quizzes or old attempts.
This commit is contained in:
parent
14ca3084a0
commit
1997f36731
3 changed files with 42 additions and 66 deletions
|
@ -205,7 +205,7 @@ $string['publish'] = 'Publish';
|
||||||
$string['publishedit'] = 'You must have permission in the publishing course to add or edit questions in this category';
|
$string['publishedit'] = 'You must have permission in the publishing course to add or edit questions in this category';
|
||||||
$string['qti'] = 'IMS QTI format';
|
$string['qti'] = 'IMS QTI format';
|
||||||
$string['question'] = 'Question';
|
$string['question'] = 'Question';
|
||||||
$string['questioninuse'] = 'The question \'$a\' is currently being used:';
|
$string['questioninuse'] = 'The question \'$a->questionname\' is currently being used in: <br />$a->quiznames<br />The question will not be deleted from these quizzes but only from the category list.';
|
||||||
$string['questionname'] = 'Question name';
|
$string['questionname'] = 'Question name';
|
||||||
$string['questionnametoolong'] = 'Question name too long at line $a (255 char. max). It has been truncated.';
|
$string['questionnametoolong'] = 'Question name too long at line $a (255 char. max). It has been truncated.';
|
||||||
$string['questions'] = 'Questions';
|
$string['questions'] = 'Questions';
|
||||||
|
@ -268,7 +268,7 @@ $string['shortanswer'] = 'Short Answer';
|
||||||
$string['show'] = 'Show';
|
$string['show'] = 'Show';
|
||||||
$string['showcorrectanswer'] = 'In feedback, show correct answers?';
|
$string['showcorrectanswer'] = 'In feedback, show correct answers?';
|
||||||
$string['showfeedback'] = 'After answering, show feedback?';
|
$string['showfeedback'] = 'After answering, show feedback?';
|
||||||
$string['showhidden'] = 'Also show hidden questions';
|
$string['showhidden'] = 'Also show old questions';
|
||||||
$string['shuffleanswers'] = 'Shuffle answers';
|
$string['shuffleanswers'] = 'Shuffle answers';
|
||||||
$string['shufflequestions'] = 'Shuffle questions';
|
$string['shufflequestions'] = 'Shuffle questions';
|
||||||
$string['significantfiguresformat'] = 'significant figures';
|
$string['significantfiguresformat'] = 'significant figures';
|
||||||
|
|
|
@ -1339,6 +1339,7 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true, $recurse=
|
||||||
$strdelete = get_string("delete");
|
$strdelete = get_string("delete");
|
||||||
$stredit = get_string("edit");
|
$stredit = get_string("edit");
|
||||||
$straction = get_string("action");
|
$straction = get_string("action");
|
||||||
|
$strrestore = get_string('restore');
|
||||||
|
|
||||||
$straddselectedtoquiz = get_string("addselectedtoquiz", "quiz");
|
$straddselectedtoquiz = get_string("addselectedtoquiz", "quiz");
|
||||||
$straddtoquiz = get_string("addtoquiz", "quiz");
|
$straddtoquiz = get_string("addtoquiz", "quiz");
|
||||||
|
@ -1415,7 +1416,7 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true, $recurse=
|
||||||
echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\" width=\"100%\">";
|
echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\" width=\"100%\">";
|
||||||
echo "<tr>";
|
echo "<tr>";
|
||||||
if ($canedit) {
|
if ($canedit) {
|
||||||
echo "<th width=\"105\" nowrap=\"nowrap\">$straction</th>";
|
echo "<th width=\"100\" nowrap=\"nowrap\">$straction</th>";
|
||||||
}
|
}
|
||||||
echo "<th width=\"100%\" align=\"left\" nowrap=\"nowrap\">$strquestionname</th><th width=\"*\" nowrap=\"nowrap\">$strtype</th>";
|
echo "<th width=\"100%\" align=\"left\" nowrap=\"nowrap\">$strquestionname</th><th width=\"*\" nowrap=\"nowrap\">$strtype</th>";
|
||||||
echo "</tr>\n";
|
echo "</tr>\n";
|
||||||
|
@ -1436,25 +1437,22 @@ function quiz_print_cat_question_list($categoryid, $quizselected=true, $recurse=
|
||||||
src=\"../../pix/t/edit.gif\" border=\"0\" alt=\"$stredit\" /></a> ";
|
src=\"../../pix/t/edit.gif\" border=\"0\" alt=\"$stredit\" /></a> ";
|
||||||
// hide-feature
|
// hide-feature
|
||||||
if($question->hidden) {
|
if($question->hidden) {
|
||||||
$strhideshow = get_string("show");
|
echo "<a title=\"$strrestore\" href=\"question.php?id=$question->id&hide=0&sesskey=$USER->sesskey\"><img
|
||||||
$imghideshow = "show.gif";
|
src=\"../../pix/t/restore.gif\" border=\"0\" alt=\"$strrestore\" /></a>";
|
||||||
$hideshow = 0;
|
|
||||||
} else {
|
} else {
|
||||||
$strhideshow = get_string("hide");
|
echo "<a title=\"$strdelete\" href=\"question.php?id=$question->id&delete=$question->id\"><img
|
||||||
$imghideshow = "hide.gif";
|
|
||||||
$hideshow = 1;
|
|
||||||
}
|
|
||||||
echo "<a title=\"$strhideshow\" href=\"question.php?id=$question->id&hide=$hideshow&sesskey=$USER->sesskey\"><img
|
|
||||||
src=\"../../pix/t/$imghideshow\" border=\"0\" alt=\"$strhideshow\" /></a>";
|
|
||||||
echo "<a title=\"$strdelete\" href=\"question.php?id=$question->id&delete=$question->id\">\n<img
|
|
||||||
src=\"../../pix/t/delete.gif\" border=\"0\" alt=\"$strdelete\" /></a>";
|
src=\"../../pix/t/delete.gif\" border=\"0\" alt=\"$strdelete\" /></a>";
|
||||||
|
}
|
||||||
if ($quizselected) {
|
if ($quizselected) {
|
||||||
echo " <input title=\"$strselect\" type=\"checkbox\" name=\"q$question->id\" value=\"1\" />";
|
echo " <input title=\"$strselect\" type=\"checkbox\" name=\"q$question->id\" value=\"1\" />";
|
||||||
}
|
}
|
||||||
echo "</td>\n";
|
echo "</td>\n";
|
||||||
}
|
}
|
||||||
|
if ($question->hidden) {
|
||||||
|
echo '<td class="dimmed_text">'.$question->name."</td>\n";
|
||||||
|
} else {
|
||||||
echo "<td>".$question->name."</td>\n";
|
echo "<td>".$question->name."</td>\n";
|
||||||
|
}
|
||||||
echo "<td align=\"center\">\n";
|
echo "<td align=\"center\">\n";
|
||||||
quiz_print_question_icon($question, $canedit);
|
quiz_print_question_icon($question, $canedit);
|
||||||
echo "</td>\n";
|
echo "</td>\n";
|
||||||
|
@ -1985,30 +1983,18 @@ function quiz_categorylist($categoryid) {
|
||||||
return $categorylist;
|
return $categorylist;
|
||||||
}
|
}
|
||||||
|
|
||||||
// function to determine where question is in use
|
function quizzes_question_used($id) {
|
||||||
function quizzes_question_used( $id, $published=false, $courseid=0 ) {
|
// $id = question id
|
||||||
// $id = question id
|
// returns array of names of quizzes a question appears in
|
||||||
// $published = is category published
|
|
||||||
// $courseid = course id, required only if $published=true
|
$quizlist = array();
|
||||||
// returns array of names of quizzes it appears in
|
if ($grades = get_records('quiz_question_grades', 'question', $id)) {
|
||||||
if ($published) {
|
foreach($grades as $grade) {
|
||||||
$quizzes = get_records("quiz");
|
$quizlist[$grade->quiz] = get_field('quiz', 'name', 'id', $grade->quiz);
|
||||||
}
|
|
||||||
else {
|
|
||||||
$quizzes = get_records("quiz","course",$courseid);
|
|
||||||
}
|
|
||||||
$beingused = array();
|
|
||||||
if ($quizzes) {
|
|
||||||
foreach ($quizzes as $quiz) {
|
|
||||||
$questions = explode(',', $quiz->questions);
|
|
||||||
foreach ($questions as $question) {
|
|
||||||
if ($question==$id) {
|
|
||||||
$beingused[] = $quiz->name;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
return $quizlist;
|
||||||
return $beingused;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function quiz_parse_fieldname($name, $nameprefix='question') {
|
function quiz_parse_fieldname($name, $nameprefix='question') {
|
||||||
|
|
|
@ -93,36 +93,27 @@
|
||||||
if (isset($_REQUEST['delete'])) {
|
if (isset($_REQUEST['delete'])) {
|
||||||
if (isset($confirm) and confirm_sesskey()) {
|
if (isset($confirm) and confirm_sesskey()) {
|
||||||
if ($confirm == md5($delete)) {
|
if ($confirm == md5($delete)) {
|
||||||
|
if (record_exists('quiz_responses', 'question', $question->id) or
|
||||||
|
record_exists('quiz_responses', 'originalquestion', $question->id) or
|
||||||
|
record_exists('quiz_question_grades', 'question', $question->id)) {
|
||||||
|
if (!set_field('quiz_questions', 'hidden', 1, 'id', $delete)) {
|
||||||
|
error('Was not able to hide question');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if (!delete_records("quiz_questions", "id", $question->id)) {
|
if (!delete_records("quiz_questions", "id", $question->id)) {
|
||||||
error("An error occurred trying to delete question (id $question->id)");
|
error("An error occurred trying to delete question (id $question->id)");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
redirect("edit.php");
|
redirect("edit.php");
|
||||||
} else {
|
} else {
|
||||||
error("Confirmation string was incorrect");
|
error("Confirmation string was incorrect");
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// determine if the question is being used in any quiz
|
if ($quiznames = quizzes_question_used($id)) {
|
||||||
$beingused = quizzes_question_used( $delete, $category->publish, $course->id );
|
$a->questionname = $question->name;
|
||||||
if ($beingused) {
|
$a->quiznames = implode(', ', $quiznames);
|
||||||
$beingused = implode(", ", $beingused);
|
notify(get_string('questioninuse', 'quiz', $a));
|
||||||
$beingused = get_string("questioninuse", "quiz", "<i>$question->name</i>")."<p>".$beingused;
|
|
||||||
notice($beingused, "edit.php");
|
|
||||||
|
|
||||||
} else { // the question is not used in any of the existing quizzes
|
|
||||||
|
|
||||||
// we also have to check if the question is being used in the quiz
|
|
||||||
// which is currently being set up
|
|
||||||
if (isset($SESSION->modform)) {
|
|
||||||
if ($qus = explode(",", $SESSION->modform->questions)) {
|
|
||||||
foreach ($qus as $key => $qu) {
|
|
||||||
if ($qu == $delete) {
|
|
||||||
unset($qus[$key]);
|
|
||||||
unset($SESSION->modform->grades[$qu]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
$SESSION->modform->questions = implode(",", $qus);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notice_yesno(get_string("deletequestioncheck", "quiz", $question->name),
|
notice_yesno(get_string("deletequestioncheck", "quiz", $question->name),
|
||||||
|
@ -131,7 +122,6 @@
|
||||||
print_footer($course);
|
print_footer($course);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($form = data_submitted() and confirm_sesskey()) {
|
if ($form = data_submitted() and confirm_sesskey()) {
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue