From: moodler
Date: Sun, 20 Oct 2002 17:15:39 +0000 (+0000)
Subject: Category editing in quizzes is now supported. Some other little
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=c74a0ca5c24473ccf5dc1ba9b8a5b44dcecb2fb9;p=moodle.git
Category editing in quizzes is now supported. Some other little
cleanups along the way ...
---
diff --git a/lang/en/quiz.php b/lang/en/quiz.php
index 7d3abf86b3..5acb098e58 100644
--- a/lang/en/quiz.php
+++ b/lang/en/quiz.php
@@ -7,7 +7,7 @@ $string['modulenameplural'] = "Quizzes";
$string['addselectedtoquiz'] = "Add selected to quiz";
$string['alwaysavailable'] = "Always available";
-$string['alreadysubmitted'] = "Perhaps you already submitted this attempt";
+$string['alreadysubmitted'] = "It is likely that you have already submitted this attempt";
$string['answer'] = "Answer";
$string['answerhowmany'] = "One or multiple answers?";
$string['answersingleyes'] = "One answer only";
@@ -18,12 +18,16 @@ $string['attemptlast'] = "Last attempt";
$string['attempts'] = "Attempts";
$string['attemptsallowed'] = "Attempts allowed";
$string['attemptsunlimited'] = "Unlimited attempts";
+$string['backtoquiz'] = "Back to quiz editing";
$string['bestgrade'] = "Best grade";
-$string['categories'] = "Categories";
-$string['category'] = "Category";
$string['casesensitive'] = "Case sensitivity";
$string['caseyes'] = "Yes, case must match";
$string['caseno'] = "No, case is unimportant";
+$string['categories'] = "Categories";
+$string['category'] = "Category";
+$string['categoryinfo'] = "Category info";
+$string['categorymove'] = "The category '\$a->name' contains \$a->count questions. Please choose another category to move them to.";
+$string['categorymoveto'] = "Move them to this category";
$string['choice'] = "Choice";
$string['choices'] = "Available choices";
$string['correctanswer'] = "Correct answer";
@@ -53,7 +57,9 @@ $string['multichoice'] = "Multiple Choice";
$string['noanswers'] = "No answers were selected!";
$string['nomoreattempts'] = "No more attempts are allowed";
$string['noquestions'] = "No questions have been added yet";
+$string['publish'] = "Publish";
$string['question'] = "Question";
+$string['questions'] = "Questions";
$string['questionname'] = "Question name";
$string['quizavailable'] = "The quiz is available until: \$a";
$string['quizclose'] = "Close the quiz";
@@ -79,5 +85,6 @@ $string['timetaken'] = "Time taken";
$string['timecompleted'] = "Completed";
$string['true'] = "True";
$string['truefalse'] = "True/False";
+$string['type'] = "Type";
$string['viewallanswers'] = "View \$a completed quizzes";
$string['yourfinalgradeis'] = "Your final grade for this quiz is \$a";
diff --git a/lib/moodlelib.php b/lib/moodlelib.php
index e32c493fdd..ac7dcc33a2 100644
--- a/lib/moodlelib.php
+++ b/lib/moodlelib.php
@@ -681,7 +681,7 @@ function optional_variable(&$var, $default=0) {
/// DATABASE HANDLING ////////////////////////////////////////////////
-function execute_sql($command) {
+function execute_sql($command, $feedback=true) {
// Completely general
global $db;
@@ -689,10 +689,14 @@ function execute_sql($command) {
$result = $db->Execute("$command");
if ($result) {
- echo "".get_string("success")."
";
+ if ($feedback) {
+ echo "".get_string("success")."
";
+ }
return true;
} else {
- echo "".get_string("error")."
";
+ if ($feedback) {
+ echo "".get_string("error")."
";
+ }
return false;
}
}
diff --git a/mod/quiz/category.php b/mod/quiz/category.php
index b3ce80f42d..4de75c88b1 100644
--- a/mod/quiz/category.php
+++ b/mod/quiz/category.php
@@ -1,4 +1,175 @@
id);
+
+ if (!isteacher($course->id)) {
+ error("Only teachers can use this page!");
+ }
+
+
+/// Print headings
+
+ $strcategory = get_string("category", "quiz");
+ $strcategoryinfo = get_string("categoryinfo", "quiz");
+ $strquestions = get_string("questions", "quiz");
+ $strpublish = get_string("publish", "quiz");
+ $strdelete = get_string("delete");
+ $straction = get_string("action");
+ $stradd = get_string("add");
+ $strcancel = get_string("cancel");
+ $strsavechanges = get_string("savechanges");
+ $strbacktoquiz = get_string("backtoquiz", "quiz");
+
+ $streditingquiz = get_string("editingquiz", "quiz");
+ $streditcategories = get_string("editcategories", "quiz");
+
+ print_header("$course->shortname: $streditcategories", "$course->shortname: $streditcategories",
+ "wwwroot/course/view.php?id=$course->id\">$course->shortname
+ -> $streditingquiz -> $streditcategories");
+
+
+/// Delete category if the user wants to delete it
+
+ if (isset($delete) and !isset($cancel)) {
+ if (!$category = get_record("quiz_categories", "id", $delete)) { // security
+ error("No such category $delete!");
+ }
+
+ if (isset($confirm)) { // Need to move some questions before deleting the category
+ if (!$category2 = get_record("quiz_categories", "id", $confirm)) { // security
+ error("No such category $confirm!");
+ }
+ if (! execute_sql("UPDATE quiz_questions SET category = '$category2->id' WHERE category = '$category->id'", false)) {
+ error("Error while moving questions from category '$category->name' to '$category2->name'");
+ }
+
+ } else {
+ if ($count = count_records("quiz_questions", "category", $category->id)) {
+ $vars->name = $category->name;
+ $vars->count = $count;
+ print_simple_box(get_string("categorymove", "quiz", $vars), "CENTER");
+ $categories = quiz_get_category_menu($course->id);
+ unset($categories[$category->id]);
+ echo "
";
+ print_footer($course);
+ exit;
+ }
+ }
+ delete_records("quiz_categories", "id", $category->id);
+ notify(get_string("categorydeleted", "", $category->name));
+ }
+
+/// Print heading
+
+ print_heading($streditcategories);
+
+/// If data submitted, then process and store.
+
+ if (match_referer() && isset($HTTP_POST_VARS)) {
+
+ $form = $HTTP_POST_VARS;
+
+ // Peel out all the data from variable names.
+ foreach ($form as $key => $val) {
+ if ($key == "new" and $val != "") {
+ $cat->name = $val;
+ $cat->info = $form['newinfo'];
+ $cat->publish = $form['newpublish'];
+ $cat->course = $course->id;
+ if (!insert_record("quiz_categories", $cat)) {
+ error("Could not insert the new quiz category '$val'");
+ } else {
+ notify(get_string("categoryadded", "", $val));
+ }
+
+ } else if (substr($key,0,1) == "c") {
+ $cat->id = substr($key,1);
+ $cat->name = $val;
+ $cat->info = $form["i$cat->id"];
+ $cat->publish = $form["p$cat->id"];
+ $cat->course = $course->id;
+ if (!update_record("quiz_categories", $cat)) {
+ error("Could not update the quiz category '$val'");
+ }
+ }
+ }
+ }
+
+
+/// Get the existing categories
+ if (!$categories = get_records("quiz_categories", "course", $course->id, "id ASC")) {
+ unset($categories);
+ if (!$categories[] = quiz_get_default_category($course->id)) {
+ error("Error: Could not find or make a category!");
+ }
+ }
+
+
+/// Find lowest ID category - this is the default category
+ $default = 99999;
+ foreach ($categories as $category) {
+ if ($category->id < $default) {
+ $default = $category->id;
+ }
+ }
+
+
+ $publishoptions[0] = get_string("no");
+ $publishoptions[1] = get_string("yes");
+
+
+/// Print the table of all categories
+ $table->head = array ($strcategory, $strcategoryinfo, $strpublish, $strquestions, $straction);
+ $table->align = array ("LEFT", "LEFT", "CENTER", "CENTER", "CENTER");
+ $table->size = array ("50", "50", "10", "10", "20");
+ $table->width = 200;
+
+ echo "";
+
+ print_footer();
-echo "not done yet";
?>
diff --git a/mod/quiz/lib.php b/mod/quiz/lib.php
index aec475b2ce..9fccbba01f 100644
--- a/mod/quiz/lib.php
+++ b/mod/quiz/lib.php
@@ -221,14 +221,28 @@ function quiz_print_correctanswer($text) {
echo "$text
";
}
-function quiz_print_question($number, $questionid, $grade, $courseid,
+function quiz_print_question_icon($question) {
+// Prints a question icon
+ switch ($question->type) {
+ case SHORTANSWER:
+ echo "
";
+ break;
+ case TRUEFALSE:
+ echo "
";
+ break;
+ case MULTICHOICE:
+ echo "
";
+ break;
+ case RANDOM:
+ echo "
";
+ break;
+ }
+}
+
+function quiz_print_question($number, $questionid, $grade, $courseid,
$feedback=NULL, $response=NULL, $actualgrade=NULL, $correct=NULL) {
/// Prints a quiz question, any format
- global $THEME;
- $comment = $THEME->cellheading2;
- $green = "#AAFFAA";
-
if (!$question = get_record("quiz_questions", "id", $questionid)) {
notify("Error: Question not found!");
}
@@ -263,7 +277,7 @@ function quiz_print_question($number, $questionid, $grade, $courseid,
quiz_print_comment("$feedback[0]
");
}
if ($correct) {
- $correctanswers = implode(",", $correct);
+ $correctanswers = implode(", ", $correct);
quiz_print_correctanswer($correctanswers);
}
break;
@@ -445,12 +459,17 @@ function quiz_get_default_category($courseid) {
return $category;
}
+function quiz_get_category_menu($courseid, $published=false) {
+ if ($published) {
+ $publish = "OR publish = '1'";
+ }
+ return get_records_sql_menu("SELECT id,name FROM quiz_categories WHERE course='$courseid' $publish ORDER by name ASC");
+}
+
function quiz_print_category_form($course, $current) {
// Prints a form to choose categories
- if (!$categories = get_records_sql_menu("SELECT id,name FROM quiz_categories
- WHERE course='$course->id' OR publish = '1'
- ORDER by name ASC")) {
+ if (!$categories = quiz_get_category_menu($course->id, true)) {
if (!$category = quiz_get_default_category($course->id)) {
notify("Error creating a default category!");
return false;
@@ -533,6 +552,7 @@ function quiz_print_question_list($questionlist, $grades) {
$strmoveup = get_string("moveup");
$strmovedown = get_string("movedown");
$strsavegrades = get_string("savegrades", "quiz");
+ $strtype = get_string("type", "quiz");
for ($i=10; $i>=0; $i--) {
$gradesmenu[$i] = $i;
@@ -542,7 +562,7 @@ function quiz_print_question_list($questionlist, $grades) {
$total = count($order);
echo "