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')));
69 if ($idx < count($tagcolls) - 1) {
70 $url->param('action', 'collmovedown');
71 $actions .= $OUTPUT->action_icon($url, new pix_icon('t/down', get_string('movedown')));
74 if (empty($tagcoll->component)) {
76 $url->param('action', 'colledit');
77 $actions .= $OUTPUT->action_icon($url, new pix_icon('t/edit', get_string('edittagcoll', 'tag', $name)));
79 if (!$tagcoll->isdefault && empty($tagcoll->component)) {
81 $url->param('action', 'colldelete');
82 $actions .= $OUTPUT->action_icon($url, new pix_icon('t/delete', get_string('delete')));
84 $manageurl = new moodle_url('/tag/manage.php', array('tc' => $tagcoll->id));
86 if ($tagcoll->component) {
87 $component = ($tagcoll->component === 'core' || preg_match('/^core_/', $tagcoll->component)) ?
88 get_string('coresystem') : get_string('pluginname', $tagcoll->component);
90 $allareas = core_tag_collection::get_areas_names(null, false);
91 $validareas = core_tag_collection::get_areas_names($tagcoll->id);
92 $areaslist = array_map(function($key) use ($allareas, $validareas) {
93 return "<li data-areaid=\"{$key}\" " .
94 (array_key_exists($key, $validareas) ? "" : "class=\"hidden\"") .
95 ">{$allareas[$key]}</li>";
96 }, array_keys($allareas));
97 $this->data[] = array(
98 html_writer::link($manageurl, $name),
100 "<ul data-collectionid=\"{$tagcoll->id}\">" . join('', $areaslist) . '</ul>',
101 $tagcoll->searchable ? get_string('yes') : '-',