MDL-50851 core_tag: introduce tag collections
[moodle.git] / tag / classes / areas_table.php
CommitLineData
c026a28d
MG
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 * Contains class core_tag_areas_table
19 *
20 * @package core_tag
21 * @copyright 2015 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25defined('MOODLE_INTERNAL') || die();
26
27/**
28 * Table with the list of available tag areas for "Manage tags" page.
29 *
30 * @package core_tag
31 * @copyright 2015 Marina Glancy
32 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
33 */
34class core_tag_areas_table extends html_table {
35
36 /**
37 * Constructor
38 *
39 * @param string|moodle_url $pageurl
40 */
41 public function __construct($pageurl) {
42 global $OUTPUT;
43 parent::__construct();
44
45 $this->attributes['class'] = 'generaltable tag-areas-table';
46
47 $this->head = array(
48 get_string('tagareaname', 'core_tag'),
49 get_string('component', 'tag'),
50 get_string('tagareaenabled', 'core_tag'),
51 get_string('tagcollection', 'tag'),
52 );
53
54 $this->data = array();
55 $this->rowclasses = array();
56
57 $tagareas = core_tag_area::get_areas();
58 $tagcollections = core_tag_collection::get_collections_menu(true);
59 $tagcollectionsall = core_tag_collection::get_collections_menu();
60
61 foreach ($tagareas as $itemtype => $it) {
62 foreach ($it as $component => $record) {
63 $areaname = core_tag_area::display_name($record->component, $record->itemtype);
64 $baseurl = new moodle_url($pageurl, array('ta' => $record->id, 'sesskey' => sesskey()));
65 if ($record->enabled) {
66 $enableurl = new moodle_url($baseurl, array('action' => 'areadisable'));
67 $enabled = html_writer::link($enableurl, $OUTPUT->pix_icon('i/hide', get_string('disable')));
68 } else {
69 $enableurl = new moodle_url($baseurl, array('action' => 'areaenable'));
70 $enabled = html_writer::link($enableurl, $OUTPUT->pix_icon('i/show', get_string('enable')));
71 }
72
73 if ($record->enabled && empty($record->locked) && count($tagcollections) > 1) {
74 $changecollurl = new moodle_url($baseurl, array('action' => 'areasetcoll'));
75
76 $select = new single_select($changecollurl, 'areacollid', $tagcollections, $record->tagcollid, null);
77 $select->set_label(get_string('changetagcoll', 'core_tag', $areaname), array('class' => 'accesshide'));
78 $collectionselect = $OUTPUT->render($select);
79 } else {
80 $collectionselect = $tagcollectionsall[$record->tagcollid];
81 }
82 $this->data[] = array(
83 $areaname,
84 ($record->component === 'core' || preg_match('/^core_/', $record->component)) ?
85 get_string('coresystem') : get_string('pluginname', $record->component),
86 $enabled,
87 $collectionselect
88 );
89 $this->rowclasses[] = $record->enabled ? '' : 'dimmed_text';
90 }
91 }
92
93 }
94
95}