forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDL-78337 tool_brickfield: Validate registration in realtime adhoc task
- Loading branch information
1 parent
ab291aa
commit d0fc13d
Showing
10 changed files
with
279 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
import Ajax from 'core/ajax'; | ||
import Template from 'core/templates'; | ||
import Log from 'core/log'; | ||
|
||
/** | ||
* Handles polling registration status and replaces the alert block with the new one. | ||
* | ||
* @module tool_brickfield/registration | ||
* @copyright 2024 onward Brickfield Education Labs Ltd, https://www.brickfield.ie | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
export function init() { | ||
Ajax.call([{ | ||
methodname: 'tool_brickfield_check_toolkit_validation', | ||
args: {}, | ||
done: (data) => { | ||
if (data.status == -1) { | ||
// Status of -1 indicates the registration adhoc task is running. | ||
setTimeout(() => { | ||
init(); | ||
}, 2000); | ||
} else { | ||
replaceAlertBlock(data.message, data.level); | ||
} | ||
}, | ||
fail: (err) => { | ||
Log.error(err); | ||
} | ||
}]); | ||
} | ||
|
||
/** | ||
* Replaces the existing alert block with a new one. | ||
* @param {string} message The notification message | ||
* @param {string} level The notification level | ||
*/ | ||
const replaceAlertBlock = (message, level) => { | ||
Template.render('core/notification', { | ||
message: message, | ||
issuccess: level == 'success', | ||
iswarning: level == 'warning', | ||
iserror: level == 'error', | ||
closebutton: true | ||
}).then((html) => { | ||
const oldAlert = document.querySelector('.alert-block'); | ||
let temp = document.createElement('div'); | ||
temp.innerHTML = html; | ||
let newAlert = temp.firstChild; | ||
oldAlert.parentNode.insertBefore(newAlert, oldAlert); | ||
oldAlert.parentNode.removeChild(oldAlert); | ||
return; | ||
}).catch((err) => { | ||
Log.error(err); | ||
}); | ||
}; |
82 changes: 82 additions & 0 deletions
82
admin/tool/brickfield/classes/external/check_toolkit_validation.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace tool_brickfield\external; | ||
|
||
use core\task\manager as taskmanager; | ||
use core_external\external_function_parameters; | ||
use core_external\external_single_structure; | ||
use core_external\external_value; | ||
use tool_brickfield\registration; | ||
use tool_brickfield\manager; | ||
|
||
/** | ||
* Service to check the status of the toolkit registrtion. | ||
* | ||
* @package tool_brickfield | ||
* @copyright 2024 onward Brickfield Education Labs Ltd, https://www.brickfield.ie | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class check_toolkit_validation extends \core_external\external_api { | ||
|
||
/** | ||
* Returns description of method parameters | ||
* @return external_function_parameters | ||
*/ | ||
public static function execute_parameters() { | ||
return new external_function_parameters([]); | ||
} | ||
|
||
/** | ||
* Check results of the adhoc task to check validation. | ||
* | ||
* @return bool | ||
*/ | ||
public static function execute() { | ||
$tasks = taskmanager::get_adhoc_tasks('\tool_brickfield\task\validate_registration', false, true); | ||
if (empty($tasks)) { | ||
$status = get_config('tool_brickfield', registration::STATUS); | ||
if ($status == registration::NOT_ENTERED || $status == registration::EXPIRED || $status == registration::INVALID) { | ||
$message = get_string('inactive', manager::PLUGINNAME); | ||
$level = 'error'; | ||
} else if ($status == registration::PENDING) { | ||
$message = get_string('notvalidated', manager::PLUGINNAME); | ||
$level = 'warning'; | ||
} else if ($status == registration::VALIDATED) { | ||
$message = get_string('activated', manager::PLUGINNAME); | ||
$level = 'success'; | ||
} else if ($status == registration::ERROR) { | ||
$message = get_string('validationerror', manager::PLUGINNAME); | ||
$level = 'error'; | ||
} | ||
return ['status' => $status, 'message' => $message, 'level' => $level]; | ||
} else { | ||
return ['status' => -1]; // Indicate task is still in progress. | ||
} | ||
} | ||
|
||
/** | ||
* Returns description of method result value | ||
* @return external_description | ||
*/ | ||
public static function execute_returns() { | ||
return new external_single_structure([ | ||
'status' => new external_value(PARAM_INT, 'Registration validation status'), | ||
'message' => new external_value(PARAM_TEXT, 'Status message', VALUE_OPTIONAL), | ||
'level' => new external_value(PARAM_TEXT, 'Status level', VALUE_OPTIONAL), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
admin/tool/brickfield/classes/task/validate_registration.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
namespace tool_brickfield\task; | ||
use tool_brickfield\registration; | ||
|
||
/** | ||
* Adhoc task to validate registration details. | ||
* | ||
* @package tool_brickfield | ||
* @copyright 2024 onward Brickfield Education Labs Ltd, https://www.brickfield.ie | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
class validate_registration extends \core\task\adhoc_task { | ||
/** | ||
* Execute the task | ||
*/ | ||
public function execute() { | ||
(new registration())->validate(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
// This file is part of Moodle - http://moodle.org/ | ||
// | ||
// Moodle is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Moodle is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* External functions and service declaration for Accessibility toolkit | ||
* | ||
* Documentation: {@link https://moodledev.io/docs/apis/subsystems/external/description} | ||
* | ||
* @package tool_brickfield | ||
* @category webservice | ||
* @copyright 2024 onward Brickfield Education Labs Ltd, https://www.brickfield.ie | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
|
||
$functions = [ | ||
'tool_brickfield_check_toolkit_validation' => [ | ||
'classname' => 'tool_brickfield\external\check_toolkit_validation', | ||
'methodname' => 'execute', | ||
'classpath' => 'classes/external/check_toolkit_validation.php', | ||
'description' => 'Service to check the status of the toolkit registration.', | ||
'type' => 'read', | ||
'ajax' => true, | ||
], | ||
]; | ||
|
||
$services = [ | ||
'Accessibility toolkit' => [ | ||
'functions' => ['tool_brickfield_check_toolkit_validation'], | ||
'restrictedusers' => 0, | ||
'enabled' => 1, | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters