Search moodle.org's
Developer Documentation

See Release Notes
Long Term Support Release

  • Bug fixes for general core bugs in 4.1.x will end 13 November 2023 (12 months).
  • Bug fixes for security issues in 4.1.x will end 10 November 2025 (36 months).
  • PHP version: minimum PHP 7.4.0 Note: minimum PHP version has increased since Moodle 4.0. PHP 8.0.x is supported too.

Differences Between: [Versions 401 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_viewquestionname;
  18  
  19  use core_question\local\bank\column_base;
  20  
  21  
  22  /**
  23   * A column type for the name of the question name.
  24   *
  25   * @package   qbank_viewquestionname
  26   * @copyright 2009 Tim Hunt
  27   * @author    2021 Safat Shahin <safatshahin@catalyst-au.net>
  28   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  class viewquestionname_column_helper extends column_base {
  31  
  32      /**
  33       * @var null $checkboxespresent
  34       */
  35      protected $checkboxespresent = null;
  36  
  37      public function get_name(): string {
  38          return 'questionname';
  39      }
  40  
  41      public function get_title(): string {
  42          return get_string('question');
  43      }
  44  
  45      protected function label_for($question): string {
  46          if (is_null($this->checkboxespresent)) {
  47              $this->checkboxespresent = $this->qbank->has_column('checkbox_column');
  48          }
  49          if ($this->checkboxespresent) {
  50              return 'checkq' . $question->id;
  51          }
  52  
  53          return '';
  54      }
  55  
  56      protected function display_content($question, $rowclasses): void {
  57          $labelfor = $this->label_for($question);
  58          if ($labelfor) {
  59              echo \html_writer::start_tag('label', array('for' => $labelfor));
  60          }
  61          echo format_string($question->name);
  62          if ($labelfor) {
  63              echo \html_writer::end_tag('label');
  64          }
  65      }
  66  
  67      public function get_required_fields(): array {
  68          return ['q.id', 'q.name'];
  69      }
  70  
  71      public function is_sortable() {
  72          return 'q.name';
  73      }
  74  
  75  }