Differences Between: [Versions 310 and 311]
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 * A question bank column showing the question name with idnumber and tags. 19 * 20 * @package core_question 21 * @copyright 2019 The Open University 22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 23 */ 24 25 namespace core_question\bank; 26 defined('MOODLE_INTERNAL') || die(); 27 28 29 /** 30 * A question bank column showing the question name with idnumber and tags. 31 * 32 * @copyright 2019 The Open University 33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 34 */ 35 class question_name_idnumber_tags_column extends question_name_column { 36 public function get_name() { 37 return 'qnameidnumbertags'; 38 } 39 40 protected function display_content($question, $rowclasses) { 41 global $OUTPUT; 42 43 $layoutclasses = 'd-inline-flex flex-nowrap overflow-hidden w-100'; 44 $labelfor = $this->label_for($question); 45 if ($labelfor) { 46 echo '<label for="' . $labelfor . '" class="' . $layoutclasses . '">'; 47 $closetag = '</label>'; 48 } else { 49 echo '<span class="' . $layoutclasses . '">'; 50 $closetag = '</span>'; 51 } 52 53 // Question name. 54 echo \html_writer::span(format_string($question->name), 'questionname flex-grow-1 flex-shrink-1 text-truncate'); 55 56 // Question idnumber. 57 if ($question->idnumber !== null && $question->idnumber !== '') { 58 echo ' ' . \html_writer::span( 59 \html_writer::span(get_string('idnumber', 'question'), 'accesshide') . ' ' . 60 \html_writer::span(s($question->idnumber), 'badge badge-primary'), 'ml-1'); 61 } 62 63 // Question tags. 64 if (!empty($question->tags)) { 65 $tags = \core_tag_tag::get_item_tags('core_question', 'question', $question->id); 66 echo $OUTPUT->tag_list($tags, null, 'd-inline flex-shrink-1 text-truncate ml-1', 0, null, true); 67 } 68 69 echo $closetag; // Computed above to ensure it matches. 70 } 71 72 public function get_required_fields() { 73 $fields = parent::get_required_fields(); 74 $fields[] = 'q.idnumber'; 75 return $fields; 76 } 77 78 public function is_sortable() { 79 return [ 80 'name' => ['field' => 'q.name', 'title' => get_string('questionname', 'question')], 81 'idnumber' => ['field' => 'q.idnumber', 'title' => get_string('idnumber', 'question')], 82 ]; 83 } 84 85 public function load_additional_data(array $questions) { 86 parent::load_additional_data($questions); 87 parent::load_question_tags($questions); 88 } 89 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body