| Línea 29... |
Línea 29... |
| 29 |
require_once($CFG->libdir . '/tablelib.php');
|
29 |
require_once($CFG->libdir . '/tablelib.php');
|
| Línea 30... |
Línea 30... |
| 30 |
|
30 |
|
| Línea 31... |
Línea 31... |
| 31 |
admin_externalpage_setup('manageavailability');
|
31 |
admin_externalpage_setup('manageavailability');
|
| 32 |
|
32 |
|
| 33 |
// Get sorted list of all availability condition plugins.
|
33 |
// Get sorted list of all availability condition plugins.
|
| 34 |
$plugins = array();
|
34 |
$plugins = [];
|
| 35 |
foreach (core_component::get_plugin_list('availability') as $plugin => $plugindir) {
|
35 |
foreach (core_component::get_plugin_list('availability') as $plugin => $plugindir) {
|
| 36 |
if (get_string_manager()->string_exists('pluginname', 'availability_' . $plugin)) {
|
36 |
if (get_string_manager()->string_exists('pluginname', 'availability_' . $plugin)) {
|
| 37 |
$strpluginname = get_string('pluginname', 'availability_' . $plugin);
|
37 |
$strpluginname = get_string('pluginname', 'availability_' . $plugin);
|
| Línea 42... |
Línea 42... |
| 42 |
}
|
42 |
}
|
| 43 |
core_collator::asort($plugins);
|
43 |
core_collator::asort($plugins);
|
| Línea 44... |
Línea 44... |
| 44 |
|
44 |
|
| 45 |
// Do plugin actions.
|
45 |
// Do plugin actions.
|
| - |
|
46 |
$pageurl = new moodle_url('/' . $CFG->admin . '/tool/availabilityconditions/');
|
| 46 |
$pageurl = new moodle_url('/' . $CFG->admin . '/tool/availabilityconditions/');
|
47 |
$classavailability = \core_plugin_manager::resolve_plugininfo_class('availability');
|
| 47 |
if (($plugin = optional_param('plugin', '', PARAM_PLUGIN))) {
|
48 |
if (($plugin = optional_param('plugin', '', PARAM_PLUGIN))) {
|
| 48 |
require_sesskey();
|
49 |
require_sesskey();
|
| 49 |
if (!array_key_exists($plugin, $plugins)) {
|
50 |
if (!array_key_exists($plugin, $plugins)) {
|
| 50 |
throw new \moodle_exception('invalidcomponent', 'error', $pageurl);
|
51 |
throw new \moodle_exception('invalidcomponent', 'error', $pageurl);
|
| 51 |
}
|
52 |
}
|
| - |
|
53 |
$action = optional_param('action', '', PARAM_ALPHA);
|
| - |
|
54 |
if ($action === 'hide' && $classavailability::enable_plugin($plugin, 0)) {
|
| - |
|
55 |
\core\notification::add(
|
| - |
|
56 |
\core\notification::SUCCESS
|
| - |
|
57 |
);
|
| - |
|
58 |
} else if ($action === 'show' && $classavailability::enable_plugin($plugin, 1)) {
|
| - |
|
59 |
\core\notification::add(
|
| - |
|
60 |
\core\notification::SUCCESS
|
| - |
|
61 |
);
|
| - |
|
62 |
}
|
| - |
|
63 |
|
| 52 |
$action = required_param('action', PARAM_ALPHA);
|
64 |
$displaymode = optional_param('displaymode', '', PARAM_ALPHA);
|
| 53 |
switch ($action) {
|
65 |
switch ($displaymode) {
|
| 54 |
case 'hide' :
|
- |
|
| 55 |
$class = \core_plugin_manager::resolve_plugininfo_class('availability');
|
66 |
case 'hide' :
|
| 56 |
$class::enable_plugin($plugin, false);
|
67 |
$classavailability::update_display_mode($plugin, false);
|
| 57 |
break;
|
68 |
break;
|
| 58 |
case 'show' :
|
- |
|
| 59 |
$class = \core_plugin_manager::resolve_plugininfo_class('availability');
|
69 |
case 'show' :
|
| 60 |
$class::enable_plugin($plugin, true);
|
70 |
$classavailability::update_display_mode($plugin, true);
|
| 61 |
break;
|
71 |
break;
|
| Línea 62... |
Línea 72... |
| 62 |
}
|
72 |
}
|
| 63 |
|
73 |
|
| 64 |
// Always redirect back after an action.
|
74 |
// Always redirect back after an action.
|
| Línea 65... |
Línea 75... |
| 65 |
redirect($pageurl);
|
75 |
redirect($pageurl);
|
| 66 |
}
|
76 |
}
|
| Línea 67... |
Línea -... |
| 67 |
|
- |
|
| 68 |
echo $OUTPUT->header();
|
77 |
|
| 69 |
echo $OUTPUT->heading(get_string('manageplugins', 'availability'));
|
- |
|
| 70 |
|
- |
|
| 71 |
// Show a table of installed availability conditions.
|
- |
|
| 72 |
$table = new flexible_table('availabilityconditions_administration_table');
|
- |
|
| 73 |
$table->define_columns(array('name', 'version', 'enable'));
|
- |
|
| 74 |
$table->define_headers(array(get_string('plugin'),
|
- |
|
| 75 |
get_string('version'), get_string('hide') . '/' . get_string('show')));
|
78 |
echo $OUTPUT->header();
|
| 76 |
$table->define_baseurl($PAGE->url);
|
- |
|
| 77 |
$table->set_attribute('id', 'availabilityconditions');
|
- |
|
| 78 |
$table->set_attribute('class', 'admintable generaltable');
|
- |
|
| 79 |
$table->setup();
|
- |
|
| 80 |
|
- |
|
| 81 |
$enabledlist = core\plugininfo\availability::get_enabled_plugins();
|
- |
|
| 82 |
foreach ($plugins as $plugin => $name) {
|
- |
|
| 83 |
|
- |
|
| 84 |
// Get version or ? if unknown.
|
- |
|
| 85 |
$version = get_config('availability_' . $plugin);
|
- |
|
| 86 |
if (!empty($version->version)) {
|
- |
|
| 87 |
$version = $version->version;
|
- |
|
| 88 |
} else {
|
- |
|
| 89 |
$version = '?';
|
- |
|
| 90 |
}
|
- |
|
| 91 |
|
- |
|
| 92 |
// Get enabled status and use to grey out name if necessary.
|
- |
|
| 93 |
$enabled = in_array($plugin, $enabledlist);
|
- |
|
| 94 |
if ($enabled) {
|
- |
|
| 95 |
$enabledaction = 'hide';
|
- |
|
| 96 |
$enabledstr = get_string('hide');
|
- |
|
| 97 |
$class = '';
|
- |
|
| 98 |
} else {
|
- |
|
| 99 |
$enabledaction = 'show';
|
- |
|
| 100 |
$enabledstr = get_string('show');
|
- |
|
| 101 |
$class = 'dimmed_text';
|
- |
|
| 102 |
}
|
- |
|
| 103 |
|
- |
|
| 104 |
// Make enable control. This is a POST request (using a form control rather
|
- |
|
| 105 |
// than just a link) because it makes a database change.
|
- |
|
| 106 |
$params = array('sesskey' => sesskey(), 'plugin' => $plugin, 'action' => $enabledaction);
|
- |
|
| 107 |
$url = new moodle_url('/' . $CFG->admin . '/tool/availabilityconditions/', $params);
|
- |
|
| 108 |
$enablecontrol = html_writer::link($url, $OUTPUT->pix_icon('t/' . $enabledaction, $enabledstr));
|
- |
|
| 109 |
|
- |
|
| 110 |
$table->add_data([$name, $version, $enablecontrol], $class);
|
- |
|
| 111 |
}
|
79 |
echo $OUTPUT->heading(get_string('manageplugins', 'availability'));
|