initial commit
This commit is contained in:
commit
63e569c6ca
9 changed files with 369 additions and 0 deletions
66
classes/get_parents.php
Normal file
66
classes/get_parents.php
Normal 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'),
|
||||
]));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue