|
|
|
@ -32,7 +32,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
defined('MOODLE_INTERNAL') || die();
|
|
|
|
|
|
|
|
|
|
|
|
class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
class enrol_iserv_plugin extends enrol_plugin
|
|
|
|
|
|
|
|
{
|
|
|
|
protected $enroltype = 'enrol_iserv';
|
|
|
|
protected $enroltype = 'enrol_iserv';
|
|
|
|
static protected $error_log_tag = 'ENROL ISERV';
|
|
|
|
static protected $error_log_tag = 'ENROL ISERV';
|
|
|
|
static protected $idnumber_course_category = 'iserv_courses';
|
|
|
|
static protected $idnumber_course_category = 'iserv_courses';
|
|
|
|
@ -44,7 +45,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
const LOG_DEBUG = 1;
|
|
|
|
const LOG_DEBUG = 1;
|
|
|
|
const LOG_MTRACE = 2;
|
|
|
|
const LOG_MTRACE = 2;
|
|
|
|
|
|
|
|
|
|
|
|
public function __construct() {
|
|
|
|
public function __construct()
|
|
|
|
|
|
|
|
{
|
|
|
|
global $CFG;
|
|
|
|
global $CFG;
|
|
|
|
require_once($CFG->libdir . '/accesslib.php');
|
|
|
|
require_once($CFG->libdir . '/accesslib.php');
|
|
|
|
require_once($CFG->libdir . '/ldaplib.php');
|
|
|
|
require_once($CFG->libdir . '/ldaplib.php');
|
|
|
|
@ -81,12 +83,14 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @param string $func Optional: Current function the message is logged from
|
|
|
|
* @param string $func Optional: Current function the message is logged from
|
|
|
|
* @param bool $mode Optional: Specify logging mode, see LOG_ constants in class
|
|
|
|
* @param bool $mode Optional: Specify logging mode, see LOG_ constants in class
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
static function debuglog ($text, $func = "Generic", $mode = 0) {
|
|
|
|
static function debuglog($text, $func = "Generic", $mode = 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
$error_log_tag = self::$error_log_tag;
|
|
|
|
$error_log_tag = self::$error_log_tag;
|
|
|
|
$now = date("H:i:s");
|
|
|
|
$now = date("H:i:s");
|
|
|
|
$line = "[{$error_log_tag} -> {$func} @ {$now}] {$text}";
|
|
|
|
$line = "[{$error_log_tag} -> {$func} @ {$now}] {$text}";
|
|
|
|
|
|
|
|
|
|
|
|
if (defined("CLI_SCRIPT")) $mode = -1;
|
|
|
|
if (defined("CLI_SCRIPT"))
|
|
|
|
|
|
|
|
$mode = -1;
|
|
|
|
|
|
|
|
|
|
|
|
switch ($mode) {
|
|
|
|
switch ($mode) {
|
|
|
|
case -1:
|
|
|
|
case -1:
|
|
|
|
@ -109,7 +113,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $userid User ID to sync enrolments with
|
|
|
|
* @param string $userid User ID to sync enrolments with
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function sync_courses ($userid = "*") {
|
|
|
|
public function sync_courses($userid = "*")
|
|
|
|
|
|
|
|
{
|
|
|
|
if ($this->config->courses_autocreate || $this->config->courses_autoremove) {
|
|
|
|
if ($this->config->courses_autocreate || $this->config->courses_autoremove) {
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
"Syncing courses for user {$userid}",
|
|
|
|
"Syncing courses for user {$userid}",
|
|
|
|
@ -151,12 +156,15 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $classes
|
|
|
|
* @param array $classes
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function create_courses ($courses = []) {
|
|
|
|
private function create_courses($courses = [])
|
|
|
|
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
global $DB;
|
|
|
|
if (empty($courses)) return;
|
|
|
|
if (empty($courses))
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
$courses_category = self::get_courses_category($this->config);
|
|
|
|
$courses_category = self::get_courses_category($this->config);
|
|
|
|
if (!$courses_category) return;
|
|
|
|
if (!$courses_category)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
$template = $DB->get_record(
|
|
|
|
$template = $DB->get_record(
|
|
|
|
'course',
|
|
|
|
'course',
|
|
|
|
@ -191,13 +199,16 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param array $courses Courses to remove
|
|
|
|
* @param array $courses Courses to remove
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function remove_courses ($courses = array()) {
|
|
|
|
private function remove_courses($courses = array())
|
|
|
|
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
|
|
|
|
if (empty($courses)) return;
|
|
|
|
if (empty($courses))
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
$courses_category = self::get_courses_category($this->config);
|
|
|
|
$courses_category = self::get_courses_category($this->config);
|
|
|
|
if (!$courses_category) return;
|
|
|
|
if (!$courses_category)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
$ids = array();
|
|
|
|
$ids = array();
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
foreach ($courses as $course) {
|
|
|
|
@ -228,13 +239,15 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return course object|false
|
|
|
|
* @return course object|false
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function create_course ($name, $category_id, $fullname = null, $template = 0) {
|
|
|
|
private function create_course($name, $category_id, $fullname = null, $template = 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
global $CFG;
|
|
|
|
global $CFG;
|
|
|
|
require_once($CFG->dirroot . '/course/externallib.php');
|
|
|
|
require_once($CFG->dirroot . '/course/externallib.php');
|
|
|
|
require_once($CFG->dirroot . '/course/lib.php');
|
|
|
|
require_once($CFG->dirroot . '/course/lib.php');
|
|
|
|
|
|
|
|
|
|
|
|
$course = false;
|
|
|
|
$course = false;
|
|
|
|
if ($fullname === null) $fullname = $course;
|
|
|
|
if ($fullname === null)
|
|
|
|
|
|
|
|
$fullname = $course;
|
|
|
|
|
|
|
|
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
"Creating course {$fullname} @{$name} in category {$category_id} with template {$template}",
|
|
|
|
"Creating course {$fullname} @{$name} in category {$category_id} with template {$template}",
|
|
|
|
@ -290,7 +303,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @return true True on success
|
|
|
|
* @return true True on success
|
|
|
|
* @return false False on failure
|
|
|
|
* @return false False on failure
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function remove_course ($course_id) {
|
|
|
|
private function remove_course($course_id)
|
|
|
|
|
|
|
|
{
|
|
|
|
global $CFG;
|
|
|
|
global $CFG;
|
|
|
|
require_once($CFG->libdir . '/moodlelib.php');
|
|
|
|
require_once($CFG->libdir . '/moodlelib.php');
|
|
|
|
return delete_course($course_id);
|
|
|
|
return delete_course($course_id);
|
|
|
|
@ -304,7 +318,11 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @return array Associative array of internal group name and group description
|
|
|
|
* @return array Associative array of internal group name and group description
|
|
|
|
* @return false False on failure
|
|
|
|
* @return false False on failure
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function get_courses_ldap ($userid = "*") {
|
|
|
|
private function get_courses_ldap($userid = "*")
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Used by a few conditionals below
|
|
|
|
|
|
|
|
$pattern = [];
|
|
|
|
|
|
|
|
|
|
|
|
// Create course filter
|
|
|
|
// Create course filter
|
|
|
|
if ($this->config->coursemapping_use_prefixes) {
|
|
|
|
if ($this->config->coursemapping_use_prefixes) {
|
|
|
|
$prefixes = explode(',', $this->config->coursemapping_prefixes);
|
|
|
|
$prefixes = explode(',', $this->config->coursemapping_prefixes);
|
|
|
|
@ -313,7 +331,15 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$pattern = '(|' . implode($pattern) . ')';
|
|
|
|
$pattern = '(|' . implode($pattern) . ')';
|
|
|
|
} else if ($this->config->coursemapping_use_attribute) {
|
|
|
|
} else if ($this->config->coursemapping_use_attribute) {
|
|
|
|
|
|
|
|
// If coursemapping attribute value contains a comma, treat it as list of valid attributes (OR'ed)
|
|
|
|
|
|
|
|
if (strstr($this->config->coursemapping_attribute_value, '|') !== false) {
|
|
|
|
|
|
|
|
foreach (explode('|', $this->config->coursemapping_attribute_value) as $prefix) {
|
|
|
|
|
|
|
|
$pattern[] = "({$this->config->coursemapping_attribute}={$prefix})";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
$pattern = '(|' . implode($pattern) . ')';
|
|
|
|
|
|
|
|
} else {
|
|
|
|
$pattern = "({$this->config->coursemapping_attribute}={$this->config->coursemapping_attribute_value})";
|
|
|
|
$pattern = "({$this->config->coursemapping_attribute}={$this->config->coursemapping_attribute_value})";
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
"Invalid settings, enable either coursemapping_use_prefix or coursemapping_use_attribute",
|
|
|
|
"Invalid settings, enable either coursemapping_use_prefix or coursemapping_use_attribute",
|
|
|
|
@ -340,7 +366,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @uses $USER
|
|
|
|
* @uses $USER
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function get_courses_moodle ($userid = "*") {
|
|
|
|
private function get_courses_moodle($userid = "*")
|
|
|
|
|
|
|
|
{
|
|
|
|
global $USER;
|
|
|
|
global $USER;
|
|
|
|
$return_var = array();
|
|
|
|
$return_var = array();
|
|
|
|
|
|
|
|
|
|
|
|
@ -395,7 +422,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @uses $DB
|
|
|
|
* @uses $DB
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static function get_courses_category ($config) {
|
|
|
|
private static function get_courses_category($config)
|
|
|
|
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
|
|
|
|
// Fetch category object from DB
|
|
|
|
// Fetch category object from DB
|
|
|
|
@ -465,10 +493,12 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @param true True on success
|
|
|
|
* @param true True on success
|
|
|
|
* @param false False on failure
|
|
|
|
* @param false False on failure
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function rename_courses_category ($name) {
|
|
|
|
public function rename_courses_category($name)
|
|
|
|
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
|
|
|
|
if (! $name || $name == "") return false;
|
|
|
|
if (!$name || $name == "")
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
"Renaming courses category to {$name}",
|
|
|
|
"Renaming courses category to {$name}",
|
|
|
|
@ -518,7 +548,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @return false Returns false on failure
|
|
|
|
* @return false Returns false on failure
|
|
|
|
* @uses $DB;
|
|
|
|
* @uses $DB;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static function create_category ($name, $idnumber, $description, $parent = 0, $sortorder = 0, $visible = 1) {
|
|
|
|
private static function create_category($name, $idnumber, $description, $parent = 0, $sortorder = 0, $visible = 1)
|
|
|
|
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
@ -578,7 +609,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @return array Associative array of interal group name and group description
|
|
|
|
* @return array Associative array of interal group name and group description
|
|
|
|
* @return false False on failure
|
|
|
|
* @return false False on failure
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function ldap_get_grouplist($username = "*", $group_pattern = null) {
|
|
|
|
private function ldap_get_grouplist($username = "*", $group_pattern = null)
|
|
|
|
|
|
|
|
{
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
"Started fetching groups for {$username}",
|
|
|
|
"Started fetching groups for {$username}",
|
|
|
|
"ldap_get_grouplist",
|
|
|
|
"ldap_get_grouplist",
|
|
|
|
@ -631,7 +663,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
// Iterate through all group contexts to look up any matching groups
|
|
|
|
// Iterate through all group contexts to look up any matching groups
|
|
|
|
foreach ($contexts as $context) {
|
|
|
|
foreach ($contexts as $context) {
|
|
|
|
$context = trim($context);
|
|
|
|
$context = trim($context);
|
|
|
|
if (empty ($context)) continue;
|
|
|
|
if (empty($context))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
if ($this->config->group_search_subtree) {
|
|
|
|
if ($this->config->group_search_subtree) {
|
|
|
|
// Search groups in this context and subcontexts
|
|
|
|
// Search groups in this context and subcontexts
|
|
|
|
@ -676,7 +709,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $userid ID of the user to check
|
|
|
|
* @param string $userid ID of the user to check
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function is_teacher($userid) {
|
|
|
|
private function is_teacher($userid)
|
|
|
|
|
|
|
|
{
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
"Checking user {$userid}",
|
|
|
|
"Checking user {$userid}",
|
|
|
|
"is_teacher",
|
|
|
|
"is_teacher",
|
|
|
|
@ -704,7 +738,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @return true True on success
|
|
|
|
* @return true True on success
|
|
|
|
* @return false False on failure
|
|
|
|
* @return false False on failure
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function init_teacher_array() {
|
|
|
|
private function init_teacher_array()
|
|
|
|
|
|
|
|
{
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
"Initializing array",
|
|
|
|
"Initializing array",
|
|
|
|
"init_teacher_array",
|
|
|
|
"init_teacher_array",
|
|
|
|
@ -734,7 +769,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @return string[] Array of users on success
|
|
|
|
* @return string[] Array of users on success
|
|
|
|
* @return false False on failure
|
|
|
|
* @return false False on failure
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function ldap_get_group_members ($group) {
|
|
|
|
private function ldap_get_group_members($group)
|
|
|
|
|
|
|
|
{
|
|
|
|
global $CFG, $DB;
|
|
|
|
global $CFG, $DB;
|
|
|
|
|
|
|
|
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
@ -779,7 +815,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
// Iterate trough all contexts and try to find the group there
|
|
|
|
// Iterate trough all contexts and try to find the group there
|
|
|
|
foreach ($contexts as $context) {
|
|
|
|
foreach ($contexts as $context) {
|
|
|
|
$context = trim($context);
|
|
|
|
$context = trim($context);
|
|
|
|
if (empty ($context)) continue;
|
|
|
|
if (empty($context))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
"LDAP Search in {$context} filters {$group_query}",
|
|
|
|
"LDAP Search in {$context} filters {$group_query}",
|
|
|
|
@ -809,7 +846,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
$member = trim($entry[$group_member_attribute][$g]);
|
|
|
|
$member = trim($entry[$group_member_attribute][$g]);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip blank members
|
|
|
|
// Skip blank members
|
|
|
|
if ($member == "") continue;
|
|
|
|
if ($member == "")
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// Grab CN from DN if necessary
|
|
|
|
// Grab CN from DN if necessary
|
|
|
|
if ($this->config->group_member_attribute_is_dn) {
|
|
|
|
if ($this->config->group_member_attribute_is_dn) {
|
|
|
|
@ -889,7 +927,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @return string[] Array of users on success
|
|
|
|
* @return string[] Array of users on success
|
|
|
|
* @return false False on failure
|
|
|
|
* @return false False on failure
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function ldap_get_role_members ($role) {
|
|
|
|
private function ldap_get_role_members($role)
|
|
|
|
|
|
|
|
{
|
|
|
|
global $CFG, $DB;
|
|
|
|
global $CFG, $DB;
|
|
|
|
|
|
|
|
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
@ -936,7 +975,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
// Iterate trough all contexts and try to find the role there
|
|
|
|
// Iterate trough all contexts and try to find the role there
|
|
|
|
foreach ($contexts as $context) {
|
|
|
|
foreach ($contexts as $context) {
|
|
|
|
$context = trim($context);
|
|
|
|
$context = trim($context);
|
|
|
|
if (empty ($context)) continue;
|
|
|
|
if (empty($context))
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
"LDAP Search in {$context} filters {$role_query}",
|
|
|
|
"LDAP Search in {$context} filters {$role_query}",
|
|
|
|
@ -966,7 +1006,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
$member = trim($entry[$role_member_attribute][$g]);
|
|
|
|
$member = trim($entry[$role_member_attribute][$g]);
|
|
|
|
|
|
|
|
|
|
|
|
// Skip blank members
|
|
|
|
// Skip blank members
|
|
|
|
if ($member == "") continue;
|
|
|
|
if ($member == "")
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
|
|
// Grab CN from DN if necessary
|
|
|
|
// Grab CN from DN if necessary
|
|
|
|
if ($this->config->role_member_attribute_is_dn) {
|
|
|
|
if ($this->config->role_member_attribute_is_dn) {
|
|
|
|
@ -1046,7 +1087,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return string CN of the DN
|
|
|
|
* @return string CN of the DN
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function get_cn_from_dn ($dn) {
|
|
|
|
private function get_cn_from_dn($dn)
|
|
|
|
|
|
|
|
{
|
|
|
|
preg_match("~^cn=(.*?),~", $dn, $matches);
|
|
|
|
preg_match("~^cn=(.*?),~", $dn, $matches);
|
|
|
|
if (count($matches) == 2) {
|
|
|
|
if (count($matches) == 2) {
|
|
|
|
return $matches[1];
|
|
|
|
return $matches[1];
|
|
|
|
@ -1060,7 +1102,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function ldap_generate_group_pattern() {
|
|
|
|
private function ldap_generate_group_pattern()
|
|
|
|
|
|
|
|
{
|
|
|
|
$pattern[] = "(objectClass={$this->config->group_object_class})";
|
|
|
|
$pattern[] = "(objectClass={$this->config->group_object_class})";
|
|
|
|
$pattern = '(|' . implode($pattern) . ')';
|
|
|
|
$pattern = '(|' . implode($pattern) . ')';
|
|
|
|
return $pattern;
|
|
|
|
return $pattern;
|
|
|
|
@ -1071,9 +1114,11 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param string $userid
|
|
|
|
* @param string $userid
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function sync_course_enrolments_user ($userid) {
|
|
|
|
public function sync_course_enrolments_user($userid)
|
|
|
|
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
global $DB;
|
|
|
|
if (!$userid) return;
|
|
|
|
if (!$userid)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
self::debuglog(
|
|
|
|
self::debuglog(
|
|
|
|
"Syncing course enrolments for {$userid}",
|
|
|
|
"Syncing course enrolments for {$userid}",
|
|
|
|
@ -1123,7 +1168,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Ensures proper user enrolment for all IServ-originating courses
|
|
|
|
* Ensures proper user enrolment for all IServ-originating courses
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public function sync_course_enrolments () {
|
|
|
|
public function sync_course_enrolments()
|
|
|
|
|
|
|
|
{
|
|
|
|
$courses_category = self::get_courses_category($this->config);
|
|
|
|
$courses_category = self::get_courses_category($this->config);
|
|
|
|
if (!$courses_category) {
|
|
|
|
if (!$courses_category) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
@ -1156,7 +1202,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @param context $context Course context
|
|
|
|
* @param context $context Course context
|
|
|
|
* @return string[] Array of enrolled usernames
|
|
|
|
* @return string[] Array of enrolled usernames
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static function get_enrolled_usernames ($context) {
|
|
|
|
private static function get_enrolled_usernames($context)
|
|
|
|
|
|
|
|
{
|
|
|
|
$moodle_user_objects = get_enrolled_users($context);
|
|
|
|
$moodle_user_objects = get_enrolled_users($context);
|
|
|
|
$enrolled = array();
|
|
|
|
$enrolled = array();
|
|
|
|
|
|
|
|
|
|
|
|
@ -1174,7 +1221,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return stdClass Enrol instance
|
|
|
|
* @return stdClass Enrol instance
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function get_enrol_instance($course) {
|
|
|
|
private function get_enrol_instance($course)
|
|
|
|
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
|
|
|
|
$enrol_instance = $DB->get_record(
|
|
|
|
$enrol_instance = $DB->get_record(
|
|
|
|
@ -1211,7 +1259,8 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @param array $current_state Array with currently enrolled users
|
|
|
|
* @param array $current_state Array with currently enrolled users
|
|
|
|
* @param array $new_state Array with users that shall be enrolled afterwards
|
|
|
|
* @param array $new_state Array with users that shall be enrolled afterwards
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function course_enrolunenrol ($course, $enrol_instance, $current_state, $new_state) {
|
|
|
|
private function course_enrolunenrol($course, $enrol_instance, $current_state, $new_state)
|
|
|
|
|
|
|
|
{
|
|
|
|
$to_enrol = array_diff($new_state, $current_state);
|
|
|
|
$to_enrol = array_diff($new_state, $current_state);
|
|
|
|
$to_unenrol = array_diff($current_state, $new_state);
|
|
|
|
$to_unenrol = array_diff($current_state, $new_state);
|
|
|
|
$to_enrol_teachers = array();
|
|
|
|
$to_enrol_teachers = array();
|
|
|
|
@ -1273,10 +1322,12 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @param array $users Array of usernames to enrol
|
|
|
|
* @param array $users Array of usernames to enrol
|
|
|
|
* @param int $role ID of role to assign to users
|
|
|
|
* @param int $role ID of role to assign to users
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function course_enrol ($course, $enrol_instance, $users, $role) {
|
|
|
|
private function course_enrol($course, $enrol_instance, $users, $role)
|
|
|
|
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
global $DB;
|
|
|
|
|
|
|
|
|
|
|
|
if (!is_array($users)) $users = array($users);
|
|
|
|
if (!is_array($users))
|
|
|
|
|
|
|
|
$users = array($users);
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($users as $username) {
|
|
|
|
foreach ($users as $username) {
|
|
|
|
$user = $DB->get_record(
|
|
|
|
$user = $DB->get_record(
|
|
|
|
@ -1311,9 +1362,11 @@ class enrol_iserv_plugin extends enrol_plugin {
|
|
|
|
* @param stdClass $enrol_instance Enrol instance to use for Unenrolling
|
|
|
|
* @param stdClass $enrol_instance Enrol instance to use for Unenrolling
|
|
|
|
* @param array $users Array of usernames to unenrol
|
|
|
|
* @param array $users Array of usernames to unenrol
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private function course_unenrol ($course, $enrol_instance, $users) {
|
|
|
|
private function course_unenrol($course, $enrol_instance, $users)
|
|
|
|
|
|
|
|
{
|
|
|
|
global $DB;
|
|
|
|
global $DB;
|
|
|
|
if (!is_array($users)) $users = array($users);
|
|
|
|
if (!is_array($users))
|
|
|
|
|
|
|
|
$users = array($users);
|
|
|
|
|
|
|
|
|
|
|
|
foreach ($users as $username) {
|
|
|
|
foreach ($users as $username) {
|
|
|
|
$user = $DB->get_record(
|
|
|
|
$user = $DB->get_record(
|
|
|
|
|