]> git.mjollnir.org Git - moodle.git/commitdiff
There is now a mechanism by which question types can have their own setup options...
authorgustav_delius <gustav_delius>
Sat, 22 Jan 2005 22:27:16 +0000 (22:27 +0000)
committergustav_delius <gustav_delius>
Sat, 22 Jan 2005 22:27:16 +0000 (22:27 +0000)
lang/en/quiz.php
mod/quiz/config.html
mod/quiz/locallib.php

index d746ad0795bd4fedc21c77812f9761e1af7eff1b..79925e8a1f6f0a6ab5e1b4755007907a7ae1b2f3 100644 (file)
@@ -203,6 +203,7 @@ $string['questionname'] = 'Question name';
 $string['questionnametoolong'] = 'Question name too long at line $a (255 char. max). It has been truncated.';
 $string['questions'] = 'Questions';
 $string['questionsperpage'] = 'Max number of questions per page';
+$string['questiontypesetupoptions'] = 'Setup options for question types:';
 $string['quizavailable'] = 'The quiz is available until: $a';
 $string['quizclose'] = 'Close the quiz';
 $string['quizclosed'] = 'This quiz closed on $a';
index 8345cb1f6d79e43e66ff4facc6e8364dd4565ba0..c3def0612ee15c1692a68742ba6f4649d162df2e 100644 (file)
@@ -1,7 +1,81 @@
+<?php
+    require_once($CFG->dirroot . '/mod/quiz/locallib.php');
+?>
 <form method="post" action="module.php" name="form">
 <input type="hidden" name="sesskey" value="<?php echo $USER->sesskey ?>">
 
-<table cellpadding="9" cellspacing="0" >
+
+<!-- Table of config options -->
+<?php
+    $table_created = false; // used to make sure that table is only created when needed
+    $submitbutton = false;
+    // Include the options from each question type
+    foreach ($QUIZ_QTYPES as $type) {
+        $options = $type->get_config_options();
+        if ($options) {
+            // Temporary code
+            if (!$table_created) {
+                echo "<table cellpadding=\"9\" cellspacing=\"0\" align=\"center\">\n";
+                echo '<tr><th colspan="3">';
+                print_heading(get_string('questiontypesetupoptions', 'quiz'));
+                echo "</th></tr>\n";
+                $table_created = true;
+            }
+            $typename = $type->name();
+            $strtype = get_string($typename, 'quiz');
+            echo "<tr valign=\"top\">\n";
+            echo '<td colspan="3" align="center"><b>' . $strtype . "</b></td>\n";
+            echo "</tr>\n";
+            foreach ($options as $option) {
+                if (!isset($option->name)) {
+                    continue;
+                }
+                echo "<tr valign=\"top\">\n";
+                if (!empty($option->link)) {
+                    echo '<td colspan="3" align="center"><a href="' . s($CFG->wwwroot) . '/mod/quiz/questiontypes/' . s($typename) . '/' . s($option->link) . '?sesskey=' . s(rawurlencode($USER->sesskey)) . '">' . get_string($option->name, 'quiz') . "</a></td>\n";
+                }
+                else {
+                    if (!isset($option->code)) {
+                        $option->code = '';
+                    }
+                    echo '<td align="right"><b>';
+                    print_string($option->name, 'quiz');
+                    echo ":</b></td>\n";
+                    echo '<td>' . $option->code . "</td>\n";
+                    if (empty($option->help)) {
+                        echo "<td></td>\n";
+                    }
+                    else {
+                        echo '<td align="left">' . get_string($option->help, 'quiz') . "</td>\n";
+                    }
+                    $submitbutton = 'true';
+                }
+                echo "</tr>\n";
+            }
+        }
+    }
+    if ($submitbutton) {
+?>
+<tr>
+  <td colspan="3" align="center">
+    <input type="submit" value="<?php print_string("savechanges") ?>" />
+  </td>
+</tr>
+</table>
+<?php
+    }
+    if ($table_created) {
+        echo '</table>';
+        print_simple_box_end();
+        echo '<br />';
+        print_simple_box_start("center", "", "$THEME->cellheading");
+    }
+?>
+
+
+<!-- Table of default values -->
+
+<table cellpadding="9" cellspacing="0" align="center">
 
 <tr valign="top">
   <th align="right">&nbsp;</th>
index 4dae361e3efd10fe1203b68d780e6097e0bf748a..e3d4540bb5f44eb06b4fa607d369522ac8fd8174 100644 (file)
@@ -312,6 +312,39 @@ class quiz_default_questiontype {
         error('grade_response has not been implemented for question type '
                 .$this->name());
     }
+
+    function get_config_options() {
+    // Returns an array of objects describing the options for the question type
+    // to be included on the quiz module admin page
+    //
+    // Configuration options can be included by setting the following fields in
+    // the object:
+    // ->name           (The name of the option within this question type
+    //                   - the full option name will be constructed as
+    //                   "quiz_{$this->name()}_$name", the human readable name
+    //                   will be displayed with get_string($name, 'quiz'))
+    // ->code           (The code to display the form element, help button, etc.
+    //                   i.e. the content for the central table cell. Be sure
+    //                   to name the element "quiz_{$this->name()}_$name" and
+    //                   set the value to $CFG->{"quiz_{$this->name()}_$name"})
+    // ->help           (Name of the string from the quiz module language file
+    //                   to be used for the help message in the third column of
+    //                   the table. An empty string (or the field not set)
+    //                   means to leave the box empty)
+    //
+    // Links to custom settings pages can be included by setting the following
+    // fields in the object:
+    // ->name           (The name of the link text string -
+    //                   get_string($name, 'quiz') will be called)
+    // ->link           (The filename part of the URL for the link
+    //                   - the full URL is contructed as
+    //                   "$CFG->wwwroot/mod/quiz/questiontypes/{$this->name()}/$link?sesskey=$sesskey"
+    //                   [but with the relavant calls to the s and rawurlencode
+    //                   functions] where $sesskey is the sesskey for the user)
+
+        // No options by default
+        return false;
+    } 
 }
 
 quiz_load_questiontypes();