MDL-69166 enrol_fee: Show a warning when no currency is supported
authorShamim Rezaie <shamim@moodle.com>
Wed, 30 Sep 2020 03:24:43 +0000 (13:24 +1000)
committerShamim Rezaie <shamim@moodle.com>
Tue, 27 Oct 2020 04:44:59 +0000 (15:44 +1100)
enrol/fee/settings.php
lang/en/payment.php

index 0a21a50..0d368cf 100644 (file)
@@ -26,6 +26,16 @@ defined('MOODLE_INTERNAL') || die();
 
 if ($ADMIN->fulltree) {
 
+    $currencies = enrol_get_plugin('fee')->get_possible_currencies();
+
+    if (empty($currencies)) {
+        $notify = new \core\output\notification(
+            get_string('nocurrencysupported', 'core_payment'),
+            \core\output\notification::NOTIFY_WARNING
+        );
+        $settings->add(new admin_setting_heading('enrol_fee_nocurrency', '', $OUTPUT->render($notify)));
+    }
+
     $settings->add(new admin_setting_heading('enrol_fee_settings', '', get_string('pluginname_desc', 'enrol_fee')));
 
     // Note: let's reuse the ext sync constants and strings here, internally it is very similar,
@@ -36,11 +46,11 @@ if ($ADMIN->fulltree) {
         ENROL_EXT_REMOVED_UNENROL        => get_string('extremovedunenrol', 'enrol'),
     );
     $settings->add(new admin_setting_configselect(
-            'enrol_fee/expiredaction',
-            get_string('expiredaction', 'enrol_fee'),
-            get_string('expiredaction_help', 'enrol_fee'),
-            ENROL_EXT_REMOVED_SUSPENDNOROLES,
-            $options));
+        'enrol_fee/expiredaction',
+        get_string('expiredaction', 'enrol_fee'),
+        get_string('expiredaction_help', 'enrol_fee'),
+        ENROL_EXT_REMOVED_SUSPENDNOROLES,
+        $options));
 
     $settings->add(new admin_setting_heading('enrol_fee_defaults',
         get_string('enrolinstancedefaults', 'admin'), get_string('enrolinstancedefaults_desc', 'admin')));
@@ -50,10 +60,11 @@ if ($ADMIN->fulltree) {
     $settings->add(new admin_setting_configselect('enrol_fee/status',
         get_string('status', 'enrol_fee'), get_string('status_desc', 'enrol_fee'), ENROL_INSTANCE_DISABLED, $options));
 
-    $settings->add(new admin_setting_configtext('enrol_fee/cost', get_string('cost', 'enrol_fee'), '', 0, PARAM_FLOAT, 4));
-
-    $currencies = enrol_get_plugin('fee')->get_possible_currencies();
-    $settings->add(new admin_setting_configselect('enrol_fee/currency', get_string('currency', 'enrol_fee'), '', '', $currencies));
+    if (!empty($currencies)) {
+        $settings->add(new admin_setting_configtext('enrol_fee/cost', get_string('cost', 'enrol_fee'), '', 0, PARAM_FLOAT, 4));
+        $settings->add(new admin_setting_configselect('enrol_fee/currency', get_string('currency', 'enrol_fee'), '', '',
+            $currencies));
+    }
 
     if (!during_initial_install()) {
         $options = get_default_enrol_roles(context_system::instance());
index b2cb516..71a8981 100644 (file)
@@ -24,6 +24,7 @@
 
 $string['callbacknotimplemented'] = 'The callback is not implemented for component {$a}.';
 $string['feeincludesurcharge'] = '{$a->fee} (includes {$a->surcharge}% surcharge for using this payment type)';
+$string['nocurrencysupported'] = 'No payment in any currency is supported. Please make sure that at least one payment gateway is enabled.';
 $string['nogateway'] = 'There is no payment gateway that can be used.';
 $string['nogatewayselected'] = 'You first need to select a payment gateway.';
 $string['selectpaymenttype'] = 'Select payment type';