initial commit

This commit is contained in:
MIN (Sebastian von Minckwitz) 2024-12-12 09:41:03 +01:00
commit 63e569c6ca
9 changed files with 369 additions and 0 deletions

68
classes/get_children.php Normal file
View file

@ -0,0 +1,68 @@
<?php
defined('MOODLE_INTERNAL') || die();
require_once $CFG->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'),
]));
}
}

View file

@ -0,0 +1,58 @@
<?php
defined('MOODLE_INTERNAL') || die();
require_once $CFG->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'),
]));
}
}

66
classes/get_parents.php Normal file
View file

@ -0,0 +1,66 @@
<?php
defined('MOODLE_INTERNAL') || die();
require_once $CFG->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'),
]));
}
}

View file

@ -0,0 +1,49 @@
<?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/>.
/**
* 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';
}
}