From: moodler Date: Mon, 14 Oct 2002 15:57:33 +0000 (+0000) Subject: Checking in what I got so far .... Not working yet but I'm going to bed. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=10b9291c9271ab2f38dd5dbc8b90f2898df87354;p=moodle.git Checking in what I got so far .... Not working yet but I'm going to bed. --- diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index da1f7e6244..5c4b438ef2 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -58,8 +58,10 @@ $numattempts = 1; } - if ($numattempts > $quiz->attempts) { - error("Sorry, you've had $quiz->attempts attempts already.", "view.php?id=$cm->id"); + if ($quiz->attempts) { + if ($numattempts > $quiz->attempts) { + error("Sorry, you've had $quiz->attempts attempts already.", "view.php?id=$cm->id"); + } } if ($course->format == "weeks" and $quiz->days) { @@ -115,7 +117,7 @@ error("Sorry! Could not calculate your best grade!"); } - print_heading(get_string("grade", "quiz").": $result->grade/$quiz->grade ($result->sumgrades / $quiz->sumgrades = $percent %)"); + print_heading(get_string("grade", "quiz").": $result->grade/$quiz->grade ($result->sumgrades / $quiz->sumgrades = $result->percentage %)"); print_continue("view.php?id=$cm->id"); @@ -139,7 +141,7 @@ error("Sorry, this quiz is not available", "view.php?id=$cm->id"); } - print_heading("Attempt $numattempts out of $quiz->attempts"); + print_heading(get_string("attempt", "quiz", $numattempts)); print_simple_box($quiz->intro, "CENTER"); @@ -148,7 +150,9 @@ echo "
"; - quiz_print_quiz_questions($quiz); + if (! quiz_print_quiz_questions($quiz)) { + print_continue("view.php?id=$cm->id"); + } /// Finish the page diff --git a/mod/quiz/edit.php b/mod/quiz/edit.php index 8cc5c179de..3219641a94 100644 --- a/mod/quiz/edit.php +++ b/mod/quiz/edit.php @@ -12,7 +12,6 @@ error(get_string("filloutallfields"), $HTTP_REFERER); } - $SESSION->modform = $modform; // Save the form in the current session save_session("SESSION"); @@ -42,7 +41,7 @@ // Now, check for commands on this page and modify variables as necessary - if ($up) { //------------------------------------------------------------ + if ($up) { /// Move the given question up a slot $questions = explode(",", $modform->questions); if ($questions[0] <> $up) { foreach ($questions as $key => $question) { @@ -57,7 +56,7 @@ } } - if ($down) { //---------------------------------------------------------- + if ($down) { /// Move the given question down a slot $questions = explode(",", $modform->questions); if ($questions[count($questions)-1] <> $down) { foreach ($questions as $key => $question) { @@ -72,25 +71,29 @@ } } - if ($add) { //----------------------------------------------------------- + if ($add) { /// Add a question to the current quiz $rawquestions = $HTTP_POST_VARS; - $questions = explode(",", $modform->questions); + if ($modform->questions) { + $questions = explode(",", $modform->questions); + } foreach ($rawquestions as $key => $value) { // Parse input for question ids if (substr($key, 0, 1) == "q") { $key = substr($key,1); - foreach ($questions as $question) { - if ($question == $key) { - continue 2; + if ($questions) { + foreach ($questions as $question) { + if ($question == $key) { + continue 2; + } } } $questions[] = $key; - $modform->grades[$key] = 1; + $modform->grades[$key] = 1; // default score } } $modform->questions = implode(",", $questions); } - if ($delete) { //-------------------------------------------------------- + if ($delete) { /// Delete a question from the list $questions = explode(",", $modform->questions); foreach ($questions as $key => $question) { if ($question == $delete) { @@ -101,7 +104,7 @@ $modform->questions = implode(",", $questions); } - if ($grade) { //--------------------------------------------------------- + if ($grade) { /// The grades have been updated, so update our internal list $rawgrades = $HTTP_POST_VARS; foreach ($rawgrades as $key => $value) { // Parse input for question -> grades if (substr($key, 0, 1) == "q") { @@ -123,6 +126,13 @@ } } + $modform->sumgrades = 0; + if ($modform->grades) { + foreach ($modform->grades as $grade) { + $modform->sumgrades += $grade; + } + } + $SESSION->modform = $modform; save_session("SESSION"); @@ -136,7 +146,7 @@ // Print basic page layout. echo ""; - echo "
"; + echo "
"; print_simple_box_start("CENTER", "100%", $THEME->body); print_heading($modform->name); quiz_print_question_list($modform->questions, $modform->grades); diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php index 0523ef5aff..7643bba22d 100644 --- a/mod/quiz/lib.php +++ b/mod/quiz/lib.php @@ -36,7 +36,7 @@ function quiz_add_instance($quiz) { return false; // some error occurred } - // The grades for each question in this quiz are stored in an array + // The grades for every question in this quiz are stored in an array if ($quiz->grades) { foreach ($quiz->grades as $question => $grade) { $questiongrade->quiz = $quiz->id; @@ -65,7 +65,7 @@ function quiz_update_instance($quiz) { } - // The grades for each question in this quiz are stored in an array + // The grades for every question in this quiz are stored in an array // Insert or update records as appropriate $existing = get_records("quiz_question_grades", "quiz", $quiz->id, "", "question,grade,id"); @@ -105,7 +105,25 @@ function quiz_delete_instance($id) { $result = true; - # Delete any dependent records here # + if ($attempts = get_record("quiz_attempts", "quiz", "$quiz->id")) { + foreach ($attempts as $attempt) { + if (! delete_records("quiz_responses", "attempt", "$attempt->id")) { + $result = false; + } + } + } + + if (! delete_records("quiz_attempts", "quiz", "$quiz->id")) { + $result = false; + } + + if (! delete_records("quiz_grades", "quiz", "$quiz->id")) { + $result = false; + } + + if (! delete_records("quiz_question_grades", "quiz", "$quiz->id")) { + $result = false; + } if (! delete_records("quiz", "id", "$quiz->id")) { $result = false; @@ -253,13 +271,15 @@ function quiz_print_quiz_questions($quiz, $results=NULL) { // Prints a whole quiz on one page. if (!$quiz->questions) { - error("No questions have been defined!", "view.php?id=$cm->id"); + notify("No questions have been defined!", "view.php?id=$cm->id"); + return false; } $questions = explode(",", $quiz->questions); if (!$grades = get_records_list("quiz_question_grades", "question", $quiz->questions, "", "question,grade")) { - error("No grades were found for these questions!"); + notify("No grades were found for these questions!"); + return false; } echo "
"; @@ -272,6 +292,8 @@ function quiz_print_quiz_questions($quiz, $results=NULL) { } echo "
"; echo "
"; + + return true; } function quiz_get_default_category($courseid) { @@ -282,8 +304,8 @@ function quiz_get_default_category($courseid) { } // Otherwise, we need to make one - $category->name = get_string("miscellaneous", "quiz"); - $category->info = get_string("miscellaneous", "quiz"); + $category->name = get_string("default", "quiz"); + $category->info = get_string("defaultinfo", "quiz"); $category->course = $courseid; $category->publish = 0; @@ -308,7 +330,7 @@ function quiz_print_category_form($course, $current) { } $strcategory = get_string("category", "quiz"); $strshow = get_string("show", "quiz"); - $strrename = get_string("rename", "quiz"); + $stredit = get_string("edit"); $strdelete = get_string("delete"); $strnew = get_string("new"); @@ -316,8 +338,8 @@ function quiz_print_category_form($course, $current) { echo "$strcategory: "; choose_from_menu($categories, "cat", "$current"); echo ""; - echo ""; - echo ""; + echo ""; + echo " "; echo ""; echo ""; } @@ -374,7 +396,7 @@ function quiz_print_question_list($questionlist, $grades) { $strmovedown = get_string("movedown"); $strsavegrades = get_string("savegrades", "quiz"); - for ($i=100; $i>=0; $i--) { + for ($i=10; $i>=0; $i--) { $gradesmenu[$i] = $i; } $count = 0; @@ -382,7 +404,7 @@ function quiz_print_question_list($questionlist, $grades) { $total = count($order); echo "
"; echo ""; - echo ""; + echo ""; foreach ($order as $qnum) { $count++; echo "cellcontent\">"; @@ -419,6 +441,8 @@ function quiz_print_question_list($questionlist, $grades) { echo ""; echo "
$strorder$strquestionname$strgrade$stredit
$strorder$strquestionname$strgrade$stredit
"; echo "
"; + + return $sumgrade; } @@ -427,6 +451,7 @@ function quiz_print_cat_question_list($categoryid) { global $THEME, $QUIZ_QUESTION_TYPE; + $strcategory = get_string("category", "quiz"); $strquestion = get_string("question", "quiz"); $strnoquestions = get_string("noquestions", "quiz"); $strselect = get_string("select", "quiz"); @@ -447,9 +472,10 @@ function quiz_print_cat_question_list($categoryid) { notify("Category not found!"); return; } - echo "

$category->info

"; + echo "

$strcategory: $category->name

\n"; + echo text_to_html($category->info); - echo "
"; + echo ""; echo "$strquestion: "; choose_from_menu($QUIZ_QUESTION_TYPE, "type", "", ""); echo "id\">"; @@ -463,21 +489,30 @@ function quiz_print_cat_question_list($categoryid) { return; } + $canedit = isteacher($category->course); + echo ""; echo ""; - echo ""; + echo ""; + if ($canedit) { + echo ""; + } + echo ""; foreach ($questions as $question) { echo "cellcontent\">"; echo ""; echo ""; - echo ""; + if ($canedit) { + echo ""; + } + echo ""; } echo "
$strselect$strquestionname$stredit
$strselect$strquestionname$stredit
"; echo "id VALUE=\"1\">"; echo "".$question->name.""; - echo "id\"> "; - echo "id\">"; - echo "
"; + echo "id\"> "; + echo "id\">"; + echo "
"; echo ""; @@ -733,6 +768,7 @@ function quiz_grade_attempt_results($quiz, $questions) { if ($grade < 0.0) { // No negative grades $grade = 0.0; } + $result->grades[$question->id] = $grade; $result->sumgrades += $grade; $result->feedback[$question->id] = $feedback; diff --git a/mod/quiz/mod.html b/mod/quiz/mod.html index 3323b3c953..2a6f29cf70 100644 --- a/mod/quiz/mod.html +++ b/mod/quiz/mod.html @@ -3,8 +3,6 @@ dirroot/mod/quiz/lib.php") ?> -

