]> git.mjollnir.org Git - moodle.git/commitdiff
New page quiz/questiontypes/datasetdependent/categorydatasetdefinitions.php?category=XX
authorkaipe <kaipe>
Thu, 5 Aug 2004 09:53:17 +0000 (09:53 +0000)
committerkaipe <kaipe>
Thu, 5 Aug 2004 09:53:17 +0000 (09:53 +0000)
offers a simple editing view for category reusable dataset definitions.
It is unlinked but can be reached by specifying the URL or having a question
edit page link it in the future.

lang/en/quiz.php
mod/quiz/questiontypes/datasetdependent/categorydatasetdefinitions.php [new file with mode: 0644]

index 8a938e59a4733872499635905adf8d01f15ec873..9f3b517d8e33a0f4cd187438876ee5813b673e06 100644 (file)
@@ -56,6 +56,7 @@ $string['coursetestmanager'] = 'Course Test Manager format';
 $string['createmultiple'] = 'Create multiple questions';
 $string['createnewquestion'] = 'Create new question';
 $string['custom'] = 'Custom format';
+$string['datasetdefinitions'] = 'Reusable dataset definitions for category $a';
 $string['datasetnumber'] = 'Number';
 $string['daysavailable'] = 'Days available';
 $string['decimals'] = ' with $a ';
@@ -96,6 +97,7 @@ $string['exportnameformat'] = '%%Y%%m%%d-%%H%%M';
 $string['exportquestions'] = 'Export questions to file';
 $string['false'] = 'False';
 $string['feedback'] = 'Feedback';
+$string['file'] = 'File';
 $string['fileformat'] = 'File format';
 $string['filloutoneanswer'] = 'You must fill out at least one possible answer.  Answers left blank will not be used.';
 $string['filloutthreequestions'] = 'You must fill out at least three questions.  Questions left blank will not be used.';
@@ -122,6 +124,7 @@ $string['importquestions'] = 'Import questions from file';
 $string['indivresp'] = 'Responses of Individuals to Each Item';
 $string['introduction'] = 'Introduction';
 $string['itemanal'] = 'Item Response Analysis';
+$string['itemdefinition'] = 'Definition';
 $string['keptcategory'] = 'a '
         // The use of ) and ( below should really not be necessary but
         // because of some sort of PHP bug it is better to keep'em
@@ -136,7 +139,9 @@ $string['keptlocal'] = 'a '
     .' from the same question private set of '
     .'".(1==$a ? \'literals\' :(2==$a ? \'files\' : (3==$a ? \'links\' : $a)))."'
     .' as before';
+$string['link'] = 'Link';
 $string['listitems'] = 'Listing of Items in Quiz';
+$string['literal'] = 'Literal';
 $string['loguniform'] = 'digits, from a loguniform distribution';
 $string['marks'] = 'Marks';
 $string['match'] = 'Matching';
diff --git a/mod/quiz/questiontypes/datasetdependent/categorydatasetdefinitions.php b/mod/quiz/questiontypes/datasetdependent/categorydatasetdefinitions.php
new file mode 100644 (file)
index 0000000..6e21bdb
--- /dev/null
@@ -0,0 +1,106 @@
+<?PHP // $Id$
+
+    /////////////////////////////////////////////////////////////////////
+    ///// This page offers a way to define category level datasets  /////
+    /////////////////////////////////////////////////////////////////////
+
+    require_once("../../../../config.php");
+
+    require_variable($category);
+    optional_variable($question);
+
+    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!");
+    }
+
+    require_login($course->id);
+
+    if (!isteacheredit($course->id)) {
+        error("Only the teacher can import quiz questions!");
+    }
+
+    $DATASET_TYPES = array('1' => get_string('literal', 'quiz'),
+                           '2' => get_string('file', 'quiz'),
+                           '3' => get_string('link', 'quiz'));
+
+    $streditingquiz = get_string("editingquiz", "quiz");
+    $strdefinedataset = get_string("datasetdefinitions", "quiz", $category->name);
+    $strquestions = get_string("questions", "quiz");
+
+    print_header("$course->shortname: $strdefinedataset", "$course->shortname: $strdefinedataset",
+                 "<A HREF=\"$CFG->wwwroot/course/view.php?id=$course->id\">$course->shortname</A> 
+                  -> <A HREF=\"../../edit.php\">$streditingquiz</A> -> $strdefinedataset");
+
+    if ($form = data_submitted()) {   /// Filename
+
+        $definition->category = $category->id;
+        foreach ($form->name as $key => $name) {
+            $definition->name = $name;
+            $definition->id   = $form->id[$key];
+            $definition->type = $form->type[$key];
+            
+            if ($definition->id) {
+                if (!update_record('quiz_dataset_definitions', $definition)) {
+                    notify("Could not update dataset item definition");
+                }
+
+            } else if ($definition->name) {
+                if (!insert_record('quiz_dataset_definitions', $definition)) {
+                    notify("Could not insert dataset item defintion");
+                }
+
+            } else {
+                // No action
+            }
+        }
+        if ($form->question) {
+            redirect("../../question.php?id=$question");
+        } else {
+            redirect("../../edit.php");
+        }
+    }
+
+    /// Print form
+
+    print_heading_with_help($strdefinedataset, "datasets", "quiz");
+
+    print_simple_box_start("center", "", "$THEME->cellheading");
+    echo "<form method=\"post\" action=\"categorydatasetdefinitions.php\">";
+    echo "<input type=\"hidden\" name=\"category\" value=\"$category->id\"/>";
+    if ($question) {
+        echo "<input type=\"hidden\" name=\"question\" value=\"$question\"/>";
+    }
+    
+    echo "<table cellpadding=5>";
+
+    $definitions = get_records('quiz_dataset_definitions',
+                               'category',
+                               $category->id);
+    for ($idef = 1, $total = max(5, count($definitions)) ; $idef <= $total ; ++$idef) {
+        if ($definitions) {
+            $definition = array_shift($definitions);
+        } else {
+            $definition = NULL;
+        }
+
+        echo "<tr><td align=right>";
+        print_string("itemdefinition", "quiz");
+        echo ":</td><td>";
+        echo "<input name=\"name[]\" type=\"text\" size=\"20\" value=\"$definition->name\"/>";
+        echo "<input type=\"hidden\" name=\"id[]\" value=\"$definition->id\"/>";
+        echo " </td><td> ";
+        choose_from_menu($DATASET_TYPES, 'type[]', $definition->type, '');
+        echo "</td></tr>\n";
+    }
+
+    echo "<tr><td align=\"CENTER\" colspan=\"3\"><input type=submit value=\"".get_string("continue")."\"></td></tr>";
+    echo "</table>";
+    echo "</form>";
+    print_simple_box_end();
+
+    print_footer($course);
+?>