MDL-77269 licencemanager: show notification instead of an exception

This commit is contained in:
Simey Lameze 2023-02-16 14:24:08 +08:00
parent 8503f2cfd8
commit 3236bf8e11

View File

@ -95,7 +95,7 @@ class manager {
}
$viewmanager = true;
$message = null;
switch ($action) {
case self::ACTION_DISABLE:
license_manager::disable($license);
@ -106,7 +106,12 @@ class manager {
break;
case self::ACTION_DELETE:
license_manager::delete($license);
try {
license_manager::delete($license);
} catch (\moodle_exception $e) {
$message = $e->getMessage();
}
break;
case self::ACTION_CREATE:
@ -124,7 +129,7 @@ class manager {
break;
}
if ($viewmanager) {
$this->view_license_manager();
$this->view_license_manager($message);
}
}
@ -229,8 +234,8 @@ class manager {
/**
* View the license manager.
*/
private function view_license_manager() : void {
global $PAGE;
private function view_license_manager(string $message = null) : void {
global $PAGE, $OUTPUT;
$PAGE->requires->js_call_amd('tool_licensemanager/delete_license');
@ -238,6 +243,10 @@ class manager {
$html = $renderer->header();
$html .= $renderer->heading(get_string('licensemanager', 'tool_licensemanager'));
if (!empty($message)) {
$html .= $OUTPUT->notification($message);
}
$table = new \tool_licensemanager\output\table();
$html .= $renderer->render($table);
$html .= $renderer->footer();