This module is not ready for use

-
@@ -95,7 +93,7 @@

:

=0; $i--) { + for ($i=100; $i>=1; $i--) { $grades[$i] = $i; } choose_from_menu($grades, "grade", "$form->grade", ""); diff --git a/mod/quiz/multichoice.html b/mod/quiz/multichoice.html new file mode 100644 index 0000000000..0f0f0fa4a9 --- /dev/null +++ b/mod/quiz/multichoice.html @@ -0,0 +1,46 @@ + +
+ + + + + + + + + + + + + + + + + +

:

+ +

:

+ + +

:

+ category", ""); + ?> +

:

+ single", ""); + ?> +
+ + + +"> + + + +answers go here ... + +
+ diff --git a/mod/quiz/question.php b/mod/quiz/question.php index 3e100f7ae3..76eb5cd1ba 100644 --- a/mod/quiz/question.php +++ b/mod/quiz/question.php @@ -1,3 +1,122 @@ category)) { + error("This question doesn't belong to a vald category!"); + } + if (! $course = get_record("course", "id", $category->course)) { + error("This question category doesn't belong to a valid course!"); + } + + $type = $question->type; + + switch ($type) { + case SHORTANSWER: + print_heading(get_string("editingshortanswer", "quiz")); + require("shortanswer.html"); + break; + case TRUEFALSE: + print_heading(get_string("editingtruefalse", "quiz")); + require("truefalse.html"); + break; + case MULTICHOICE: + print_heading(get_string("editingmultichoice", "quiz")); + require("multichoice.html"); + break; + } + + } else if ($category) { + if (! $category = get_record("quiz_categories", "id", $category)) { + error("This wasn't a valid category!"); + } + if (! $course = get_record("course", "id", $category->course)) { + error("This category doesn't belong to a valid course!"); + } + + $question->category = $category->id; + $question->type = $type; + + } else { + error("Must specify question id or category"); + } + + require_login($course->id); + + if (!isteacher($course->id)) { + error("You can't modify this course!"); + } + + $streditingquiz = get_string("editingquiz", "quiz"); + $streditingquestion = get_string("editingquestion", "quiz"); + + print_header("$course->shortname: $streditingquestion", "$course->shortname: $streditingquestion", + "wwwroot/course/view.php?id=$course->id\">$course->shortname + -> $streditingquiz -> $streditingquestion"); + + if (match_referer() and isset($HTTP_POST_VARS)) { // question submitted + + } + + $grades = array(100,90,80,75,70,66.66,60,50,40,33.33,30,25,20,10,5); + foreach ($grades as $grade) { + $gradeoptions[$grade] = $grade; + $gradeoptions[-$grade] = -$grade; + } + arsort($gradeoptions, SORT_NUMERIC); + + if (!$categories = get_records_sql_menu("SELECT id,name FROM quiz_categories + WHERE course='$course->id' OR publish = '1' + ORDER by name ASC")) { + error("No categories!"); + } + + // Print the question editing form + + switch ($type) { + case SHORTANSWER: + $options = get_record("quiz_shortanswer", "question", "$question->id");// OK to fail + $answer = get_record("quiz_answers", "id", "$options->answer"); // OK to fail + print_heading(get_string("editingshortanswer", "quiz")); + require("shortanswer.html"); + break; + + case TRUEFALSE: + $options = get_record("quiz_truefalse", "question", "$question->id"); // OK to fail + $true = get_record("quiz_answers", "id", "$options->true"); // OK to fail + $false = get_record("quiz_answers", "id", "$options->false"); // OK to fail + print_heading(get_string("editingtruefalse", "quiz")); + require("truefalse.html"); + break; + + case MULTICHOICE: + $options = get_record("quiz_multichoice", "question", "$question->id");// OK to fail + $answersraw = get_records_list("quiz_answers", "id", "$options->answers");// OK to fail + if ($answersraw) { + foreach ($answersraw as $answer) { + $answers[] = $answer; // to renumber index 0,1,2... + } + } + print_heading(get_string("editingmultichoice", "quiz")); + require("multichoice.html"); + break; + + default: + error("Invalid question type"); + break; + } + + print_footer($course); ?> diff --git a/mod/quiz/shortanswer.html b/mod/quiz/shortanswer.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mod/quiz/truefalse.html b/mod/quiz/truefalse.html new file mode 100644 index 0000000000..e69de29bb2 diff --git a/mod/quiz/view.php b/mod/quiz/view.php index 2a2d362b6a..c7e0c2b0f3 100644 --- a/mod/quiz/view.php +++ b/mod/quiz/view.php @@ -106,12 +106,13 @@ $mygrade = quiz_get_best_grade($quiz->id, $USER->id); - if ($numattempts < $quiz->attempts) { + if ($numattempts < $quiz->attempts or !$quiz->attempts) { if ($available) { - $options["id"] = $quiz->id; + $options["id"] = $cm->id; if ($numattempts) { print_heading("Your best grade so far is $mygrade / $quiz->grade."); } + echo "
"; echo "
"; print_single_button("attempt.php", $options, $label="Attempt quiz now"); echo "

";