From 9e9ae7a51e64c2390e6000d3edc52eaac30313a2 Mon Sep 17 00:00:00 2001 From: Shamim Rezaie Date: Mon, 16 Dec 2019 23:58:11 +1100 Subject: [PATCH] MDL-69166 core: list settings page in the admin tree --- .../manage_payment_gateway_plugins.php | 74 +++++++++++++++++++ admin/settings/plugins.php | 13 ++++ lang/en/payment.php | 25 +++++++ lang/en/plugin.php | 2 + 4 files changed, 114 insertions(+) create mode 100644 admin/classes/local/settings/manage_payment_gateway_plugins.php create mode 100644 lang/en/payment.php diff --git a/admin/classes/local/settings/manage_payment_gateway_plugins.php b/admin/classes/local/settings/manage_payment_gateway_plugins.php new file mode 100644 index 00000000000..eb97b47efe3 --- /dev/null +++ b/admin/classes/local/settings/manage_payment_gateway_plugins.php @@ -0,0 +1,74 @@ +. + +/** + * Payment gateway admin setting. + * + * @package core_admin + * @copyright 2020 Shamim Rezaie + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace core_admin\local\settings; + +/** + * Generic class for managing plugins in a table that allows re-ordering and enable/disable of each plugin. + */ +class manage_payment_gateway_plugins extends \admin_setting_manage_plugins { + /** + * Get the admin settings section title (use get_string). + * + * @return string + */ + public function get_section_title() { + return get_string('type_pg_plural', 'plugin'); + } + + /** + * Get the type of plugin to manage. + * + * @return string + */ + public function get_plugin_type() { + return 'pg'; + } + + /** + * Get the name of the second column. + * + * @return string + */ + public function get_info_column_name() { + return get_string('supportedcurrencies', 'core_payment'); + } + + /** + * Get the type of plugin to manage. + * + * @param plugininfo The plugin info class. + * @return string + */ + public function get_info_column($plugininfo) { + $codes = $plugininfo->get_supported_currencies(); + + $currencies = []; + foreach ($codes as $c) { + $currencies[$c] = new \lang_string($c, 'core_currencies'); + } + + return implode(get_string('listsep', 'langconfig') . ' ', $currencies); + } +} diff --git a/admin/settings/plugins.php b/admin/settings/plugins.php index 249bd53f873..31bbcc762bf 100644 --- a/admin/settings/plugins.php +++ b/admin/settings/plugins.php @@ -280,6 +280,19 @@ if ($hassiteconfig) { $plugin->load_settings($ADMIN, 'mediaplayers', $hassiteconfig); } + // Payment gateway plugins. + $ADMIN->add('modules', new admin_category('paymentgateways', new lang_string('type_pg_plural', 'plugin'))); + $temp = new admin_settingpage('managepaymentgateways', new lang_string('type_pgmanage', 'plugin')); + $temp->add(new \core_admin\local\settings\manage_payment_gateway_plugins()); + $ADMIN->add('paymentgateways', $temp); + + $plugins = core_plugin_manager::instance()->get_plugins_of_type('pg'); + core_collator::asort_objects_by_property($plugins, 'displayname'); + foreach ($plugins as $plugin) { + /** @var \core\plugininfo\pg $plugin */ + $plugin->load_settings($ADMIN, 'paymentgateways', $hassiteconfig); + } + // Data format settings. $ADMIN->add('modules', new admin_category('dataformatsettings', new lang_string('dataformats'))); $temp = new admin_settingpage('managedataformats', new lang_string('managedataformats')); diff --git a/lang/en/payment.php b/lang/en/payment.php new file mode 100644 index 00000000000..a78b8ac7270 --- /dev/null +++ b/lang/en/payment.php @@ -0,0 +1,25 @@ +. + +/** + * Strings for component 'payment', language 'en' + * + * @package core_payment + * @copyright 2019 Shamim Rezaie + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['supportedcurrencies'] = 'Supported currencies'; diff --git a/lang/en/plugin.php b/lang/en/plugin.php index 14e3f57c641..74481c13e85 100644 --- a/lang/en/plugin.php +++ b/lang/en/plugin.php @@ -165,6 +165,8 @@ $string['type_mnetservice'] = 'MNet service'; $string['type_mnetservice_plural'] = 'MNet services'; $string['type_mod'] = 'Activity module'; $string['type_mod_plural'] = 'Activity modules'; +$string['type_pgmanage'] = 'Manage payment gateways'; +$string['type_pg_plural'] = 'Payment gateways'; $string['type_plagiarism'] = 'Plagiarism plugin'; $string['type_plagiarism_plural'] = 'Plagiarism plugins'; $string['type_portfolio'] = 'Portfolio';