2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * The question tags column subclass.
20 * @package core_question
21 * @copyright 2018 Simey Lameze <simey@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24 namespace core_question\bank;
26 defined('MOODLE_INTERNAL') || die();
29 * Action to add and remove tags to questions.
31 * @package core_question
32 * @copyright 2018 Simey Lameze <simey@moodle.com>
33 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
35 class tags_action_column extends action_column_base {
38 * Return the name for this column.
42 public function get_name() {
47 * Display tags column content.
49 * @param object $question The question database record.
50 * @param string $rowclasses
52 protected function display_content($question, $rowclasses) {
55 if (\core_tag_tag::is_enabled('core_question', 'question') &&
56 question_has_capability_on($question, 'view')) {
58 $cantag = question_has_capability_on($question, 'tag');
59 $category = $DB->get_record('question_categories', ['id' => $question->category], 'contextid');
60 $url = $this->qbank->edit_question_url($question->id);
62 $this->print_tag_icon($question->id, $url, $cantag, $category->contextid);
67 * Build and print the tags icon.
69 * @param int $id The question ID.
70 * @param string $url Editing question url.
71 * @param bool $cantag Whether the user can tag questions or not.
72 * @param int $contextid Question category context ID.
74 protected function print_tag_icon($id, $url, $cantag, $contextid) {
78 'data-action' => 'edittags',
79 'data-cantag' => $cantag,
80 'data-contextid' => $contextid,
81 'data-questionid' => $id
84 echo \html_writer::link($url, $OUTPUT->pix_icon('t/tags', get_string('managetags', 'tag')), $params);