68 lines
2.1 KiB
PHP
68 lines
2.1 KiB
PHP
<?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'),
|
|
]));
|
|
}
|
|
}
|