Differences Between: [Versions 400 and 403] [Versions 401 and 403] [Versions 402 and 403]
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 namespace qbank_viewquestiontext; 18 19 use core_question\local\bank\row_base; 20 use qbank_viewquestiontext\output\question_text_format; 21 use question_utils; 22 23 /** 24 * A column type for the name of the question name. 25 * 26 * @package qbank_viewquestiontext 27 * @copyright 2009 Tim Hunt 28 * @author 2021 Safat Shahin <safatshahin@catalyst-au.net> 29 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 30 */ 31 class question_text_row extends row_base { 32 33 /** @var int if true, we will show the question text reduced to plain text, else it is fully rendered. */ 34 protected $preference; 35 36 /** @var \stdClass $formatoptions options used when displaying the question text as HTML. */ 37 protected $formatoptions; 38 39 protected function init(): void { 40 41 // Cannot use $this->get_preference because of PHP type hints. 42 $this->preference = (int)question_get_display_preference($this->get_preference_key(), 0, PARAM_INT, new \moodle_url('')); 43 $this->formatoptions = new \stdClass(); 44 $this->formatoptions->noclean = true; 45 $this->formatoptions->para = false; 46 } 47 48 public function get_name(): string { 49 return 'questiontext'; 50 } 51 52 public function get_title(): string { 53 return get_string('questiontext', 'question'); 54 } 55 56 protected function display_content($question, $rowclasses): void { 57 // Access 'showtext' filter from pagevars. 58 if ($this->preference !== question_text_format::OFF) { 59 $text = ''; 60 if ($this->preference === question_text_format::PLAIN) { 61 $text = question_utils::to_plain_text($question->questiontext, 62 $question->questiontextformat, ['noclean' => true, 'para' => false, 'filter' => false]); 63 } else if ($this->preference === question_text_format::FULL) { 64 $text = question_rewrite_question_preview_urls($question->questiontext, $question->id, 65 $question->contextid, 'question', 'questiontext', $question->id, 66 $question->contextid, 'core_question'); 67 $text = format_text($text, $question->questiontextformat, 68 $this->formatoptions); 69 } 70 if ($text == '') { 71 $text = ' '; 72 } 73 echo $text; 74 } 75 } 76 77 public function get_required_fields(): array { 78 return ['q.questiontext', 'q.questiontextformat']; 79 } 80 81 public function has_preference(): bool { 82 return false; 83 } 84 85 public function get_preference_key(): string { 86 return 'qbshowtext'; 87 } 88 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body