Skip to content

Commit

Permalink
There is now a mechanism by which question types can have their own s…
Browse files Browse the repository at this point in the history
…etup options. Because this does not change anything unless it is used I hope it is o.k. that I am submitting this without asking first. This is based on code by Mad Alex.
  • Loading branch information
gustav_delius committed Jan 22, 2005
1 parent 4530d43 commit 0353801
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 1 deletion.
1 change: 1 addition & 0 deletions lang/en/quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@
$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';
Expand Down
76 changes: 75 additions & 1 deletion mod/quiz/config.html
Original file line number Diff line number Diff line change
@@ -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>
Expand Down
33 changes: 33 additions & 0 deletions mod/quiz/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,39 @@ function grade_response($question, $nameprefix) {
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();
Expand Down

0 comments on commit 0353801

Please sign in to comment.