MDL-62950 behat: Correct path to P&P
[moodle.git] / tag / classes / collections_table.php
blob5e6d23e30a6ba06a54146f9fdd8f5a9ae64a9dd9
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.
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/>.
17 /**
18 * Contains class core_tag_collections_table
20 * @package core_tag
21 * @copyright 2015 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 /**
28 * Table with the list of tag collections for "Manage tags" page.
30 * @package core_tag
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 {
36 /**
37 * Constructor
38 * @param string|moodle_url $pageurl
40 public function __construct($pageurl) {
41 global $OUTPUT;
42 parent::__construct();
44 $this->attributes['class'] = 'generaltable tag-collections-table';
46 $this->head = array(
47 get_string('name'),
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();
57 $idx = 0;
58 foreach ($tagcolls as $tagcoll) {
59 $actions = '';
60 $name = core_tag_collection::display_name($tagcoll);
61 $url = new moodle_url($pageurl, array('sesskey' => sesskey(), 'tc' => $tagcoll->id));
62 if (!$tagcoll->isdefault) {
63 // Move up.
64 if ($idx > 1) {
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'));
69 // Move down.
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)) {
77 // Delete.
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'));
83 $component = '';
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),
99 $component,
100 "<ul data-collectionid=\"{$tagcoll->id}\">" . join('', $areaslist) . '</ul>',
101 $searchable->render($OUTPUT),
102 $actions);
103 $idx++;