[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * Essay question definition class. 19 * 20 * @package qtype 21 * @subpackage essay 22 * @copyright 2009 The Open University 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 27 defined('MOODLE_INTERNAL') || die(); 28 29 30 /** 31 * Represents an essay question. 32 * 33 * @copyright 2009 The Open University 34 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 35 */ 36 class qtype_essay_question extends question_with_responses { 37 38 public $responseformat; 39 40 /** @var int Indicates whether an inline response is required ('0') or optional ('1') */ 41 public $responserequired; 42 43 public $responsefieldlines; 44 public $attachments; 45 46 /** @var int The number of attachments required for a response to be complete. */ 47 public $attachmentsrequired; 48 49 public $graderinfo; 50 public $graderinfoformat; 51 public $responsetemplate; 52 public $responsetemplateformat; 53 54 public function make_behaviour(question_attempt $qa, $preferredbehaviour) { 55 return question_engine::make_behaviour('manualgraded', $qa, $preferredbehaviour); 56 } 57 58 /** 59 * @param moodle_page the page we are outputting to. 60 * @return qtype_essay_format_renderer_base the response-format-specific renderer. 61 */ 62 public function get_format_renderer(moodle_page $page) { 63 return $page->get_renderer('qtype_essay', 'format_' . $this->responseformat); 64 } 65 66 public function get_expected_data() { 67 if ($this->responseformat == 'editorfilepicker') { 68 $expecteddata = array('answer' => question_attempt::PARAM_RAW_FILES); 69 } else { 70 $expecteddata = array('answer' => PARAM_RAW); 71 } 72 $expecteddata['answerformat'] = PARAM_ALPHANUMEXT; 73 if ($this->attachments != 0) { 74 $expecteddata['attachments'] = question_attempt::PARAM_FILES; 75 } 76 return $expecteddata; 77 } 78 79 public function summarise_response(array $response) { 80 if (isset($response['answer'])) { 81 return question_utils::to_plain_text($response['answer'], 82 $response['answerformat'], array('para' => false)); 83 } else { 84 return null; 85 } 86 } 87 88 public function get_correct_response() { 89 return null; 90 } 91 92 public function is_complete_response(array $response) { 93 // Determine if the given response has inline text and attachments. 94 $hasinlinetext = array_key_exists('answer', $response) && ($response['answer'] !== ''); 95 $hasattachments = array_key_exists('attachments', $response) 96 && $response['attachments'] instanceof question_response_files; 97 98 // Determine the number of attachments present. 99 if ($hasattachments) { 100 $attachcount = count($response['attachments']->get_files()); 101 } else { 102 $attachcount = 0; 103 } 104 105 // Determine if we have /some/ content to be graded. 106 $hascontent = $hasinlinetext || ($attachcount > 0); 107 108 // Determine if we meet the optional requirements. 109 $meetsinlinereq = $hasinlinetext || (!$this->responserequired) || ($this->responseformat == 'noinline'); 110 $meetsattachmentreq = ($attachcount >= $this->attachmentsrequired); 111 112 // The response is complete iff all of our requirements are met. 113 return $hascontent && $meetsinlinereq && $meetsattachmentreq; 114 } 115 116 public function is_same_response(array $prevresponse, array $newresponse) { 117 if (array_key_exists('answer', $prevresponse) && $prevresponse['answer'] !== $this->responsetemplate) { 118 $value1 = (string) $prevresponse['answer']; 119 } else { 120 $value1 = ''; 121 } 122 if (array_key_exists('answer', $newresponse) && $newresponse['answer'] !== $this->responsetemplate) { 123 $value2 = (string) $newresponse['answer']; 124 } else { 125 $value2 = ''; 126 } 127 return $value1 === $value2 && ($this->attachments == 0 || 128 question_utils::arrays_same_at_key_missing_is_blank( 129 $prevresponse, $newresponse, 'attachments')); 130 } 131 132 public function check_file_access($qa, $options, $component, $filearea, $args, $forcedownload) { 133 if ($component == 'question' && $filearea == 'response_attachments') { 134 // Response attachments visible if the question has them. 135 return $this->attachments != 0; 136 137 } else if ($component == 'question' && $filearea == 'response_answer') { 138 // Response attachments visible if the question has them. 139 return $this->responseformat === 'editorfilepicker'; 140 141 } else if ($component == 'qtype_essay' && $filearea == 'graderinfo') { 142 return $options->manualcomment; 143 144 } else { 145 return parent::check_file_access($qa, $options, $component, 146 $filearea, $args, $forcedownload); 147 } 148 } 149 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |