From 7f65c565be4e3dd4fd26c13179e8041bce27b500 Mon Sep 17 00:00:00 2001 From: gustav_delius Date: Sat, 18 Feb 2006 17:32:56 +0000 Subject: [PATCH] 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 --- mod/quiz/questionlib.php | 29 ++++++++++- mod/quiz/questiontypes/question.html | 45 +++++++++++++++++ mod/quiz/questiontypes/questiontype.php | 67 ++++++++----------------- 3 files changed, 95 insertions(+), 46 deletions(-) create mode 100644 mod/quiz/questiontypes/question.html diff --git a/mod/quiz/questionlib.php b/mod/quiz/questionlib.php index a0dc16549ec..fca725dedea 100644 --- a/mod/quiz/questionlib.php +++ b/mod/quiz/questionlib.php @@ -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 .= '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 * diff --git a/mod/quiz/questiontypes/question.html b/mod/quiz/questiontypes/question.html new file mode 100644 index 00000000000..953559f6318 --- /dev/null +++ b/mod/quiz/questiontypes/question.html @@ -0,0 +1,45 @@ + + + + + + + + + +
+ number; ?> + editlink; ?> + marks) { ?> +
+ : +
+ marks; ?> +
+ +
+
+ print_question_formulation_and_controls($question, $state, $cmoptions, $options); ?> +
+
+ print_question_grading_details($question, $state, $cmoptions, $options); ?> +
+
+ print_question_submit_buttons($question, $state, $cmoptions, $options); ?> +
+
+ history; ?> +
+
+ \ No newline at end of file diff --git a/mod/quiz/questiontypes/questiontype.php b/mod/quiz/questiontypes/questiontype.php index 944d6b2dd57..e7ff791b979 100644 --- a/mod/quiz/questiontypes/questiontype.php +++ b/mod/quiz/questiontypes/questiontype.php @@ -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 ''; - if ($options->readonly) { - echo '
'; - } else { - echo ''; - } + global $CFG; // Print question number - echo '' . $number . ''; - if (isteacher($cmoptions->course)) { - echo '
'; - link_to_popup_window ('/mod/quiz/question.php?id=' . $question->id, - 'editquestion', get_string('edit'), 450, 550, get_string('edit')); - echo ''; + $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 = ''.$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 '
'; - echo get_string('marks', 'quiz').': '; + $q->strmarks .= get_string('marks', 'quiz').': '; if ($cmoptions->optionflags & QUIZ_ADAPTIVE) { - echo '
'; - 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.'
'; - } - - echo '
'; - - $this->print_question_formulation_and_controls($question, $state, - $cmoptions, $options); - - echo '
'; - - 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 '
'; - $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 '
'; - print_table($table); + $q->history = make_table($table); } } - echo '
'; - 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