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 * Contains class core_tag_collections_table
21 * @copyright 2015 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
28 * Table with the list of tag collections for "Manage tags" page.
31 * @copyright 2015 Marina Glancy
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
34 class core_tag_collections_table
extends html_table
{
38 * @param string|moodle_url $pageurl
40 public function __construct($pageurl) {
42 parent
::__construct();
44 $this->attributes
['class'] = 'generaltable tag-collections-table';
48 get_string('component', 'tag'),
49 get_string('tagareas', 'tag'),
50 get_string('searchable', 'tag') . $OUTPUT->help_icon('searchable', 'tag'),
54 $this->data
= array();
56 $tagcolls = core_tag_collection
::get_collections();
58 foreach ($tagcolls as $tagcoll) {
60 $name = core_tag_collection
::display_name($tagcoll);
61 $url = new moodle_url($pageurl, array('sesskey' => sesskey(), 'tc' => $tagcoll->id
));
62 if (!$tagcoll->isdefault
) {
65 $url->param('action', 'collmoveup');
66 $actions .= $OUTPUT->action_icon($url, new pix_icon('t/up', get_string('moveup')), null,
67 array('class' => 'action-icon action_moveup'));
70 if ($idx < count($tagcolls) - 1) {
71 $url->param('action', 'collmovedown');
72 $actions .= $OUTPUT->action_icon($url, new pix_icon('t/down', get_string('movedown')), null,
73 array('class' => 'action-icon action_movedown'));
76 if (!$tagcoll->isdefault
&& empty($tagcoll->component
)) {
78 $url->param('action', 'colldelete');
79 $actions .= $OUTPUT->action_icon('#', new pix_icon('t/delete', get_string('delete')), null,
80 array('data-url' => $url->out(false), 'data-collname' => $name,
81 'class' => 'action-icon action_delete'));
84 if ($tagcoll->component
) {
85 $component = ($tagcoll->component
=== 'core' ||
preg_match('/^core_/', $tagcoll->component
)) ?
86 get_string('coresystem') : get_string('pluginname', $tagcoll->component
);
88 $allareas = core_tag_collection
::get_areas_names(null, false);
89 $validareas = core_tag_collection
::get_areas_names($tagcoll->id
);
90 $areaslist = array_map(function($key) use ($allareas, $validareas) {
91 return "<li data-areaid=\"{$key}\" " .
92 (array_key_exists($key, $validareas) ?
"" : "style=\"display:none;\"") .
93 ">{$allareas[$key]}</li>";
94 }, array_keys($allareas));
95 $displayname = new \core_tag\output\tagcollname
($tagcoll);
96 $searchable = new \core_tag\output\tagcollsearchable
($tagcoll);
97 $this->data
[] = array(
98 $displayname->render($OUTPUT),
100 "<ul data-collectionid=\"{$tagcoll->id}\">" . join('', $areaslist) . '</ul>',
101 $searchable->render($OUTPUT),