initial commit
This commit is contained in:
commit
63e569c6ca
9 changed files with 369 additions and 0 deletions
68
classes/get_children.php
Normal file
68
classes/get_children.php
Normal 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'),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
58
classes/get_global_roles.php
Normal file
58
classes/get_global_roles.php
Normal 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
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'),
|
||||||
|
]));
|
||||||
|
}
|
||||||
|
}
|
49
classes/privacy/provider.php
Normal file
49
classes/privacy/provider.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
52
db/services.php
Normal file
52
db/services.php
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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' => '',
|
||||||
|
),
|
||||||
|
);
|
7
externallib.php
Normal file
7
externallib.php
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?php
|
||||||
|
defined('MOODLE_INTERNAL') || die();
|
||||||
|
|
||||||
|
require_once($CFG->dirroot . '/lib/externallib.php');
|
||||||
|
require_once('classes/get_children.php');
|
||||||
|
require_once('classes/get_global_roles.php');
|
||||||
|
require_once('classes/get_parents.php');
|
26
lang/en/local_lara.php
Normal file
26
lang/en/local_lara.php
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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';
|
13
redirector.php
Normal file
13
redirector.php
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
<?php
|
||||||
|
require_once('../../config.php');
|
||||||
|
|
||||||
|
$pmurl = optional_param('wantsurl',"/", PARAM_TEXT);
|
||||||
|
|
||||||
|
$PAGE->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());
|
30
version.php
Normal file
30
version.php
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
<?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/>.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
Loading…
Add table
Add a link
Reference in a new issue