diff --git a/admin/communication.php b/admin/communication.php new file mode 100644 index 00000000000..8acb12d657f --- /dev/null +++ b/admin/communication.php @@ -0,0 +1,65 @@ +. + +/** + * Communication and its plugins settings. + * + * @package core + * @subpackage communication + * @copyright 2023 Huong Nguyen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +require_once('../config.php'); +require_once($CFG->libdir . '/adminlib.php'); + +$action = required_param('action', PARAM_ALPHANUMEXT); +$name = required_param('name', PARAM_PLUGIN); + +$syscontext = context_system::instance(); +$PAGE->set_url('/admin/communication.php'); +$PAGE->set_context($syscontext); + +require_admin(); +require_sesskey(); + +$return = new moodle_url('/admin/settings.php', ['section' => 'managecommunicationproviders']); + +$plugins = core_plugin_manager::instance()->get_plugins_of_type('communication'); +$sortorder = array_flip(array_keys($plugins)); + +if (!isset($plugins[$name])) { + throw new moodle_exception('communicationprovidernotfound', 'core_communication', $return, $name); +} + +$plugintypename = $plugins[$name]->type . '_' . $plugins[$name]->name; + +switch ($action) { + case 'disable': + if ($plugins[$name]->is_enabled()) { + $class = core_plugin_manager::resolve_plugininfo_class('communication'); + $class::enable_plugin($name, false); + } + break; + case 'enable': + if (!$plugins[$name]->is_enabled()) { + $class = core_plugin_manager::resolve_plugininfo_class('communication'); + $class::enable_plugin($name, true); + } + break; +} + +redirect($return); diff --git a/admin/settings/development.php b/admin/settings/development.php index 1ac32993d5d..9fb6f0c5042 100644 --- a/admin/settings/development.php +++ b/admin/settings/development.php @@ -38,6 +38,11 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page new lang_string('enablesharingtomoodlenet', 'core_admin'), new lang_string('enablesharingtomoodlenet_desc', 'core_admin'), 0)); + // New communication subsystem setting. + $temp->add(new admin_setting_configcheckbox('enablecommunicationsubsystem', + new lang_string('enablecommunicationsubsystem', 'core_admin'), + new lang_string('enablecommunicationsubsystem_desc', 'core_admin'), 0)); + $ADMIN->add('experimental', $temp); // "debugging" settingpage diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 02319e06647..954d5aec200 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -781,6 +781,20 @@ if ($hassiteconfig) { } } +// Communication plugins. +if ($hassiteconfig && core_communication\api::is_available()) { + $ADMIN->add('modules', new admin_category('communicationsettings', new lang_string('communication', 'core_communication'))); + $temp = new admin_settingpage('managecommunicationproviders', + new lang_string('managecommunicationproviders', 'core_communication')); + $temp->add(new \core_communication\admin\manage_communication_providers_page()); + $ADMIN->add('communicationsettings', $temp); + $plugins = core_plugin_manager::instance()->get_plugins_of_type('communication'); + foreach ($plugins as $plugin) { + /** @var \core\plugininfo\communication $plugin */ + $plugin->load_settings($ADMIN, 'communicationsettings', $hassiteconfig); + } +} + // Content bank content types. if ($hassiteconfig) { $ADMIN->add('modules', new admin_category('contentbanksettings', new lang_string('contentbank'))); diff --git a/communication/classes/admin/manage_communication_providers_page.php b/communication/classes/admin/manage_communication_providers_page.php new file mode 100644 index 00000000000..384f8d2b12a --- /dev/null +++ b/communication/classes/admin/manage_communication_providers_page.php @@ -0,0 +1,124 @@ +. + +namespace core_communication\admin; + +use admin_setting; +use core_plugin_manager; +use core_text; +use html_table; +use html_table_row; +use html_writer; +use moodle_url; + +/** + * Communication providers manager. Allow enable/disable communication providers and jump to settings. + * + * @package core_communication + * @copyright 2023 Huong Nguyen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class manage_communication_providers_page extends admin_setting { + + public function __construct() { + $this->nosave = true; + parent::__construct('managecommunications', + new \lang_string('managecommunicationproviders', 'core_communication'), '', ''); + } + + public function get_setting(): bool { + return true; + } + + public function write_setting($data): string { + // Do not write any setting. + return ''; + } + + public function output_html($data, $query = ''): string { + global $OUTPUT; + + $pluginmanager = core_plugin_manager::instance(); + $plugins = $pluginmanager->get_plugins_of_type('communication'); + if (empty($plugins)) { + return get_string('nocommunicationprovider', 'core_communication'); + } + + $table = new html_table(); + $table->head = [ + get_string('name'), + get_string('enable'), + get_string('settings'), + get_string('uninstallplugin', 'core_admin'), + ]; + $table->align = ['left', 'center', 'center', 'center']; + $table->attributes['class'] = 'managecommunicationtable generaltable admintable'; + $table->data = []; + + foreach ($plugins as $plugin) { + $class = ''; + $actionurl = new moodle_url('/admin/communication.php', ['sesskey' => sesskey(), 'name' => $plugin->name]); + if ($pluginmanager->get_plugin_info('communication_' . $plugin->name)->get_status() === + core_plugin_manager::PLUGIN_STATUS_MISSING) { + $strtypename = $plugin->displayname . ' (' . get_string('missingfromdisk') . ')'; + } else { + $strtypename = $plugin->displayname; + } + + if ($plugin->is_enabled()) { + $hideshow = html_writer::link($actionurl->out(false, ['action' => 'disable']), + $OUTPUT->pix_icon('t/hide', get_string('disable'), 'moodle', ['class' => 'iconsmall'])); + } else { + $class = 'dimmed_text'; + $hideshow = html_writer::link($actionurl->out(false, ['action' => 'enable']), + $OUTPUT->pix_icon('t/show', get_string('enable'), 'moodle', ['class' => 'iconsmall'])); + } + + $settings = ''; + if ($plugin->get_settings_url()) { + $settings = html_writer::link($plugin->get_settings_url(), get_string('settings')); + } + + $uninstall = ''; + if ($uninstallurl = core_plugin_manager::instance()->get_uninstall_url( + 'communication_' . $plugin->name, 'manage')) { + $uninstall = html_writer::link($uninstallurl, get_string('uninstallplugin', 'core_admin')); + } + + $row = new html_table_row([$strtypename, $hideshow, $settings, $uninstall]); + if ($class) { + $row->attributes['class'] = $class; + } + $table->data[] = $row; + } + + return highlight($query, html_writer::table($table)); + } + + public function is_related($query): bool { + if (parent::is_related($query)) { + return true; + } + $types = core_plugin_manager::instance()->get_plugins_of_type('communication'); + foreach ($types as $type) { + if (strpos($type->component, $query) !== false || + strpos(core_text::strtolower($type->displayname), $query) !== false) { + return true; + } + } + return false; + } +} diff --git a/communication/classes/privacy/provider.php b/communication/classes/privacy/provider.php new file mode 100644 index 00000000000..36695f05af6 --- /dev/null +++ b/communication/classes/privacy/provider.php @@ -0,0 +1,39 @@ +. + +namespace core_communication\privacy; + +use core_privacy\local\metadata\null_provider; + +/** + * Privacy Subsystem for core_communication implementing null_provider. + * + * @package core_communication + * @copyright 2023 Huong Nguyen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason(): string { + return 'privacy:metadata'; + } +} diff --git a/lang/en/admin.php b/lang/en/admin.php index 886bd7aabd3..672c595fb3b 100644 --- a/lang/en/admin.php +++ b/lang/en/admin.php @@ -589,6 +589,8 @@ $string['enableanalytics'] = 'Analytics'; $string['enableblogs'] = 'Enable blogs'; $string['enablecalendarexport'] = 'Enable calendar export'; $string['enablecomments'] = 'Enable comments'; +$string['enablecommunicationsubsystem'] = 'Enable communication subsystem'; +$string['enablecommunicationsubsystem_desc'] = 'This setting enables the new communication subsystem. This new subsystem allow teachers and students to more easily communicate while using Moodle for teaching and learning'; $string['enablecourserelativedates'] = 'Enable course relative dates'; $string['enablecourserelativedates_desc'] = 'Allow courses to be set up to display dates relative to the user\'s start date in the course.'; $string['enablecourserequests'] = 'Enable course requests'; diff --git a/lang/en/communication.php b/lang/en/communication.php new file mode 100644 index 00000000000..92c906dfae4 --- /dev/null +++ b/lang/en/communication.php @@ -0,0 +1,29 @@ +. + +/** + * Strings for component 'communication', language 'en'. + * + * @package core_communication + * @copyright 2022 Huong Nguyen + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['communication'] = 'Communication'; +$string['communicationprovidernotfound'] = 'The \'{$a}\' communication provider doesn\'t exist or is not recognised.'; +$string['managecommunicationproviders'] = 'Manage communication providers'; +$string['nocommunicationprovider'] = 'No communication provider found.'; +$string['privacy:metadata'] = 'The Moodle communication subsystem does not store any personal data.'; diff --git a/lib/classes/plugin_manager.php b/lib/classes/plugin_manager.php index 2e1505c69e8..076329cc2b3 100644 --- a/lib/classes/plugin_manager.php +++ b/lib/classes/plugin_manager.php @@ -1825,6 +1825,8 @@ class core_plugin_manager { 'gregorian' ), + 'communication' => [], + 'contenttype' => array( 'h5p' ), diff --git a/lib/components.json b/lib/components.json index cc6dd1f620b..89b6b31e093 100644 --- a/lib/components.json +++ b/lib/components.json @@ -59,6 +59,7 @@ "calendar": "calendar", "cohort": "cohort", "comment": "comment", + "communication": "communication", "competency": "competency", "completion": "completion", "contentbank": "contentbank", diff --git a/lib/tests/component_test.php b/lib/tests/component_test.php index 5ae4d2b51ce..9463ca885d7 100644 --- a/lib/tests/component_test.php +++ b/lib/tests/component_test.php @@ -31,7 +31,7 @@ class component_test extends advanced_testcase { * this is defined here to annoy devs that try to add more without any thinking, * always verify that it does not collide with any existing add-on modules and subplugins!!! */ - const SUBSYSTEMCOUNT = 76; + const SUBSYSTEMCOUNT = 77; public function setUp(): void { $psr0namespaces = new ReflectionProperty('core_component', 'psr0namespaces');