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\question_action_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 extends question_action_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 /** 71 * Get the URL for editing a question as a link. 72 * 73 * @param int $questionid the question id. 74 * @return moodle_url the URL, HTML-escaped. 75 */ 76 public function edit_question_moodle_url($questionid): moodle_url { 77 return new moodle_url($this->editquestionurl, ['id' => $questionid]); 78 } 79 80 protected function get_url_icon_and_label(\stdClass $question): array { 81 if (!\question_bank::is_qtype_installed($question->qtype)) { 82 // It sometimes happens that people end up with junk questions 83 // in their question bank of a type that is no longer installed. 84 // We cannot do most actions on them, because that leads to errors. 85 return [null, null, null]; 86 } 87 88 if (question_has_capability_on($question, 'edit')) { 89 return [$this->edit_question_moodle_url($question->id), 't/edit', $this->stredit]; 90 } else if (question_has_capability_on($question, 'view')) { 91 return [$this->edit_question_moodle_url($question->id), 'i/info', $this->strview]; 92 } else { 93 return [null, null, null]; 94 } 95 } 96 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body