MDL-14363 - Fix a broken redirect from mod/quiz/ attempt.php to edit.php when the...
[moodle.git] / question / type / description / questiontype.php
CommitLineData
516cf3eb 1<?php // $Id$
2
3///////////////////
4/// DESCRIPTION ///
5///////////////////
6
7/// QUESTION TYPE CLASS //////////////////
8
9//
dfa47f96 10// The question type 'description' is not really a question type
516cf3eb 11// and it therefore often sticks to some kind of odd behaviour
12//
1976496e 13/**
14 * @package questionbank
15 * @subpackage questiontypes
7375c542 16 */
7518b645 17class description_qtype extends default_questiontype {
516cf3eb 18
19 function name() {
20 return 'description';
21 }
271e6dec 22
a2156789 23 function is_usable_by_random() {
24 return false;
25 }
516cf3eb 26
bfbafdfe 27 function save_question($question, $form, $course) {
28 // Make very sure that descriptions can'e be created with a grade of
29 // anything other than 0.
30 $form->defaultgrade = 0;
31 return parent::save_question($question, $form, $course);
32 }
33
516cf3eb 34 function get_question_options(&$question) {
35 // No options to be restored for this question type
36 return true;
37 }
38
39 function save_question_options($question) {
40 /// No options to be saved for this question type:
41 return true;
42 }
43
44 function print_question(&$question, &$state, $number, $cmoptions, $options) {
37a12367 45 global $CFG;
46
e7e62d45 47 if (!empty($cmoptions->id)) {
48 $cm = get_coursemodule_from_instance('quiz', $cmoptions->id);
49 $cmorcourseid = '&amp;cmid='.$cm->id;
50 } else if (!empty($cmoptions->course)) {
51 $cmorcourseid = '&amp;courseid='.$cmoptions->course;
52 } else {
5a2a5331 53 print_error('Need to provide courseid or cmid to print_question.');
e7e62d45 54 }
55
37a12367 56 // For editing teachers print a link to an editing popup window
096d42f4 57 $editlink = '';
271e6dec 58 if (question_has_capability_on($question, 'edit')) {
37a12367 59 $stredit = get_string('edit');
0fd5feef 60 $linktext = '<img src="'.$CFG->pixpath.'/t/edit.gif" alt="'.$stredit.'" />';
e7e62d45 61 $editlink = link_to_popup_window('/question/question.php?id='.$question->id.$cmorcourseid,
62 $stredit, $linktext, 450, 550, $stredit, '', true);
37a12367 63 }
64
b2ba9f6e 65 $questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions);
9fc3100f 66 $image = get_question_image($question);
37a12367 67
aaae75b0 68 include "$CFG->dirroot/question/type/description/question.html";
516cf3eb 69 }
70
71 function actual_number_of_questions($question) {
72 /// Used for the feature number-of-questions-per-page
73 /// to determine the actual number of questions wrapped
74 /// by this question.
75 /// The question type description is not even a question
76 /// in itself so it will return ZERO!
77 return 0;
78 }
79
80 function grade_responses(&$question, &$state, $cmoptions) {
81 $state->raw_grade = 0;
82 $state->penalty = 0;
83 }
84
85}
86//// END OF CLASS ////
87
88//////////////////////////////////////////////////////////////////////////
89//// INITIATION - Without this line the question type is not in use... ///
90//////////////////////////////////////////////////////////////////////////
a2156789 91question_register_questiontype(new description_qtype());
516cf3eb 92?>