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 $qbank = $this->qbank;
60 $url = $qbank->edit_question_url($question->id);
61 $editingcontext = $qbank->get_most_specific_context();
63 $this->print_tag_icon($question->id, $url, $cantag, $editingcontext->id);
68 * Build and print the tags icon.
70 * @param int $id The question ID.
71 * @param string $url Editing question url.
72 * @param bool $cantag Whether the user can tag questions or not.
73 * @param int $contextid Question category context ID.
75 protected function print_tag_icon($id, $url, $cantag, $contextid) {
79 'data-action' => 'edittags',
80 'data-cantag' => $cantag,
81 'data-contextid' => $contextid,
82 'data-questionid' => $id
85 echo \html_writer::link($url, $OUTPUT->pix_icon('t/tags', get_string('managetags', 'tag')), $params);