Skip to content

Commit

Permalink
Merge branch 'MDL-77248-master' of https://github.com/andrewnicols/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Feb 28, 2023
2 parents 855cc8c + 36b69bb commit 946a88c
Show file tree
Hide file tree
Showing 11 changed files with 252 additions and 315 deletions.
292 changes: 152 additions & 140 deletions admin/modules.php
@@ -1,151 +1,163 @@
<?php
// Allows the admin to manage activity modules

require_once('../config.php');
require_once('../course/lib.php');
require_once($CFG->libdir.'/adminlib.php');
require_once($CFG->libdir.'/tablelib.php');

// defines
define('MODULE_TABLE','module_administration_table');

admin_externalpage_setup('managemodules');

$show = optional_param('show', '', PARAM_PLUGIN);
$hide = optional_param('hide', '', PARAM_PLUGIN);


/// Print headings

$stractivities = get_string("activities");
$struninstall = get_string('uninstallplugin', 'core_admin');
$strversion = get_string("version");
$strhide = get_string("hide");
$strshow = get_string("show");
$strsettings = get_string("settings");
$stractivities = get_string("activities");
$stractivitymodule = get_string("activitymodule");
$strshowmodulecourse = get_string('showmodulecourse');

/// If data submitted, then process and store.

if (!empty($hide) and confirm_sesskey()) {
$class = \core_plugin_manager::resolve_plugininfo_class('mod');
$class::enable_plugin($hide, false);

admin_get_root(true, false); // settings not required - only pages
redirect(new moodle_url('/admin/modules.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/>.

/**
* A page to manage activity modules.
*
* @package core_admin
* @copyright 2023 Andrew Lyons <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/

require_once('../config.php');
require_once('../course/lib.php');
require_once("{$CFG->libdir}/adminlib.php");
require_once("{$CFG->libdir}/tablelib.php");

define('MODULE_TABLE', 'module_administration_table');

admin_externalpage_setup('managemodules');

$show = optional_param('show', '', PARAM_PLUGIN);
$hide = optional_param('hide', '', PARAM_PLUGIN);

// Print headings.
$stractivities = get_string("activities");
$struninstall = get_string('uninstallplugin', 'core_admin');
$strversion = get_string("version");
$strhide = get_string("hide");
$strshow = get_string("show");
$strsettings = get_string("settings");
$stractivities = get_string("activities");
$stractivitymodule = get_string("activitymodule");
$strshowmodulecourse = get_string('showmodulecourse');

// If data submitted, then process and store.
if (!empty($hide) && confirm_sesskey()) {
$class = \core_plugin_manager::resolve_plugininfo_class('mod');
if ($class::enable_plugin($hide, false)) {
// Settings not required - only pages.
admin_get_root(true, false);
}

if (!empty($show) and confirm_sesskey()) {
$canenablemodule = true;
$modulename = $show;

// Invoking a callback function that enables plugins to force additional actions (e.g. displaying notifications,
// modals, etc.) and also specify through its returned value (bool) whether the process of enabling the plugin
// should continue after these actions or not.
if (component_callback_exists("mod_{$modulename}", 'pre_enable_plugin_actions')) {
$canenablemodule = component_callback("mod_{$modulename}", 'pre_enable_plugin_actions');
}

if ($canenablemodule) {
$class = \core_plugin_manager::resolve_plugininfo_class('mod');
$class::enable_plugin($show, true);
admin_get_root(true, false); // Settings not required - only pages.
redirect(new moodle_url('/admin/modules.php'));
}
redirect(new moodle_url('/admin/modules.php'));
}

if (!empty($show) && confirm_sesskey()) {
$class = \core_plugin_manager::resolve_plugininfo_class('mod');
if ($class::enable_plugin($show, true)) {
// Settings not required - only pages.
admin_get_root(true, false);
}
redirect(new moodle_url('/admin/modules.php'));
}

echo $OUTPUT->header();
echo $OUTPUT->heading($stractivities);

// Get and sort the existing modules.
if (!$modules = $DB->get_records('modules', [], 'name ASC')) {
throw new \moodle_exception('moduledoesnotexist', 'error');
}

// Print the table of all modules.
// Construct the flexible table ready to display.
$table = new flexible_table(MODULE_TABLE);
$table->define_columns(['name', 'instances', 'version', 'hideshow', 'uninstall', 'settings']);
$table->define_headers([$stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall]);
$table->define_baseurl($CFG->wwwroot . '/' . $CFG->admin . '/modules.php');
$table->set_attribute('id', 'modules');
$table->set_attribute('class', 'admintable generaltable');
$table->setup();

$pluginmanager = core_plugin_manager::instance();

foreach ($modules as $module) {
$plugininfo = $pluginmanager->get_plugin_info('mod_' . $module->name);
$status = $plugininfo->get_status();

if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
$strmodulename = '<span class="notifyproblem">' . $module->name . ' (' . get_string('missingfromdisk') . ')</span>';
$missing = true;
} else {
$icon = "<img src=\"" . $OUTPUT->image_url('monologo', $module->name) . "\" class=\"icon\" alt=\"\" />";
$strmodulename = $icon . ' ' . get_string('modulename', $module->name);
$missing = false;
}

echo $OUTPUT->header();
echo $OUTPUT->heading($stractivities);
$uninstall = '';
if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_' . $module->name, 'manage')) {
$uninstall = html_writer::link($uninstallurl, $struninstall);
}

/// Get and sort the existing modules
if (
file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")
) {
$settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
} else {
$settings = "";
}

if (!$modules = $DB->get_records('modules', array(), 'name ASC')) {
throw new \moodle_exception('moduledoesnotexist', 'error');
try {
$count = $DB->count_records_select($module->name, "course<>0");
} catch (dml_exception $e) {
$count = -1;
}
if ($count > 0) {
$countlink = $OUTPUT->action_link(
new moodle_url('/course/search.php', ['modulelist' => $module->name]),
$count,
null,
['title' => $strshowmodulecourse]
);
} else if ($count < 0) {
$countlink = get_string('error');
} else {
$countlink = "$count";
}

/// Print the table of all modules
// construct the flexible table ready to display
$table = new flexible_table(MODULE_TABLE);
$table->define_columns(array('name', 'instances', 'version', 'hideshow', 'uninstall', 'settings'));
$table->define_headers(array($stractivitymodule, $stractivities, $strversion, "$strhide/$strshow", $strsettings, $struninstall));
$table->define_baseurl($CFG->wwwroot.'/'.$CFG->admin.'/modules.php');
$table->set_attribute('id', 'modules');
$table->set_attribute('class', 'admintable generaltable');
$table->setup();

$pluginmanager = core_plugin_manager::instance();

foreach ($modules as $module) {
$plugininfo = $pluginmanager->get_plugin_info('mod_'.$module->name);
$status = $plugininfo->get_status();

if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
$strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
$missing = true;
} else {
// took out hspace="\10\", because it does not validate. don't know what to replace with.
$icon = "<img src=\"" . $OUTPUT->image_url('monologo', $module->name) . "\" class=\"icon\" alt=\"\" />";
$strmodulename = $icon.' '.get_string('modulename', $module->name);
$missing = false;
}

$uninstall = '';
if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url('mod_'.$module->name, 'manage')) {
$uninstall = html_writer::link($uninstallurl, $struninstall);
}

if (file_exists("$CFG->dirroot/mod/$module->name/settings.php") ||
file_exists("$CFG->dirroot/mod/$module->name/settingstree.php")) {
$settings = "<a href=\"settings.php?section=modsetting$module->name\">$strsettings</a>";
} else {
$settings = "";
}

try {
$count = $DB->count_records_select($module->name, "course<>0");
} catch (dml_exception $e) {
$count = -1;
}
if ($count>0) {
$countlink = $OUTPUT->action_link(new moodle_url('/course/search.php', ['modulelist' => $module->name]),
$count, null, ['title' => $strshowmodulecourse]);
} else if ($count < 0) {
$countlink = get_string('error');
} else {
$countlink = "$count";
}

if ($missing) {
$visible = '';
$class = '';
} else if ($module->visible) {
$visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=".sesskey()."\" title=\"$strhide\">".
$OUTPUT->pix_icon('t/hide', $strhide) . '</a>';
$class = '';
} else {
$visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=".sesskey()."\" title=\"$strshow\">".
$OUTPUT->pix_icon('t/show', $strshow) . '</a>';
$class = 'dimmed_text';
}
if ($module->name == "forum") {
$uninstall = "";
$visible = "";
$class = "";
}
$version = get_config('mod_'.$module->name, 'version');

$table->add_data(array(
$strmodulename,
$countlink,
$version,
$visible,
$settings,
$uninstall,
), $class);
if ($missing) {
$visible = '';
$class = '';
} else if ($module->visible) {
$visible = "<a href=\"modules.php?hide=$module->name&amp;sesskey=" . sesskey() . "\" title=\"$strhide\">" .
$OUTPUT->pix_icon('t/hide', $strhide) . '</a>';
$class = '';
} else {
$visible = "<a href=\"modules.php?show=$module->name&amp;sesskey=" . sesskey() . "\" title=\"$strshow\">" .
$OUTPUT->pix_icon('t/show', $strshow) . '</a>';
$class = 'dimmed_text';
}
if ($module->name == "forum") {
$uninstall = "";
$visible = "";
$class = "";
}
$version = get_config('mod_' . $module->name, 'version');

$table->add_data([
$strmodulename,
$countlink,
$version,
$visible,
$settings,
$uninstall,
], $class);
}

$table->print_html();
$table->finish_html();

echo $OUTPUT->footer();
echo $OUTPUT->footer();
12 changes: 12 additions & 0 deletions lib/classes/plugininfo/mod.php
Expand Up @@ -51,6 +51,18 @@ public static function enable_plugin(string $pluginname, int $enabled): bool {

// Only set visibility if it's different from the current value.
if ($module->visible != $enabled) {
if ($enabled && component_callback_exists("mod_{$pluginname}", 'pre_enable_plugin_actions')) {
// This callback may be used to perform actions that must be completed prior to enabling a plugin.
// Example of this may include:
// - making a configuration change
// - adding an alert
// - checking a pre-requisite
//
// If the return value is falsy, then the change will be prevented.
if (!component_callback("mod_{$pluginname}", 'pre_enable_plugin_actions')) {
return false;
}
}
// Set module visibility.
$DB->set_field('modules', 'visible', $enabled, ['id' => $module->id]);
$haschanged = true;
Expand Down
11 changes: 0 additions & 11 deletions mod/bigbluebuttonbn/amd/build/accept_dpa.min.js

This file was deleted.

1 change: 0 additions & 1 deletion mod/bigbluebuttonbn/amd/build/accept_dpa.min.js.map

This file was deleted.

56 changes: 0 additions & 56 deletions mod/bigbluebuttonbn/amd/src/accept_dpa.js

This file was deleted.

0 comments on commit 946a88c

Please sign in to comment.