Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/question/type/essay/question.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00027 defined('MOODLE_INTERNAL') || die();
00028 
00029 
00036 class qtype_essay_question extends question_with_responses {
00037     public $responseformat;
00038     public $responsefieldlines;
00039     public $attachments;
00040     public $graderinfo;
00041     public $graderinfoformat;
00042 
00043     public function make_behaviour(question_attempt $qa, $preferredbehaviour) {
00044         question_engine::load_behaviour_class('manualgraded');
00045         return new qbehaviour_manualgraded($qa, $preferredbehaviour);
00046     }
00047 
00052     public function get_format_renderer(moodle_page $page) {
00053         return $page->get_renderer('qtype_essay', 'format_' . $this->responseformat);
00054     }
00055 
00056     public function get_expected_data() {
00057         if ($this->responseformat == 'editorfilepicker') {
00058             $expecteddata = array('answer' => question_attempt::PARAM_CLEANHTML_FILES);
00059         } else {
00060             $expecteddata = array('answer' => PARAM_CLEANHTML);
00061         }
00062         $expecteddata['answerformat'] = PARAM_FORMAT;
00063         if ($this->attachments != 0) {
00064             $expecteddata['attachments'] = question_attempt::PARAM_FILES;
00065         }
00066         return $expecteddata;
00067     }
00068 
00069     public function summarise_response(array $response) {
00070         if (isset($response['answer'])) {
00071             $formatoptions = new stdClass();
00072             $formatoptions->para = false;
00073             return html_to_text(format_text(
00074                     $response['answer'], FORMAT_HTML, $formatoptions), 0, false);
00075         } else {
00076             return null;
00077         }
00078     }
00079 
00080     public function get_correct_response() {
00081         return null;
00082     }
00083 
00084     public function is_complete_response(array $response) {
00085         return !empty($response['answer']);
00086     }
00087 
00088     public function is_same_response(array $prevresponse, array $newresponse) {
00089         return question_utils::arrays_same_at_key_missing_is_blank(
00090                 $prevresponse, $newresponse, 'answer') && ($this->attachments == 0 ||
00091                 question_utils::arrays_same_at_key_missing_is_blank(
00092                 $prevresponse, $newresponse, 'attachments'));
00093     }
00094 
00095     public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) {
00096         if ($component == 'question' && $filearea == 'response_attachments') {
00097             // Response attachments visible if the question has them.
00098             return $this->attachments != 0;
00099 
00100         } else if ($component == 'question' && $filearea == 'response_answer') {
00101             // Response attachments visible if the question has them.
00102             return $this->responseformat === 'editorfilepicker';
00103 
00104         } else if ($component == 'qtype_essay' && $filearea == 'graderinfo') {
00105             return $options->manualcomment;
00106 
00107         } else {
00108             return parent::check_file_access($qa, $options, $component,
00109                     $filearea, $args, $forcedownload);
00110         }
00111     }
00112 }
 All Data Structures Namespaces Files Functions Variables Enumerations