MDL-61364 question: add support for course tags on modal
[moodle.git] / question / classes / bank / tags_action_column.php
CommitLineData
d587dc6f
SL
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 * The question tags column subclass.
19 *
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
23 */
24namespace core_question\bank;
25
26defined('MOODLE_INTERNAL') || die();
27
28/**
29 * Action to add and remove tags to questions.
30 *
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
34 */
35class tags_action_column extends action_column_base {
36
37 /**
38 * Return the name for this column.
39 *
40 * @return string
41 */
42 public function get_name() {
43 return 'tagsaction';
44 }
45
46 /**
47 * Display tags column content.
48 *
49 * @param object $question The question database record.
50 * @param string $rowclasses
51 */
52 protected function display_content($question, $rowclasses) {
53 global $DB;
54
55 if (\core_tag_tag::is_enabled('core_question', 'question') &&
56 question_has_capability_on($question, 'view')) {
57
e2795e86 58 $cantag = question_has_capability_on($question, 'tag');
e6890b11
SL
59 $qbank = $this->qbank;
60 $url = $qbank->edit_question_url($question->id);
61 $editingcontext = $qbank->get_most_specific_context();
d587dc6f 62
e6890b11 63 $this->print_tag_icon($question->id, $url, $cantag, $editingcontext->id);
d587dc6f
SL
64 }
65 }
66
67 /**
68 * Build and print the tags icon.
69 *
70 * @param int $id The question ID.
71 * @param string $url Editing question url.
e2795e86 72 * @param bool $cantag Whether the user can tag questions or not.
d587dc6f
SL
73 * @param int $contextid Question category context ID.
74 */
e2795e86 75 protected function print_tag_icon($id, $url, $cantag, $contextid) {
d587dc6f
SL
76 global $OUTPUT;
77
78 $params = [
79 'data-action' => 'edittags',
e2795e86 80 'data-cantag' => $cantag,
d587dc6f
SL
81 'data-contextid' => $contextid,
82 'data-questionid' => $id
83 ];
84
85 echo \html_writer::link($url, $OUTPUT->pix_icon('t/tags', get_string('managetags', 'tag')), $params);
86 }
87}