From fbe3178a558e380ab54eb0f7f7b74822492aea64 Mon Sep 17 00:00:00 2001 From: Dani Palou Date: Thu, 13 Feb 2020 13:34:39 +0100 Subject: [PATCH] MDL-67907 airnotifier: Warn if some settings disabled after get key --- .../lang/en/message_airnotifier.php | 1 + .../output/airnotifier/requestaccesskey.php | 41 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/message/output/airnotifier/lang/en/message_airnotifier.php b/message/output/airnotifier/lang/en/message_airnotifier.php index 5b8750144cd..5005377ca71 100644 --- a/message/output/airnotifier/lang/en/message_airnotifier.php +++ b/message/output/airnotifier/lang/en/message_airnotifier.php @@ -35,6 +35,7 @@ $string['configairnotifiermobileappname'] = 'The Mobile app unique identifier (u $string['deletecheckdevicename'] = 'Delete your device: {$a->name}'; $string['deletedevice'] = 'Delete the device. Note that an app can register the device again. If the device keeps reappearing, disable it.'; $string['devicetoken'] = 'Device token'; +$string['enableprocessor'] = 'Enable Mobile notifications.'; $string['errorretrievingkey'] = 'An error occurred while retrieving the access key. Your site must be registered to use this service. If your site is already registered, please try updating your registration.'; $string['keyretrievedsuccessfully'] = 'Key retrieved successfully'; $string['nodevices'] = 'No registered devices. Devices will automatically appear after you install the Moodle app and add this site.'; diff --git a/message/output/airnotifier/requestaccesskey.php b/message/output/airnotifier/requestaccesskey.php index 3d1991fc3e2..e9ca761927e 100644 --- a/message/output/airnotifier/requestaccesskey.php +++ b/message/output/airnotifier/requestaccesskey.php @@ -62,12 +62,49 @@ if (strpos($CFG->airnotifierurl, AIRNOTIFIER_PUBLICURL) !== false ) { } $manager = new message_airnotifier_manager(); +$warnings = []; if ($key = $manager->request_accesskey()) { set_config('airnotifieraccesskey', $key); - $msg = get_string('keyretrievedsuccessfully', 'message_airnotifier'); + $msg = $OUTPUT->box(get_string('keyretrievedsuccessfully', 'message_airnotifier'), 'generalbox alert alert-success'); + + // Check mobile notifications. + $processors = get_message_processors(); + $enabled = false; + foreach ($processors as $processor => $status) { + if ($processor == 'airnotifier' && $status->enabled) { + $enabled = true; + } + } + + if (!$enabled) { + // Airnotifier processor isn't enabled. Warn the user. + $warnings[] = [ + 'msg' => get_string('mobilenotificationsdisabledwarning', 'tool_mobile'), + 'linkmsg' => get_string('enableprocessor', 'message_airnotifier'), + 'linkurl' => new moodle_url('/admin/message.php'), + ]; + } + + if (empty($CFG->enablemobilewebservice)) { + // Mobile web services not enabled. Warn the user. + $warnings[] = [ + 'msg' => get_string('mobilenotconfiguredwarning', 'admin'), + 'linkmsg' => get_string('enablemobilewebservice', 'admin'), + 'linkurl' => new moodle_url('/admin/settings.php', ['section' => 'mobilesettings']), + ]; + } } else { - $msg = get_string('errorretrievingkey', 'message_airnotifier'); + $msg = $OUTPUT->box(get_string('errorretrievingkey', 'message_airnotifier'), 'generalbox alert alert-danger'); +} + +// Display the warnings. +foreach ($warnings as $warning) { + if (!empty($warning['linkurl'])) { + $warning['msg'] = $warning['msg'] . ' ' . html_writer::tag('a', $warning['linkmsg'], ['href' => $warning['linkurl']]); + } + + $msg .= $OUTPUT->box($warning['msg'], 'generalbox alert alert-warning'); } $msg .= $OUTPUT->continue_button($returl);