qtype admin: MDL-16412 Enforce the allowed question types when a user tries to create...
[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;
e31a98a6 46 $isfinished = question_state_is_graded($state->last_graded) || $state->event == QUESTION_EVENTCLOSE;
37a12367 47
48 // For editing teachers print a link to an editing popup window
aafdb447 49 $editlink = $this->get_question_edit_link($question, $cmoptions, $options);
37a12367 50
b2ba9f6e 51 $questiontext = $this->format_text($question->questiontext, $question->questiontextformat, $cmoptions);
9fc3100f 52 $image = get_question_image($question);
37a12367 53
e31a98a6 54 $generalfeedback = '';
55 if ($isfinished && $options->generalfeedback) {
56 $generalfeedback = $this->format_text($question->generalfeedback,
57 $question->questiontextformat, $cmoptions);
58 }
59
aaae75b0 60 include "$CFG->dirroot/question/type/description/question.html";
516cf3eb 61 }
62
63 function actual_number_of_questions($question) {
64 /// Used for the feature number-of-questions-per-page
65 /// to determine the actual number of questions wrapped
66 /// by this question.
67 /// The question type description is not even a question
68 /// in itself so it will return ZERO!
69 return 0;
70 }
71
72 function grade_responses(&$question, &$state, $cmoptions) {
73 $state->raw_grade = 0;
74 $state->penalty = 0;
373f0afd 75 return true;
516cf3eb 76 }
77
78}
79//// END OF CLASS ////
80
81//////////////////////////////////////////////////////////////////////////
82//// INITIATION - Without this line the question type is not in use... ///
83//////////////////////////////////////////////////////////////////////////
a2156789 84question_register_questiontype(new description_qtype());
516cf3eb 85?>