-
Notifications
You must be signed in to change notification settings - Fork 4
/
learningtoolslist.php
139 lines (128 loc) · 5.9 KB
/
learningtoolslist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* List of the Available learningtools actions.
*
* @package local_learningtools
* @copyright bdecent GmbH 2021
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../../config.php');
require_once($CFG->libdir.'/tablelib.php');
require_login();
$context = context_system::instance();
$PAGE->set_context($context);
require_capability("moodle/site:config", $context);
$pageurl = new moodle_url("/local/learningtools/learningtoolslist.php");
$PAGE->set_url($pageurl);
$PAGE->set_pagelayout('admin');
$PAGE->set_title(get_string('learningtools', 'local_learningtools'));
$PAGE->set_heading(get_string('learningtools', 'local_learningtools'));
$action = optional_param('action', '', PARAM_ALPHANUMEXT);
$tool = optional_param('tool', '', PARAM_ALPHANUMEXT);
// Strings.
$strenable = get_string('enable');
$strdisable = get_string('disable');
$strup = get_string('up');
$strdown = get_string('down');
$strname = get_string('name');
$strversion = get_string('version');
$uninstallplug = get_string('uninstallplugin', 'core_admin');
$strname = get_string('name');
// Show/hide tools.
if (!empty($action) && !empty($tool)) {
require_sesskey();
if ($action == 'disable') {
$DB->set_field('local_learningtools_products', 'status', 0, array('shortname' => $tool));
} else if ($action == 'enable') {
$DB->set_field('local_learningtools_products', 'status', 1, array('shortname' => $tool));
} else if ($action == 'up') {
$curtool = $DB->get_record('local_learningtools_products', array('shortname' => $tool));
$prevtool = $DB->get_record('local_learningtools_products', array('sort' => $curtool->sort - 1));
$DB->set_field('local_learningtools_products', 'sort', $prevtool->sort, array('shortname' => $curtool->shortname));
$DB->set_field('local_learningtools_products', 'sort', $curtool->sort, array('shortname' => $prevtool->shortname));
} else if ($action = "down") {
$basetool = $DB->get_record('local_learningtools_products', array('shortname' => $tool));
$nexttool = $DB->get_record('local_learningtools_products', array('sort' => $basetool->sort + 1));
$DB->set_field('local_learningtools_products', 'sort', $nexttool->sort, array('shortname' => $basetool->shortname));
$DB->set_field('local_learningtools_products', 'sort', $basetool->sort, array('shortname' => $nexttool->shortname));
}
redirect($pageurl);
}
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('learningtools', 'local_learningtools'));
// Print the table of all installed ltools plugins.
$table = new flexible_table('learningtool_products_info');
$table->define_columns(array('name', 'version', 'status', 'updown', 'uninstall'));
$table->define_headers(array($strname, $strversion, $strenable.'/'.$strdisable,
$strup.'/'.$strdown, $uninstallplug));
$table->define_baseurl($PAGE->url);
$table->set_attribute('id', 'learningtool-products');
$table->set_attribute('class', 'learningtool generaltable');
$table->setup();
$plugins = array();
$pluginman = core_plugin_manager::instance();
$spacer = $OUTPUT->pix_icon('spacer', '', 'moodle', array('class' => 'iconsmall'));
$cnt = 0;
$learningtools = $DB->get_records('local_learningtools_products', null, 'sort');
foreach ($learningtools as $tool) {
$plugin = $tool->shortname;
$uninstall = '';
if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('ltool_'.$plugin, 'manage')) {
$uninstall = html_writer::link($uninstallurl, get_string('uninstallplugin', 'core_admin'));
}
// Plugin version.
$version = get_config('ltool_' . $plugin);
if (!empty($version->version)) {
$version = $version->version;
} else {
$version = '?';
}
// Plugin enable/disable.
$status = '-';
$lttool = $DB->get_record('local_learningtools_products', array('shortname' => $plugin));
if ($lttool->status) {
$aurl = new moodle_url($PAGE->url, array('action' => 'disable', 'tool' => $plugin, 'sesskey' => sesskey()));
$status = "<a href=\"$aurl\">";
$status .= $OUTPUT->pix_icon('t/hide', $strdisable) . '</a>';
$enabled = true;
} else {
$aurl = new moodle_url($PAGE->url, array('action' => 'enable', 'tool' => $plugin, 'sesskey' => sesskey()));
$status = "<a href=\"$aurl\">";
$status .= $OUTPUT->pix_icon('t/show', $strenable) . '</a>';
$enabled = false;
}
// Plugin sort option.
$updown = '';
if ($cnt) {
$updown .= html_writer::link($PAGE->url->out(false, array('action' => 'up', 'tool' => $plugin, 'sesskey' => sesskey())),
$OUTPUT->pix_icon('t/up', $strup, 'moodle', array('class' => 'iconsmall'))). '';
} else {
$updown .= $spacer;
}
if ($cnt < count($learningtools) - 1) {
$updown .= ' '.html_writer::link($PAGE->url->out(false, array('action' => 'down', 'tool' => $plugin,
'sesskey' => sesskey())),
$OUTPUT->pix_icon('t/down', $strdown, 'moodle', array('class' => 'iconsmall')));
} else {
$updown .= $spacer;
}
$cnt++;
$table->add_data(array($tool->name, $version, $status, $updown, $uninstall));
}
// Print the ltool plugins table.
$table->print_html();
echo $OUTPUT->footer();