From 985292b7cde0a5d2f90f10c98a217ed8f817aada Mon Sep 17 00:00:00 2001
From: jonhartm Be careful in making any changes if this quiz has submissions.
Be careful in making any changes if this quiz has submissions.
+\n"); +// echo('+The assignment is configured by carefully editing the gift below. +The documentation for the GIFT format comes from +Moodle Documentation. +
+ +footer(); diff --git a/quiz_data.php b/quiz_data.php new file mode 100644 index 0000000..005934c --- /dev/null +++ b/quiz_data.php @@ -0,0 +1,22 @@ +getJson(); + +$questions = false; +$errors = array("No questions found"); +if ( strlen($gift) > 0 ) { + $questions = array(); + $errors = array(); + parse_gift($gift, $questions, $errors); +} + +echo json_encode($questions, JSON_PRETTY_PRINT); diff --git a/templates/common.hbs b/templates/common.hbs new file mode 100644 index 0000000..d80a3f2 --- /dev/null +++ b/templates/common.hbs @@ -0,0 +1,11 @@ +{{__ 'True'}}
+{{__ 'False'}}
+WARNING: Please fix the following errors before saving...
'); + + // Add each error as a seperateelement + for (var i = 0; i < validation_errors.length; i++) { + var p = $("
").text(validation_errors[i]); + $(".validation-error-list").append(p); + } + } + else { + // No errors, so hide the error list and enable the "save" buttons + $(".validation-error-list").hide(); + $("input[name='save_quiz']").removeAttr("disabled"); + } +} + +// Check the given question number to make sure there are no validation errors +// If there are, return a list of strings indicating which errors were found +// If not, return null +function validate_question(num) { + var validation_errors = []; + var q_div = "#question"+num; // the div id for this question + var q_type = $(q_div + " [type='hidden']").val(); // the type of this question + + // check that there's at least something in the question text field + var q_text = $(q_div + " [name^=text_question]"); + if (q_text.val().length == 0) { + q_text.addClass("warning"); + validation_errors.push("Question " + num + ": Question Text must not be blank."); + } else { + q_text.removeClass("warning"); + } + + // specific checks for different question types + if (q_type == "true_false_question") { + // make sure the user has selected either true or false for this question + var checked_count = $(q_div + " [type='radio']:checked").length; + if (checked_count == 0) { + $(q_div + " .truefalse-container").addClass("warning"); + validation_errors.push("Question " + num + ": True/False Questions must have \"True\" or \"False\" selected."); + } else { + $(q_div + " .truefalse-container").removeClass("warning"); + } + } else if ( q_type == "multiple_choice_question" || q_type == "multiple_answers_question") { + // make sure there's at least one right answer checked for MC/MA questions + var checked_count = $(q_div + " [type='checkbox']:checked").length; + if (checked_count == 0) { + $(q_div + " .question-content-container").addClass("warning"); + validation_errors.push("Question " + num + ": At least one correct answer must be provided."); + } else { + $(q_div + " .question-content-container").removeClass("warning"); + } + } else if (q_type == "short_answer_question") { + // make sure there's at least one answer at least 1 character long + var answer_present = false; + var answers = $(q_div + " .answer-option"); + for (var i = 0; i < answers.length; i++) { + if ($(answers[i]).val().length > 0) { + answer_present = true; + } + } + if (!answer_present) { + $(q_div + " .question-content-container").addClass("warning"); + validation_errors.push("Question " + num + ": At least one correct answer must be provided."); + } else { + $(q_div + " .question-content-container").removeClass("warning"); + } + } + // return the list of errors, or null if there weren't any + if (validation_errors.length > 0) { + return validation_errors; + } else { + return null; + } +} From 213db0114391ee4b16d379fe15575929ad502738 Mon Sep 17 00:00:00 2001 From: jonhartm{{__ 'True'}}
{{__ 'False'}}
From 3b640b627c836a41fccb135cf87f0937069053bb Mon Sep 17 00:00:00 2001 From: jonhartm