From ac27e47dc48dbe82b19e24ae59e281b74e758213 Mon Sep 17 00:00:00 2001
From: gustav_delius
Date: Sun, 2 Jan 2005 15:10:50 +0000
Subject: [PATCH] Hierarchical question categories from mediagonal, see
http://moodle.org/bugs/bug.php?op=show&bugid=1947
---
lang/de/quiz.php | 5 +
lang/en/help/quiz/categories.html | 14 +-
lang/en/help/quiz/categories_edit.html | 24 +
lang/en/quiz.php | 5 +
lang/fr/quiz.php | 5 +
mod/quiz/category.php | 863 +++++++++++++++++++++----
mod/quiz/db/mysql.php | 7 +-
mod/quiz/db/mysql.sql | 2 +
mod/quiz/db/postgres7.php | 5 +
mod/quiz/db/postgres7.sql | 5 +-
mod/quiz/lib.php | 75 ++-
mod/quiz/version.php | 4 +-
12 files changed, 871 insertions(+), 143 deletions(-)
create mode 100644 lang/en/help/quiz/categories_edit.html
diff --git a/lang/de/quiz.php b/lang/de/quiz.php
index 9c821760ed..2f2e600048 100644
--- a/lang/de/quiz.php
+++ b/lang/de/quiz.php
@@ -3,6 +3,7 @@
$string['acceptederror'] = 'Akzeptierter Fehler';
+$string['addcategory'] = 'Kategorie hinzufügen';
$string['addingquestions'] = 'Diese Spalte der Seite ist zum Verwalten von Testfragen. Fragen werden in Kategorien gespeichert, um sie besser organisieren zu können, und können von jedem Test Ihres Kurses oder sogar von anderen Kursen (Wenn man \'veröffentlichen\' ausgewählt hat) benutzt werden.
Nachdem Sie eine Kategorie erzeugt haben, können Sie Fragen erzeugen oder bearbeiten. Sie können jede dieser Fragen auswählen und Ihrem Test in der anderen Spalte hinzufügen.';
$string['addquestions'] = 'Fragen hinzufügen';
$string['addquestionstoquiz'] = 'Frage zu aktuellem Test hinzufügen';
@@ -41,6 +42,7 @@ $string['category'] = 'Kategorie';
$string['categoryinfo'] = 'Kategorie-Information';
$string['categorymove'] = 'Die Kategorie \'$a->name\' enthält $a->count Fragen. Bitte wählen Sie eine andere Kategorie, um sie zu verschieben.';
$string['categorymoveto'] = 'In diese Kategorie verschieben';
+$string['categoryupdated'] = 'Änderung an Kategorie gespeichert';
$string['checkanswer'] = 'Prüfen';
$string['choice'] = 'Auswahl';
$string['choices'] = 'Verfügbare Auswahl';
@@ -72,6 +74,7 @@ $string['description'] = 'Beschreibung';
$string['discrimination'] = 'Index für die Abgrenzung';
$string['eachattemptbuildsonthelast'] = 'Jeder Versuch basiert auf dem Letzten';
$string['editcategories'] = 'Kategorien bearbeiten';
+$string['editcategory'] = 'Kategorie bearbeiten';
$string['editdatasets'] = 'Datensatz bearbeiten';
$string['editingcalculated'] = 'Bearbeiten einer Rechen-Frage';
$string['editingdescription'] = 'Eine Beschreibung bearbeiten';
@@ -167,6 +170,7 @@ $string['numerical'] = 'Numerisch';
$string['optional'] = 'optional';
$string['overdue'] = 'Überfällig';
$string['paragraphquestion'] = 'Fragezeichen in Zeile $a wird nicht unterstützt. Die Frage wird ignoriert.';
+$string['parent'] = 'Übergeordnete Kategorie';
$string['passworderror'] = 'Das eingegebene Passwort war falsch';
$string['percentcorrect'] = 'Richtig in Prozent';
$string['preview'] = 'Vorschau';
@@ -240,6 +244,7 @@ $string['timesup'] = 'Zeitraum ist abgelaufen';
$string['timetaken'] = 'Verbrauchte Zeit';
$string['tolerance'] = 'Toleranz';
$string['toomanyrandom'] = 'Die Anzahl der benötigten Zufallsfragen ist größer als die, die die Kategorie enthält! ($a)';
+$string['top'] = 'Oberste Ebene';
$string['true'] = 'Wahr';
$string['truefalse'] = 'Wahr/Falsch';
$string['type'] = 'Typ';
diff --git a/lang/en/help/quiz/categories.html b/lang/en/help/quiz/categories.html
index 5d22556e6c..ea1a95fa75 100644
--- a/lang/en/help/quiz/categories.html
+++ b/lang/en/help/quiz/categories.html
@@ -1,17 +1,23 @@
Question categories
Rather than keeping all your questions in one big list,
- you can create categories to keep them in.
+ you can create categories to keep them in.
-
Each category consists of a name and a short description.
+
Each category consists of a name and a short description.
Each category can also be "published", which means
that the category (and all questions in it) will be
available to all courses on this server, so that
- other courses can use your questions in their quizzes.
+ other courses can use your questions in their quizzes.
Categories can also be created or deleted at will.
However, if you try to delete a category containing
questions, then you will be asked to specify another
- category to move them to.
+ category to move them to.
+
You can also arrange the categories in a heirarchy so
+ that they are easier to manage. The 'Move category to'
+ field lets you move a category to another category.
+
+
By clicking on the arrows in the 'Order' field, you
+ can change the order in which the categories are listed.
\ No newline at end of file
diff --git a/lang/en/help/quiz/categories_edit.html b/lang/en/help/quiz/categories_edit.html
new file mode 100644
index 0000000000..0efab74c63
--- /dev/null
+++ b/lang/en/help/quiz/categories_edit.html
@@ -0,0 +1,24 @@
+
Question categories
+
+
Rather than keeping all your questions in one big list,
+ you can create categories to keep them in.
+
+
Each category consists of a name and a short description.
+
+
Each category can also be "published", which means
+ that the category (and all questions in it) will be
+ available to all courses on this server, so that
+ other courses can use your questions in their quizzes.
+
+
Field descriptions
+
+
Parent: The category in which this one will be placed. If
+ no other categories have been created, only 'Top' will be
+ available
+
+
Category: The name of the category.
+
+
Category info: A brief description of the category.
+
+
Publish: Whether or not to immediately publish this
+ category.
diff --git a/lang/en/quiz.php b/lang/en/quiz.php
index e683ba58b0..17474deb10 100644
--- a/lang/en/quiz.php
+++ b/lang/en/quiz.php
@@ -3,6 +3,7 @@
$string['acceptederror'] = 'Accepted error';
+$string['addcategory'] = 'Add category';
$string['addingquestions'] = 'This side of the page is where you manage your database of questions. Questions are stored in categories to help you keep them organised, and can be used by any quiz in your course or even other courses if you choose to \'publish\' them.
After you select or create a question category you will be able to create or edit questions. You can select any of these questions to add to your quiz over on the other side of this page.';
$string['addquestions'] = 'Add questions';
$string['addquestionstoquiz'] = 'Add questions to current quiz';
@@ -44,6 +45,7 @@ $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['categoryupdated'] = 'The category was successfully updated';
$string['checkanswer'] = 'Check';
$string['choice'] = 'Choice';
$string['choices'] = 'Available choices';
@@ -78,6 +80,7 @@ $string['description'] = 'Description';
$string['discrimination'] = 'Discrim. Index';
$string['eachattemptbuildsonthelast'] = 'Each attempt builds on the last';
$string['editcategories'] = 'Edit categories';
+$string['editcategory'] = 'Edit category';
$string['editdatasets'] = 'Edit the datasets';
$string['editingcalculated'] = 'Editing a Calculated question';
$string['editingdescription'] = 'Editing a Description';
@@ -182,6 +185,7 @@ $string['numerical'] = 'Numerical';
$string['optional'] = 'optional';
$string['overdue'] = 'Overdue';
$string['paragraphquestion'] = 'Paragraph Question not supported at line $a. The question will be ignored';
+$string['parent'] = 'Parent';
$string['passworderror'] = 'The password entered was incorrect';
$string['percentcorrect'] = 'Percent Correct';
$string['popup'] = 'Show quiz in a \"secure\" window';
@@ -265,6 +269,7 @@ $string['timetaken'] = 'Time taken';
$string['tolerance'] = 'Tolerance';
$string['tolerancetype'] = 'Tolerance Type';
$string['toomanyrandom'] = 'The number of random questions required is more than this category contains! ($a)';
+$string['top'] = 'Top';
$string['true'] = 'True';
$string['truefalse'] = 'True/False';
$string['type'] = 'Type';
diff --git a/lang/fr/quiz.php b/lang/fr/quiz.php
index 0c5999ff67..76c83bdb0f 100644
--- a/lang/fr/quiz.php
+++ b/lang/fr/quiz.php
@@ -1,6 +1,7 @@
Créez d\'abord une catégorie. Vous pourrez ensuite créer ou modifier des questions. Vous pouvez choisir une de ces questions pour l\'ajouter à votre test dans l\'autre partie de la page.';
$string['addquestions'] = 'Ajouter des questions';
$string['addquestionstoquiz'] = 'Ajouter ces questions au test en cours';
@@ -42,6 +43,7 @@ $string['category'] = 'Cat
$string['categoryinfo'] = 'Information sur la catégorie';
$string['categorymove'] = 'La catégorie « $a->name » contient $a->count questions. Choisir une autre catégorie dans laquelle les déplacer.';
$string['categorymoveto'] = 'Les déplacer dans cette catégorie';
+$string['categoryupdated'] = 'Catégorie enregistrée';
$string['checkanswer'] = 'Vérifier';
$string['choice'] = 'Proposition';
$string['choices'] = 'Propositions';
@@ -76,6 +78,7 @@ $string['description'] = 'Description';
$string['discrimination'] = 'Index de discrimination';
$string['eachattemptbuildsonthelast'] = 'Chaque tentative complète la précédente';
$string['editcategories'] = 'Modifier les catégories';
+$string['editcategory'] = 'Modifier la catégorie';
$string['editdatasets'] = 'Modifier les jeux de données';
$string['editingcalculated'] = 'Modifier une question calculée';
$string['editingdescription'] = 'Modifier une description';
@@ -180,6 +183,7 @@ $string['numerical'] = 'Num
$string['optional'] = 'facultatif';
$string['overdue'] = 'En retard';
$string['paragraphquestion'] = 'Question paragraphe non supportée à la ligne $a. La question sera ignorée.';
+$string['parent'] = 'Catégorie supérieure';
$string['passworderror'] = 'La clef n\'est pas correcte';
$string['percentcorrect'] = 'Pourcentage de réponses correctes';
$string['popup'] = 'Afficher le test dans une fenêtre « sécurisée »';
@@ -257,6 +261,7 @@ $string['timesup'] = 'Le chrono est enclench
$string['tolerance'] = 'Tolerance';
$string['tolerancetype'] = 'Type de tolerance';
$string['toomanyrandom'] = 'Le nombre de questions aléatoires demandées est plus grand que le total ($a) des questions de cette catégorie !';
+$string['top'] = 'Catégorie racine';
$string['true'] = 'Vrai';
$string['truefalse'] = 'Vrai/Faux';
$string['type'] = 'Type';
diff --git a/mod/quiz/category.php b/mod/quiz/category.php
index c7c2f058f0..6f97ec93a6 100644
--- a/mod/quiz/category.php
+++ b/mod/quiz/category.php
@@ -16,167 +16,786 @@
require_login($course->id);
- if (!isteacher($course->id)) {
- error("Only teachers can use this page!");
+ if (!isteacheredit($course->id)) {
+ error("Only teachers authorized to edit the course '{$course->fullname}' can use this page!");
+ }
+
+ /// CHECK FOR AND ACT UPON VARIABLES SUBMITTED VIA GET OR POST
+ $qcobject = new quiz_category_object();
+ $qcobject->set_course($course);
+
+ if (isset($delete) and !isset($cancel)) {
+ /// Delete category if the user wants to delete it
+ if (isset($confirm)) {
+ /// 'confirm' is the category to move existing questions to
+ $qcobject->delete_category($delete, $confirm);
+ } else {
+ $qcobject->delete_category($delete);
+ }
+ } else if (isset($moveup)) {
+ $qcobject->move_category_up_down('up', $moveup);
+ } else if (isset($movedown)) {
+ $qcobject->move_category_up_down('down', $movedown);
+ } else if (isset($hide)) {
+ $qcobject->publish_category(false, $hide);
+ } else if (isset($move) and isset($moveto)) {
+ $qcobject->move_category($move, $moveto);
+ } else if (isset($publish)) {
+ $qcobject->publish_category(true, $publish);
+ } else if (isset($addcategory)) {
+ require_variable($newparent);
+ require_variable($newcategory);
+ require_variable($newinfo);
+ require_variable($newpublish);
+ $qcobject->add_category($newparent, $newcategory, $newinfo, $newpublish, $course->id);
+ } else if (isset($edit)) {
+ $qcobject->edit_single_category($edit);
+ } else if (isset($updateid)) {
+ require_variable($updateparent);
+ require_variable($updatename);
+ require_variable($updateinfo);
+ require_variable($updatepublish);
+ $qcobject->update_category($updateid, $updateparent, $updatename, $updateinfo, $updatepublish, $course->id);
}
+ /// DISPLAY THE NORMAL USER INTERFACE
+ if (isset($modform)) {
+ $qcobject->display_user_interface($modform);
+ } else {
+ $qcobject->display_user_interface();
+ }
-/// Print headings
+/**
+* Class quiz_category_object
+*
+* Used for handling changes to the quiz categories
+*
+*/
+class quiz_category_object {
+
+ var $str;
+ var $pixpath;
+ var $edittable;
+ var $newtable;
+ var $tab;
+ var $tabsize = 3;
+ var $categories;
+ var $categorystrings;
+ var $defaultcategory;
+ var $course;
+
+/**
+* Constructor
+*
+* Gets necessary strings and sets relevant path information
+*
+*/
+ function quiz_category_object() {
+ global $CFG;
+
+ $this->tab = str_repeat(' ', $this->tabsize);
+
+ $this->str->course = get_string('course');
+ $this->str->category = get_string('category', 'quiz');
+ $this->str->categoryinfo = get_string('categoryinfo', 'quiz');
+ $this->str->questions = get_string('questions', 'quiz');
+ $this->str->add = get_string('add');
+ $this->str->movecategoryto = get_string('movecategoryto');
+ $this->str->delete = get_string('delete');
+ $this->str->moveup = get_string('moveup');
+ $this->str->movedown = get_string('movedown');
+ $this->str->edit = get_string('editthiscategory');
+ $this->str->hide = get_string('hide');
+ $this->str->publish = get_string('publish', 'quiz');
+ $this->str->order = get_string('order');
+ $this->str->parent = get_string('parent', 'quiz');
+ $this->str->add = get_string('add');
+ $this->str->action = get_string('action');
+ $this->str->top = get_string('top', 'quiz');
+ $this->str->addcategory = get_string('addcategory', 'quiz');
+ $this->str->editcategory = get_string('editcategory', 'quiz');
+ $this->str->cancel = get_string('cancel');
+ $this->str->editcategories = get_string('editcategories', 'quiz');
+ $this->pixpath = $CFG->pixpath;
+
+ /// Header:
+ print_header_simple($this->str->editcategories, '',
+ "course->id\">".get_string('modulenameplural', 'quiz').''.
+ " -> {$this->str->editcategories}");
- $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(isset($modform->instance) ? "editingquiz"
- : "editquestions",
- "quiz");
- $streditcategories = get_string("editcategories", "quiz");
+/**
+* Sets the course for this object
+*
+* @param object course
+*/
+ function set_course($course) {
+ $this->course = $course;
+ }
+
+/**
+* Displays the user interface
+*
+* @param object modform
+*/
+ function display_user_interface($modform = null) {
+ $this->initialize();
+
+ /// Interface for adding a new category:
+ echo '