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.
   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   * Class for question bank edit question column.
  19   *
  20   * @package   qbank_editquestion
  21   * @copyright 2009 Tim Hunt
  22   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  namespace qbank_editquestion;
  26  
  27  use core_question\local\bank\menu_action_column_base;
  28  use moodle_url;
  29  
  30  /**
  31   * Class for question bank edit question column.
  32   *
  33   * @copyright 2009 Tim Hunt
  34   * @author    2021 Safat Shahin <safatshahin@catalyst-au.net>
  35   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  36   */
  37  class edit_action_column extends menu_action_column_base {
  38  
  39      /**
  40       * Contains the string.
  41       * @var string
  42       */
  43      protected $stredit;
  44  
  45      /**
  46       * Contains the string.
  47       * @var string
  48       */
  49      protected $strview;
  50  
  51      /**
  52       * Contains the url of the edit question page.
  53       * @var moodle_url|string
  54       */
  55      public $editquestionurl;
  56  
  57      public function init(): void {
  58          parent::init();
  59          $this->stredit = get_string('editquestion', 'question');
  60          $this->strview = get_string('view');
  61          $this->editquestionurl = new \moodle_url('/question/bank/editquestion/question.php',
  62                  array('returnurl' => $this->qbank->returnurl));
  63          if ($this->qbank->cm !== null) {
  64              $this->editquestionurl->param('cmid', $this->qbank->cm->id);
  65          } else {
  66              $this->editquestionurl->param('courseid', $this->qbank->course->id);
  67          }
  68      }
  69  
  70      public function get_name() {
  71          return 'editaction';
  72      }
  73  
  74      /**
  75       * Get the URL for editing a question as a link.
  76       *
  77       * @param int $questionid the question id.
  78       * @return moodle_url the URL, HTML-escaped.
  79       */
  80      public function edit_question_moodle_url($questionid): moodle_url {
  81          return new moodle_url($this->editquestionurl, ['id' => $questionid]);
  82      }
  83  
  84      protected function get_url_icon_and_label(\stdClass $question): array {
  85          if (!\question_bank::is_qtype_installed($question->qtype)) {
  86              // It sometimes happens that people end up with junk questions
  87              // in their question bank of a type that is no longer installed.
  88              // We cannot do most actions on them, because that leads to errors.
  89              return [null, null, null];
  90          }
  91  
  92          if (question_has_capability_on($question, 'edit')) {
  93              return [$this->edit_question_moodle_url($question->id), 't/edit', $this->stredit];
  94          } else if (question_has_capability_on($question, 'view')) {
  95              return [$this->edit_question_moodle_url($question->id), 'i/info', $this->strview];
  96          } else {
  97              return [null, null, null];
  98          }
  99      }
 100  }