From 63e569c6cadd07fa639cc86f4a76cd023517cbb8 Mon Sep 17 00:00:00 2001 From: min Date: Thu, 12 Dec 2024 09:41:03 +0100 Subject: [PATCH] initial commit --- classes/get_children.php | 68 ++++++++++++++++++++++++++++++++++++ classes/get_global_roles.php | 58 ++++++++++++++++++++++++++++++ classes/get_parents.php | 66 ++++++++++++++++++++++++++++++++++ classes/privacy/provider.php | 49 ++++++++++++++++++++++++++ db/services.php | 52 +++++++++++++++++++++++++++ externallib.php | 7 ++++ lang/en/local_lara.php | 26 ++++++++++++++ redirector.php | 13 +++++++ version.php | 30 ++++++++++++++++ 9 files changed, 369 insertions(+) create mode 100644 classes/get_children.php create mode 100644 classes/get_global_roles.php create mode 100644 classes/get_parents.php create mode 100644 classes/privacy/provider.php create mode 100644 db/services.php create mode 100644 externallib.php create mode 100644 lang/en/local_lara.php create mode 100644 redirector.php create mode 100644 version.php diff --git a/classes/get_children.php b/classes/get_children.php new file mode 100644 index 0000000..f3e3171 --- /dev/null +++ b/classes/get_children.php @@ -0,0 +1,68 @@ +dirroot . '/lib/externallib.php'; + +class local_lara_get_children extends external_api +{ + /** + * Parameter description for get_roles(). + * + * @return external_function_parameters. + */ + public static function get_children_parameters() + { + return new external_function_parameters([ + 'param' => new external_single_structure([ + 'roleid' => new external_value(PARAM_INT, 'id of the parent role'), + 'parentid' => new external_value(PARAM_INT, 'parent id'), + ]), + ]); + } + + /** + * Return roleinformation. + * + * This function returns roleid, rolename and roleshortname for all roles or for given roles. + * + * @param array $param + * @return array Array of arrays with role informations. + */ + public static function get_children($param) + { + global $CFG, $DB; + require_once "$CFG->dirroot/group/lib.php"; + + $params = self::validate_parameters(self::get_children_parameters(), ['param' => $param]); + + $roleid = $params['param']['roleid']; + $parentid = $params['param']['parentid']; + + $children = []; + + $parents = $DB->get_records('role_assignments', ['roleid' => (string) $roleid, 'userid' => (string) $parentid]); + foreach ($parents as $parent) { + $ctxid = (string)$parent->contextid; + $dbChildren = $DB->get_records('context', ['id' => $ctxid, 'contextlevel' => '30']); + foreach ($dbChildren as $child) { + $cl = new stdClass; + $cl->id = ($child->instanceid); + array_push($children, $cl); + } + } + return $children; + } + + /** + * Parameter description for create_sections(). + * + * @return external_description + */ + public static function get_children_returns() + { + return new external_multiple_structure( + new external_single_structure([ + 'id' => new external_value(PARAM_INT, 'role id'), + ])); + } +} diff --git a/classes/get_global_roles.php b/classes/get_global_roles.php new file mode 100644 index 0000000..7e10ac6 --- /dev/null +++ b/classes/get_global_roles.php @@ -0,0 +1,58 @@ +dirroot . '/lib/externallib.php'; + +class local_lara_get_global_roles extends external_api +{ + /** + * Parameter description for get_global_roles(). + * + * @return external_function_parameters. + */ + public static function get_global_roles_parameters() + { + return new external_function_parameters([]); + } + + /** + * Return roleinformation. + * + * This function returns a userid and the roleids of that user. + * + * @return array Array of arrays with role informations. + */ + public static function get_global_roles() + { + global $DB; + // require_once "$CFG->dirroot/group/lib.php"; + + $roles = $DB->get_records('role_assignments', ['contextid' => '1']); + + print $roles; + + $roleIds = []; + foreach ($roles as $role) { + $cl = new stdClass(); + $cl->roleid = ($role->roleid); + $cl->userid = ($role->userid); + array_push($roleIds, $cl); + } + + return $roleIds; + } + + /** + * Parameter description for get_global_roles(). + * + * @return external_description + */ + public static function get_global_roles_returns() + { + return new external_multiple_structure( + new external_single_structure([ + 'userid' => new external_value(PARAM_INT, 'user id'), + 'roleid' => new external_value(PARAM_INT, 'role id'), + ])); + } +} diff --git a/classes/get_parents.php b/classes/get_parents.php new file mode 100644 index 0000000..4ad5b6e --- /dev/null +++ b/classes/get_parents.php @@ -0,0 +1,66 @@ +dirroot . '/lib/externallib.php'; + +class local_lara_get_parents extends external_api +{ + /** + * Parameter description for get_roles(). + * + * @return external_function_parameters. + */ + public static function get_parents_parameters() + { + return new external_function_parameters([ + 'param' => new external_single_structure([ + 'roleid' => new external_value(PARAM_INT, 'id of the parent role'), + 'userid' => new external_value(PARAM_INT, 'child id'), + ]), + ]); + } + + /** + * Return roleinformation. + * + * This function returns roleid, rolename and roleshortname for all roles or for given roles. + * + * @param array $param + * @return array Array of arrays with role informations. + */ + public static function get_parents($param) + { + global $CFG, $DB; + require_once "$CFG->dirroot/group/lib.php"; + + $params = self::validate_parameters(self::get_parents_parameters(), ['param' => $param]); + + $roleid = $params['param']['roleid']; + $userid = $params['param']['userid']; + + $parents = []; + $contexts = $DB->get_records('context', ['instanceid' => (string) $userid, 'contextlevel' => '30']); + foreach ($contexts as $context) { + $dbParents = $DB->get_records('role_assignments', ['contextid' => (string) $context->id]); + foreach ($dbParents as $parent) { + $cl = new stdClass; + $cl->id = ($parent->userid); + array_push($parents, $cl); + } + } + return $parents; + } + + /** + * Parameter description for create_sections(). + * + * @return external_description + */ + public static function get_parents_returns() + { + return new external_multiple_structure( + new external_single_structure([ + 'id' => new external_value(PARAM_INT, 'role id'), + ])); + } +} diff --git a/classes/privacy/provider.php b/classes/privacy/provider.php new file mode 100644 index 0000000..08562b4 --- /dev/null +++ b/classes/privacy/provider.php @@ -0,0 +1,49 @@ +. + +/** + * Privacy implementation for local_wsgetroles. + * + * @package local_wsgetroles + * @copyright 2020 corvus albus + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +namespace local_wsgetroles\privacy; + +defined('MOODLE_INTERNAL') || die(); + +/** + * Privacy functions for the plugin. + * + * @package local_wsgetroles + * @copyright 2020 corvus albus + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ +class provider implements + // This plugin does not store any personal user data. + \core_privacy\local\metadata\null_provider { + + /** + * Get the language string identifier with the component's language + * file to explain why this plugin stores no data. + * + * @return string + */ + public static function get_reason() : string { + return 'privacy:metadata'; + } +} diff --git a/db/services.php b/db/services.php new file mode 100644 index 0000000..cf1ed39 --- /dev/null +++ b/db/services.php @@ -0,0 +1,52 @@ +. + +/** + * Web service definitions for local_wsgetroles + * + * @package local_wsgetroles + * @copyright 2020 corvus albus + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +defined('MOODLE_INTERNAL') || die(); + +$functions = array( + 'local_lara_get_global_roles' => array( + 'classname' => 'local_lara_get_global_roles', + 'methodname' => 'get_global_roles', + 'classpath' => 'local/lara/externallib.php', + 'description' => 'Get globally assigned roles of the user.', + 'type' => 'read', + 'capabilities' => '', + ), + 'local_lara_get_parents' => array( + 'classname' => 'local_lara_get_parents', + 'methodname' => 'get_parents', + 'classpath' => 'local/lara/externallib.php', + 'description' => 'Get the Users assigned with a role to another user.', + 'type' => 'read', + 'capabilities' => '', + ), + 'local_lara_get_children' => array( + 'classname' => 'local_lara_get_children', + 'methodname' => 'get_children', + 'classpath' => 'local/lara/externallib.php', + 'description' => 'Get the Users assigned with a role to another user.', + 'type' => 'read', + 'capabilities' => '', + ), +); diff --git a/externallib.php b/externallib.php new file mode 100644 index 0000000..d221efa --- /dev/null +++ b/externallib.php @@ -0,0 +1,7 @@ +dirroot . '/lib/externallib.php'); +require_once('classes/get_children.php'); +require_once('classes/get_global_roles.php'); +require_once('classes/get_parents.php'); diff --git a/lang/en/local_lara.php b/lang/en/local_lara.php new file mode 100644 index 0000000..1f9ef20 --- /dev/null +++ b/lang/en/local_lara.php @@ -0,0 +1,26 @@ +. + +/** + * Language file for local_wsgetroles + * + * @package local_wsgetroles + * @copyright 2020 corvus albus + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +$string['privacy:metadata'] = 'The webservice_lara plugin does not store any personal data.'; +$string['pluginname'] = 'Lara-Sync Plugin'; diff --git a/redirector.php b/redirector.php new file mode 100644 index 0000000..9241d59 --- /dev/null +++ b/redirector.php @@ -0,0 +1,13 @@ +set_url(new moodle_url('local/auto_oauth2/redirector.php')); + +$PAGE->set_context(\context_system::instance()); + +$PAGE->set_title("Redirect"); + +// id may need to be adjusted +redirect($CFG->wwwroot.'/auth/oauth2/login.php?id=1&wantsurl='.$pmurl.'&sesskey='.sesskey()); \ No newline at end of file diff --git a/version.php b/version.php new file mode 100644 index 0000000..a5234f6 --- /dev/null +++ b/version.php @@ -0,0 +1,30 @@ +. + +/** + * local_lara version information + * + * @package local_lara + * @copyright 2024 + */ + +defined('MOODLE_INTERNAL') || die(); + +$plugin->component = 'local_lara'; +$plugin->maturity = MATURITY_STABLE; +$plugin->release = 'v1.1.0'; +$plugin->requires = 2017051500; +$plugin->version = 2024072207;