First steps towards separating logic and layout in the printing of questions: the print_question() method in the default question type now uses the template question.html

This commit is contained in:
gustav_delius
2006-02-18 17:32:56 +00:00
parent 7aa42eb0c8
commit 7f65c565be
3 changed files with 95 additions and 46 deletions
+28 -1
View File
@@ -833,6 +833,34 @@ function quiz_print_question_icon($question, $editlink=true, $return = false) {
}
/**
* Returns a html link to the question image if there is one
*
* @return string The html image tag or the empy string if there is no image.
* @param object $question The question object
*/
function quiz_get_image($question, $courseid) {
global $CFG;
$img = '';
if ($question->image) {
$img .= '<img border="0" src="';
if (substr(strtolower($question->image), 0, 7) == 'http://') {
$img .= $question->image;
} else if ($CFG->slasharguments) { // Use this method if possible for better caching
$img .= "$CFG->wwwroot/file.php/$courseid/$question->image";
} else {
$img .= "$CFG->wwwroot/file.php?file=$courseid/$question->image";
}
$img .= '" alt="" />';
}
return $img;
}
/**
* Print the question image if there is one
*
@@ -859,7 +887,6 @@ function quiz_print_possible_question_image($question, $courseid) {
}
}
/**
* Construct name prefixes for question form element names
*
+45
View File
@@ -0,0 +1,45 @@
<?php
/* The question number is printed in the first column of a table.
* The main content is printed in the second column in the following order
* question text
* answer controls and feedback
* grading details
* submit button
* session history
*/
print_simple_box_start('center', '90%');
?>
<table width="100%" cellspacing="10">
<tr>
<!-- The first column spans all rows and contains the question number
and score -->
<td nowrap="nowrap" width="80" valign="top">
<b><font size="+1"><?php echo $q->number; ?></font></b>
<?php echo $q->editlink; ?>
<?php if ($q->marks) { ?>
<div class="grade">
<?php print_string('marks', 'quiz'); ?>:
<br />
<?php echo $q->marks; ?>
</div>
<?php } ?>
</td>
<!-- The second column contains the main content -->
<td valign="top">
<div>
<?php $this->print_question_formulation_and_controls($question, $state, $cmoptions, $options); ?>
</div>
<div>
<?php $this->print_question_grading_details($question, $state, $cmoptions, $options); ?>
</div>
<div align="right">
<?php $this->print_question_submit_buttons($question, $state, $cmoptions, $options); ?>
</div>
<div>
<?php echo $q->history; ?>
</div>
</td>
</tr>
</table>
<?php print_simple_box_end(); ?>
+22 -45
View File
@@ -452,55 +452,30 @@ class quiz_default_questiontype {
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. */
print_simple_box_start('center', '90%');
echo '<table width="100%" cellspacing="10"><tr>';
if ($options->readonly) {
echo '<td nowrap="nowrap" width="80" valign="top" rowspan="2">';
} else {
echo '<td nowrap="nowrap" width="80" valign="top" rowspan="3">';
}
global $CFG;
// Print question number
echo '<b><font size="+1">' . $number . '</font></b>';
if (isteacher($cmoptions->course)) {
echo '<br /><font size="1">';
link_to_popup_window ('/mod/quiz/question.php?id=' . $question->id,
'editquestion', get_string('edit'), 450, 550, get_string('edit'));
echo '</font>';
$q->number = $number;
// For editing teachers print a link to an editing popup window
$q->editlink = '';
if (isteacheredit($cmoptions->course)) {
$stredit = get_string('edit');
$linktext = '<img src="'.$CFG->pixpath.'/t/edit.gif" border="0" alt="'.$stredit.'" />';
$q->editlink = link_to_popup_window('/mod/quiz/question.php?id='.$question->id, $stredit, $linktext, 450, 550, $stredit, '', true);
}
$q->strmarks = '';
$q->marks = '';
if ($question->maxgrade and $options->scores) {
echo '<div class="grade">';
echo get_string('marks', 'quiz').': ';
$q->strmarks .= get_string('marks', 'quiz').': ';
if ($cmoptions->optionflags & QUIZ_ADAPTIVE) {
echo '<br />';
echo ('' === $state->last_graded->grade) ? '--/' : round($state->last_graded->grade, $cmoptions->decimalpoints).'/';
$q->marks = ('' === $state->last_graded->grade) ? '--/' : round($state->last_graded->grade, $cmoptions->decimalpoints).'/';
}
echo $question->maxgrade.'</div>';
}
echo '</td><td valign="top">';
$this->print_question_formulation_and_controls($question, $state,
$cmoptions, $options);
echo '</td></tr><tr><td valign="top">';
if ($question->maxgrade and $options->scores) {
$this->print_question_grading_details($question, $state, $cmoptions, $options);
}
if (QUIZ_EVENTDUPLICATEGRADE == $state->event) {
echo ' ';
print_string('duplicateresponse', 'quiz');
}
if(!$options->readonly) {
echo '</td></tr><tr><td align="right">';
$this->print_question_submit_buttons($question, $state,
$cmoptions, $options);
$q->marks .= $question->maxgrade;
}
$q->history = '';
if(isset($options->history) and $options->history) {
if ($options->history == 'all') {
// show all states
@@ -537,12 +512,10 @@ class quiz_default_questiontype {
$b.round($st->grade, $cmoptions->decimalpoints).$be
);
}
echo '</td></tr><tr><td colspan="2" valign="top">';
print_table($table);
$q->history = make_table($table);
}
}
echo '</td></tr></table>';
print_simple_box_end();
include "$CFG->dirroot/mod/quiz/questiontypes/question.html";
}
@@ -570,6 +543,10 @@ class quiz_default_questiontype {
attempt and displays the overall grade obtained counting all previous
responses (and penalties) */
if (QUIZ_EVENTDUPLICATEGRADE == $state->event) {
echo ' ';
print_string('duplicateresponse', 'quiz');
}
if (!empty($question->maxgrade) && $options->scores) {
if (!('' === $state->last_graded->grade)) {
// Display the grading details from the last graded state