Templates and css hooks for more questiontypes. Essay and RQP will be done at a later date.

This commit is contained in:
gustav_delius 2006-03-01 16:15:30 +00:00
parent f413e3fbee
commit 37a12367c5
9 changed files with 89 additions and 89 deletions

View File

@ -0,0 +1,14 @@
<table id="q<?php echo $question->id; ?>" class="question <?php echo $this->name(); ?>"><tr><td>
<div class="info">
<span class="edit"><?php echo $editlink; ?></span>
</div>
<div class="content">
<div class="qtext">
<?php echo $questiontext; ?>
</div>
<?php if ($image) { ?>
<img class="qimage" src="<?php echo $q->imageurl; ?>" alt="" />
<?php } ?>
</div>
</td></tr></table>

View File

@ -28,18 +28,22 @@ class quiz_description_qtype extends quiz_default_questiontype {
}
function print_question(&$question, &$state, $number, $cmoptions, $options) {
print_simple_box_start('center', '90%');
echo format_text($question->questiontext,
global $CFG;
// For editing teachers print a link to an editing popup window
$editlink = '';
if (isteacheredit($cmoptions->course)) {
$stredit = get_string('edit');
$linktext = '<img src="'.$CFG->pixpath.'/t/edit.gif" border="0" alt="'.$stredit.'" />';
$editlink = link_to_popup_window('/question/question.php?id='.$question->id, $stredit, $linktext, 450, 550, $stredit, '', true);
}
$questiontext = format_text($question->questiontext,
$question->questiontextformat,
NULL, $cmoptions->course);
quiz_print_possible_question_image($question, $cmoptions->course);
if (isteacher($cmoptions->course)) {
echo '<font size="1">';
link_to_popup_window ('/question/question.php?id=' . $question->id,
'editquestion', get_string('edit'), 450, 550, get_string('edit'));
echo '</font>';
}
print_simple_box_end('center', '90%');
$image = get_question_image($question, $cmoptions->course);
include "$CFG->dirroot/question/questiontypes/description/question.html";
}
function actual_number_of_questions($question) {

View File

@ -91,7 +91,7 @@ class quiz_essay_qtype extends quiz_default_questiontype {
$question->questiontextformat,
NULL, $cmoptions->course);
quiz_print_possible_question_image($question, $cmoptions->course);
echo get_question_image($question, $cmoptions->course);
/// Print input controls
$stranswer = get_string("answer", "quiz");

View File

@ -0,0 +1,29 @@
<div class="qtext">
<?php echo $questiontext; ?>
</div>
<?php if ($image) { ?>
<img class="qimage" src="<?php echo $q->imageurl; ?>" alt="" />
<?php } ?>
<div class="ablock clearfix">
<table class="answer">
<?php $row = 1; foreach ($anss as $answer) { ?>
<tr class="<?php echo 'r'.$row = $row ? 0 : 1; ?>">
<td class="c0 text">
<?php echo $answer->text; ?>
</td>
<td class="c1 control <?php echo $answer->class ?>">
<?php echo $answer->control; ?>
</td>
<!--
<td class="c0 feedback">
<?php echo $answer->feedback; ?>
</td>
-->
</tr>
<?php } ?>
</table>
<?php $this->print_question_submit_buttons($question, $state, $cmoptions, $options); ?>
</div>

View File

@ -211,6 +211,7 @@ class quiz_match_qtype extends quiz_default_questiontype {
}
function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
global $CFG;
$subquestions = $state->options->subquestions;
$correctanswers = $this->get_correct_responses($question, $state);
$nameprefix = $question->name_prefix;
@ -227,22 +228,19 @@ class quiz_match_qtype extends quiz_default_questiontype {
// Shuffle the answers
$answers = draw_rand_array($answers, count($answers));
// Print question text and possible image
if (!empty($question->questiontext)) {
echo format_text($question->questiontext,
$question->questiontextformat,
NULL, $cmoptions->course);
}
quiz_print_possible_question_image($question, $cmoptions->course);
// Print formulation
$questiontext = format_text($question->questiontext,
$question->questiontextformat,
NULL, $cmoptions->course);
$image = get_question_image($question, $cmoptions->course);
///// Print the input controls //////
echo '<table border="0" cellpadding="10" align="right">';
foreach ($subquestions as $key => $subquestion) {
/// Subquestion text:
echo '<tr><td align="left" valign="top">';
echo format_text($subquestion->questiontext,
$a->text = format_text($subquestion->questiontext,
$question->questiontextformat, NULL, $cmoptions->course);
echo '</td>';
/// Drop-down list:
$menuname = $nameprefix.$subquestion->id;
@ -252,14 +250,13 @@ class quiz_match_qtype extends quiz_default_questiontype {
and $options->correct_responses
and isset($correctanswers[$subquestion->id])
and ($correctanswers[$subquestion->id] == $response)) {
$class = ' class="highlight" ';
$a->class = ' class="highlight" ';
} else {
$class = '';
$a->class = '';
}
echo "<td align=\"right\" valign=\"top\" $class>";
choose_from_menu($answers, $menuname, $response, 'choose', '', 0,
false, $options->readonly);
$a->control = choose_from_menu($answers, $menuname, $response, 'choose', '', 0,
true, $options->readonly);
// Neither the editing interface or the database allow to provide
// fedback for this question type.
@ -270,9 +267,10 @@ class quiz_match_qtype extends quiz_default_questiontype {
// && !empty($subquestion->options->answers[$responses[$key]]->feedback)) {
// quiz_print_comment($subquestion->options->answers[$responses[$key]]->feedback);
//}
echo '</td></tr>';
$anss[] = clone($a);
}
echo '</table>';
include("$CFG->dirroot/question/questiontypes/match/display.html");
}
function grade_responses(&$question, &$state, $cmoptions) {

View File

@ -273,54 +273,6 @@ class quiz_numerical_qtype extends quiz_shortanswer_qtype {
return false;
}
function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
/// This implementation is very similar to the code used by question type SHORTANSWER
$answers = &$question->options->answers;
$correctanswers = $this->get_correct_responses($question, $state);
$readonly = empty($options->readonly) ? '' : 'readonly="readonly"';
$nameprefix = $question->name_prefix;
/// Print question text and media
echo format_text($question->questiontext,
$question->questiontextformat,
NULL, $cmoptions->course);
quiz_print_possible_question_image($question, $cmoptions->course);
/// Print input controls
$stranswer = get_string("answer", "quiz");
if (isset($state->responses[''])) {
$value = ' value="'.htmlSpecialChars($state->responses['']).'" ';
} else {
$value = ' value="" ';
}
$inputname = ' name="'.$nameprefix.'" ';
echo "<p align=\"right\">$stranswer: <input type=\"text\" $readonly $inputname size=\"20\" $value /></p>";
if ($options->feedback) {
foreach($answers as $answer) {
if($this->test_response($question, $state, $answer)) {
quiz_print_comment($answer->feedback);
break;
}
}
}
if ($options->readonly && $options->correct_responses) {
$delimiter = '';
$correct = '';
if ($correctanswers) {
foreach ($correctanswers as $correctanswer) {
$correct .= $delimiter.$correctanswer;
$delimiter = ', ';
}
}
quiz_print_correctanswer($correct);
}
}
function grade_responses(&$question, &$state, $cmoptions) {
$answers = &$question->options->answers;
$state->raw_grade = 0;

View File

@ -444,14 +444,7 @@ class quiz_default_questiontype {
function print_question(&$question, &$state, $number, $cmoptions, $options) {
/* The default implementation should work for most question types
provided the member functions it calls are overridden where required.
The question number is printed in the first cell of a table.
The main content is printed below in the top row of the second column
using {@link print_question_formulation_and_controls}.
The grading details are printed in the second row in the second column
using {@print_question_grading_details}.
The {@link print_question_submit_buttons} member is invoked to add a third
row containing the submit button(s) when $options->readonly is false. */
The layout is determined by the template question.html */
global $CFG;
// For editing teachers print a link to an editing popup window
@ -728,6 +721,18 @@ class quiz_default_questiontype {
return $state->responses == $teststate->responses;
}
/**
* Checks whether a response matches a given answer
*
* This method only applies to questions that use teacher-defined answers
*
* @return boolean
*/
function test_response(&$question, &$state, $answer) {
$response = isset($state->responses['']) ? $state->responses[''] : '';
return ($response == $answer->answer);
}
/**
* Performs response processing and grading
*

View File

@ -327,6 +327,7 @@ class quiz_rqp_qtype extends quiz_default_questiontype {
// them yet.
// Remove the render output created during grading (if any)
unset($state->options->renderoutput);
$this->print_question_submit_buttons($question, $state, $cmoptions, $options);
}
/**

View File

@ -144,11 +144,8 @@ class quiz_shortanswer_qtype extends quiz_default_questiontype {
$feedback = '';
if ($options->feedback) {
$testedstate = clone($state);
$teststate = clone($state);
foreach($answers as $answer) {
$teststate->responses[''] = trim($answer->answer);
if($answer->feedback and $this->compare_responses($question, $testedstate, $teststate)) {
if($answer->feedback and $this->test_response($question, $state, $answer)) {
$feedback = format_text($answer->feedback, true, false);
break;
}