first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-09-30 18:11:26 -04:00
commit e592ca6823
27270 changed files with 5002257 additions and 0 deletions
@@ -0,0 +1,41 @@
<?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 Subsystem implementation for enrol_imsenterprise.
*
* @package enrol_imsenterprise
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_imsenterprise\privacy;
defined('MOODLE_INTERNAL') || die();
/**
* Privacy Subsystem for enrol_imsenterprise implementing null_provider.
*
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class provider implements \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';
}
}
@@ -0,0 +1,54 @@
<?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/>.
/**
* A scheduled task.
*
* @package enrol_imsenterprise
* @copyright 2014 Universite de Montreal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace enrol_imsenterprise\task;
/**
* Simple task to run the IMS Enterprise enrolment cron.
*
* @copyright 2014 Universite de Montreal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cron_task extends \core\task\scheduled_task {
/**
* Get a descriptive name for this task (shown to admins).
*
* @return string
*/
public function get_name() {
return get_string('imsenterprisecrontask', 'enrol_imsenterprise');
}
/**
* Do the job.
* Throw exceptions on errors (the job will be retried).
*/
public function execute() {
global $CFG;
require_once($CFG->dirroot . '/enrol/imsenterprise/lib.php');
$ims = new \enrol_imsenterprise_plugin();
$ims->cron();
}
}
+37
View File
@@ -0,0 +1,37 @@
<?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/>.
/**
* Capabilities for imsenterprise enrolment plugin.
*
* @package enrol_imsenterprise
* @copyright 2014 Daniel Neis Araujo
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$capabilities = array(
'enrol/imsenterprise:config' => array(
'captype' => 'write',
'contextlevel' => CONTEXT_COURSE,
'archetypes' => array(
'manager' => CAP_ALLOW,
'editingteacher' => CAP_ALLOW,
)
),
);
+33
View File
@@ -0,0 +1,33 @@
<?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/>.
/**
* imsenterprise enrolment plugin installation.
*
* @package enrol_imsenterprise
* @copyright 2011 Petr Skoda {@link http://skodak.org}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Post installation procedure
*/
function xmldb_enrol_imsenterprise_install() {
global $CFG, $DB;
}
+34
View File
@@ -0,0 +1,34 @@
<?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/>.
/**
* Defines message providers (types of message sent) for the PayPal enrolment plugin.
*
* @package enrol_imsenterprise
* @copyright 2012 Andrew Davis
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$messageproviders = array(
'imsenterprise_enrolment' => [
'defaults' => [
'popup' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED,
'email' => MESSAGE_PERMITTED + MESSAGE_DEFAULT_ENABLED,
],
],
);
+38
View File
@@ -0,0 +1,38 @@
<?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/>.
/**
* Definition of IMS Enterprise enrolment scheduled tasks.
*
* @package enrol_imsenterprise
* @category task
* @copyright 2014 Universite de Montreal
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$tasks = array(
array(
'classname' => 'enrol_imsenterprise\task\cron_task',
'blocking' => 0,
'minute' => '10',
'hour' => '*',
'day' => '*',
'month' => '*',
'dayofweek' => '*'
)
);
+45
View File
@@ -0,0 +1,45 @@
<?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/>.
/**
* This file keeps track of upgrades to the imsenterprise enrolment plugin
*
* @package enrol_imsenterprise
* @copyright 2011 Petr Skoda (http://skodak.org)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
/**
* Performs upgrade of the database structure and data
*
* @param int $oldversion the version we are upgrading from
* @return bool true
*/
function xmldb_enrol_imsenterprise_upgrade($oldversion) {
// Automatically generated Moodle v4.1.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.2.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.3.0 release upgrade line.
// Put any upgrade step following this.
// Automatically generated Moodle v4.4.0 release upgrade line.
// Put any upgrade step following this.
return true;
}
@@ -0,0 +1,171 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<enterprise>
<properties lang="EN"><!-- ccc -->
<datasource>sits:vision</datasource>
<datetime>28/Oct/2005</datetime>
<target>moodle</target>
</properties>
<person>
<sourcedid>
<source>sits:vision</source>
<id>91046433</id>
</sourcedid>
<userid/>
<name>
<fn>Simon Shikalislami </fn>
<n>
<family> SHIKALISLAMI</family>
<given> SIMON</given>
</n>
</name>
<extension>
<webcredential/>
</extension>
</person>
<person recstatus = "1">
<sourcedid>
<source>sits:vision</source>
<id>90078058</id>
</sourcedid>
<userid>IMGBY26</userid>
<name>
<fn>Chloe Eva Piotrowska </fn>
<n>
<family> PIOTROWSKA</family>
<given> CHLOE</given>
</n>
</name>
<extension>
<webcredential/>
</extension>
</person>
<person>
<sourcedid>
<source>sits:vision</source>
<id>90182274</id>
</sourcedid>
<userid>IMCAY21</userid>
<name>
<fn>Aliza Quist Yeboah </fn>
<n>
<family> YEBOAH</family>
<given> ALIZA</given>
</n>
</name>
<extension>
<webcredential/>
</extension>
</person>
<person>
<sourcedid>
<source>sits:vision</source>
<id>90528553</id>
</sourcedid>
<userid>IMGBX76</userid>
<name>
<fn>Miriam Rajakumar </fn>
<n>
<family> RAJAKUMAR</family>
<given> MIRIAM</given>
</n>
</name>
<extension>
<webcredential/>
</extension>
</person>
<person>
<sourcedid>
<source>sits:vision</source>
<id>DSTOW61</id>
</sourcedid>
<userid>CCAADAS</userid>
<name>
<fn>Dan Stowell</fn>
<n>
<family> STOWELL</family>
<given> DAN</given>
</n>
</name>
<extension>
<webcredential/>
</extension>
</person>
<group recstatus="3">
<sourcedid>
<source>sits:vision</source>
<id>PHRE1001A2005/06T1/2</id>
</sourcedid>
<description>
<short>Phrenology</short>
</description>
<extension>
<template>Blank</template>
</extension>
<org><orgunit>Inconsequential studies</orgunit></org>
</group>
<membership>
<sourcedid>
<source>sits:vision</source>
<id>PHRE1001A2005/06T1/2</id>
</sourcedid>
<member>
<sourcedid>
<source>sits:vision</source>
<id> 91046433 </id>
</sourcedid>
<idtype idtype="1"/>
<role roletype="01">
<userid/>
<status>1</status>
<extension><cohort>yellow team</cohort></extension>
</role>
</member>
<member>
<sourcedid>
<source>sits:vision</source>
<id> 90078058 </id>
</sourcedid>
<idtype idtype="1"/>
<role roletype="01" recstatus="3">
<userid>IMGBY26</userid>
<status>1</status>
<extension><cohort>green team</cohort></extension>
</role>
</member>
<member>
<sourcedid>
<source>sits:vision</source>
<id> 90182274 </id>
</sourcedid>
<idtype idtype="1"/>
<role roletype="01">
<userid>IMCAY21</userid>
<status>1</status>
<extension><cohort>green team</cohort></extension>
</role>
</member>
<member>
<sourcedid>
<source>sits:vision</source>
<id> 90528553 </id>
</sourcedid>
<idtype idtype="1"/>
<role roletype="01">
<userid>IMGBX76</userid>
<status>1</status><timeframe><begin restrict="1">2005-12-25</begin><end restrict="1">2005-12-31</end></timeframe>
<extension><cohort>yellow team</cohort></extension>
</role>
</member>
<member>
<sourcedid>
<source>sits:vision</source>
<id>DSTOW61 </id>
</sourcedid>
<idtype idtype="1"/>
<role roletype="02" recstatus="2">
<userid>CCAADAS</userid>
<status>1</status>
</role>
</member>
</membership>
</enterprise>
@@ -0,0 +1 @@
<?xml version="1.0" encoding="ISO-8859-1"?><enterprise><properties lang="EN"><datasource>sits:vision</datasource><datetime>28/Oct/2005</datetime></properties><person><sourcedid><source>sits:vision</source><id>91046433</id></sourcedid><userid/><name><fn>Simon Shikalislami </fn><n><family> SHIKALISLAMI</family><given> SIMON</given></n></name><extension><webcredential/></extension></person><person><sourcedid><source>sits:vision</source><id>90078058</id></sourcedid><userid>IMGBY26</userid><name><fn>Chloe Eva Piotrowska </fn><n><family> PIOTROWSKA</family><given> CHLOE</given></n></name><extension><webcredential/></extension></person><person><sourcedid><source>sits:vision</source><id>90182274</id></sourcedid><userid>IMCAY21</userid><name><fn>Aliza Quist Yeboah </fn><n><family> YEBOAH</family><given> ALIZA</given></n></name><extension><webcredential/></extension></person><person><sourcedid><source>sits:vision</source><id>90528553</id></sourcedid><userid>IMGBX76</userid><name><fn>Miriam Rajakumar </fn><n><family> RAJAKUMAR</family><given> MIRIAM</given></n></name><extension><webcredential/></extension></person><person><sourcedid><source>sits:vision</source><id>DSTOW61</id></sourcedid><userid>CCAADAS</userid><name><fn>Dan Stowell</fn><n><family> STOWELL</family><given> DAN</given></n></name><extension><webcredential/></extension></person><group><sourcedid><source>sits:vision</source><id>PHRE1001A2005/06T1/2</id></sourcedid><description><short>Phrenology</short></description><extension><template>Blank</template></extension></group><membership><sourcedid><source>sits:vision</source><id>PHRE1001A2005/06T1/2</id></sourcedid><member><sourcedid><source>sits:vision</source><id> 91046433 </id></sourcedid><idtype idtype="1"/><role roletype="01"><userid/><status>1</status></role></member><member><sourcedid><source>sits:vision</source><id> 90078058 </id></sourcedid><idtype idtype="1"/><role roletype="01"><userid>IMGBY26</userid><status>1</status></role></member><member><sourcedid><source>sits:vision</source><id> 90182274 </id></sourcedid><idtype idtype="1"/><role roletype="01"><userid>IMCAY21</userid><status>1</status></role></member><member><sourcedid><source>sits:vision</source><id> 90528553 </id></sourcedid><idtype idtype="1"/><role roletype="01"><userid>IMGBX76</userid><status>1</status></role></member><member><sourcedid><source>sits:vision</source><id>DSTOW61 </id></sourcedid><idtype idtype="1"/><role roletype="02"><userid>CCAADAS</userid><status>1</status></role></member></membership></enterprise>
+166
View File
@@ -0,0 +1,166 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<enterprise>
<properties lang="EN"><!-- c -->
<datasource>sits:vision</datasource>
<datetime>28/Oct/2005</datetime>
</properties>
<person>
<sourcedid>
<source>sits:vision</source>
<id>91046433</id>
</sourcedid>
<userid/>
<name>
<fn>Simon Shikalislami </fn>
<n>
<family> SHIKALISLAMI</family>
<given> SIMON</given>
</n>
</name>
<extension>
<webcredential/>
</extension>
</person>
<person>
<sourcedid>
<source>sits:vision</source>
<id>90078058</id>
</sourcedid>
<userid>IMGBY26</userid>
<name>
<fn>Chloe Eva Piotrowska </fn>
<n>
<family> PIOTROWSKA</family>
<given> CHLOE</given>
</n>
</name>
<extension>
<webcredential/>
</extension>
</person>
<person>
<sourcedid>
<source>sits:vision</source>
<id>90182274</id>
</sourcedid>
<userid>IMCAY21</userid>
<name>
<fn>Aliza Quist Yeboah </fn>
<n>
<family> YEBOAH</family>
<given> ALIZA</given>
</n>
</name>
<extension>
<webcredential/>
</extension>
</person>
<person>
<sourcedid>
<source>sits:vision</source>
<id>90528553</id>
</sourcedid>
<userid>IMGBX76</userid>
<name>
<fn>Miriam Rajakumar </fn>
<n>
<family> RAJAKUMAR</family>
<given> MIRIAM</given>
</n>
</name>
<extension>
<webcredential/>
</extension>
</person>
<person>
<sourcedid>
<source>sits:vision</source>
<id>DSTOW61</id>
</sourcedid>
<userid>CCAADAS</userid>
<name>
<fn>Dan Stowell</fn>
<n>
<family> STOWELL</family>
<given> DAN</given>
</n>
</name>
<extension>
<webcredential/>
</extension>
</person>
<group>
<sourcedid>
<source>sits:vision</source>
<id>PHRE1001A2005/06T1/2</id>
</sourcedid>
<description>
<short>Phrenology</short>
</description>
<extension>
<template>Blank</template>
</extension>
<org><orgunit>Inconsequential studies</orgunit></org>
</group>
<membership>
<sourcedid>
<source>sits:vision</source>
<id>PHRE1001A2005/06T1/2</id>
</sourcedid>
<member>
<sourcedid>
<source>sits:vision</source>
<id> 91046433 </id>
</sourcedid>
<idtype idtype="1"/>
<role roletype="01">
<userid/>
<status>1</status>
</role>
</member>
<member>
<sourcedid>
<source>sits:vision</source>
<id> 90078058 </id>
</sourcedid>
<idtype idtype="1"/>
<role roletype="01">
<userid>IMGBY26</userid>
<status>1</status>
</role>
</member>
<member>
<sourcedid>
<source>sits:vision</source>
<id> 90182274 </id>
</sourcedid>
<idtype idtype="1"/>
<role roletype="01">
<userid>IMCAY21</userid>
<status>1</status>
</role>
</member>
<member>
<sourcedid>
<source>sits:vision</source>
<id> 90528553 </id>
</sourcedid>
<idtype idtype="1"/>
<role roletype="01">
<userid>IMGBX76</userid>
<status>1</status>
</role>
</member>
<member>
<sourcedid>
<source>sits:vision</source>
<id>DSTOW61 </id>
</sourcedid>
<idtype idtype="1"/>
<role roletype="02">
<userid>CCAADAS</userid>
<status>1</status>
</role>
</member>
</membership>
</enterprise>
+57
View File
@@ -0,0 +1,57 @@
<?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/>.
/**
* Import IMS Enterprise file immediately.
*
* @package enrol_imsenterprise
* @copyright 2006 Dan Stowell
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require(__DIR__.'/../../config.php');
require_login(0, false);
require_capability('moodle/site:config', context_system::instance());
require_sesskey();
$site = get_site();
// Get language strings.
$PAGE->set_context(context_system::instance());
$PAGE->set_url('/enrol/imsenterprise/importnow.php');
$PAGE->set_title(get_string('importimsfile', 'enrol_imsenterprise'));
$PAGE->set_heading(get_string('importimsfile', 'enrol_imsenterprise'));
$PAGE->navbar->add(get_string('administrationsite'));
$PAGE->navbar->add(get_string('plugins', 'admin'));
$PAGE->navbar->add(get_string('enrolments', 'enrol'));
$PAGE->navbar->add(get_string('pluginname', 'enrol_imsenterprise'),
new moodle_url('/admin/settings.php', array('section' => 'enrolsettingsimsenterprise')));
$PAGE->navbar->add(get_string('importimsfile', 'enrol_imsenterprise'));
$PAGE->navigation->clear_cache();
echo $OUTPUT->header();
require_once('lib.php');
$enrol = new enrol_imsenterprise_plugin();
?>
<p>Launching the IMS Enterprise "cron" function. The import log will appear below (giving details of any
problems that might require attention).</p>
<pre style="margin:10px; padding: 2px; border: 1px solid black; background-color: white; color: black;"><?php
$enrol->cron();
?></pre><?php
echo $OUTPUT->footer();
@@ -0,0 +1,101 @@
<?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/>.
/**
* Strings for component 'enrol_imsenterprise', language 'en'.
*
* @package enrol_imsenterprise
* @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
$string['aftersaving...'] = 'Once you have saved your settings, you may wish to';
$string['allowunenrol'] = 'Allow IMS data to unenrol students and teachers';
$string['allowunenrol_desc'] = 'If enabled, course enrolments will be removed when specified in the Enterprise data.';
$string['basicsettings'] = 'Basic settings';
$string['categoryidnumber'] = 'Allow category ID number';
$string['categoryidnumber_desc'] = 'If enabled IMS Enterprise will create a category with ID number.';
$string['categoryseparator'] = 'Category separator character';
$string['categoryseparator_desc'] = 'Required when \'Allow category ID number\' is enabled. Character to separate the category name and ID number.';
$string['coursesettings'] = 'Course data options';
$string['createnewcategories'] = 'Create new (hidden) course categories if not found in Moodle';
$string['createnewcategories_desc'] = 'If the &lt;org&gt;&lt;orgunit&gt; element is present in a course\'s incoming data, its content will be used to specify a category if the course is to be created from scratch. The plugin will NOT re-categorise existing courses.
If no category exists with the desired name, then a hidden category will be created.';
$string['createnewcourses'] = 'Create new (hidden) courses if not found in Moodle';
$string['createnewcourses_desc'] = 'If enabled, the IMS Enterprise enrolment plugin can create new courses for any it finds in the IMS data but not in Moodle\'s database. Any newly-created courses are initially hidden.';
$string['createnewusers'] = 'Create user accounts for users not yet registered in Moodle';
$string['createnewusers_desc'] = 'IMS Enterprise enrolment data typically describes a set of users. If enabled, accounts can be created for any users not found in the Moodle database.
Users are searched for first by their ID number, and then by their Moodle username. Passwords are not imported by the IMS Enterprise plugin. The use of an authentication plugin is recommended for authenticating users.';
$string['cronfrequency'] = 'Frequency of processing';
$string['deleteusers'] = 'Delete user accounts when specified in IMS data';
$string['deleteusers_desc'] = 'If enabled, IMS Enterprise enrolment data can specify the deletion of user accounts (if the "recstatus" flag is set to 3, which represents deletion of an account). As is standard in Moodle, the user record isn\'t actually deleted from Moodle\'s database, but a flag is set to mark the account as deleted.';
$string['doitnow'] = 'perform an IMS Enterprise import right now';
$string['emptyattribute'] = 'Leave it empty';
$string['filelockedmail'] = 'The text file you are using for IMS-file-based enrolments ({$a}) can not be deleted by the cron process. This usually means the permissions are wrong on it. Please fix the permissions so that Moodle can delete the file, otherwise it might be processed repeatedly.';
$string['filelockedmailsubject'] = 'Important error: Enrolment file';
$string['fixcasepersonalnames'] = 'Change personal names to Title Case';
$string['fixcaseusernames'] = 'Change usernames to lower case';
$string['imsenterprisecrontask'] = 'Enrolment file processing';
$string['imsenterprise:config'] = 'Configure IMS Enterprise enrol instances';
$string['imsrolesdescription'] = 'The IMS Enterprise specification includes 8 distinct role types. Please choose how you want them to be assigned in Moodle, including whether any of them should be ignored.';
$string['location'] = 'File location';
$string['logtolocation'] = 'Log file output location (blank for no logging)';
$string['mailadmins'] = 'Notify admin by email';
$string['mailusers'] = 'Notify users by email';
$string['messageprovider:imsenterprise_enrolment'] = 'IMS Enterprise enrolment messages';
$string['miscsettings'] = 'Miscellaneous';
$string['nestedcategories'] = 'Allow nested categories';
$string['nestedcategories_desc'] = 'If enabled IMS Enterprise will create nested categories';
$string['pluginname'] = 'IMS Enterprise file';
$string['pluginname_desc'] = 'This method will repeatedly check for and process a specially-formatted text file in the location that you specify. The file must follow the IMS Enterprise specifications containing person, group, and membership XML elements.';
$string['processphoto'] = 'Add user photo data to profile';
$string['processphotowarning'] = 'Warning: Image processing is likely to add a significant burden to the server. You are recommended not to activate this option if large numbers of students are expected to be processed.';
$string['restricttarget'] = 'Only process data if the following target is specified';
$string['restricttarget_desc'] = 'An IMS Enterprise data file could be intended for multiple "targets" - different LMSes, or different systems within a school/university. It\'s possible to specify in the Enterprise file that the data is intended for one or more named target systems, by naming them in <target> tags contained within the <properties> tag.
In general you don\'t need to worry about this. Leave the setting blank and Moodle will always process the data file, no matter whether a target is specified or not. Otherwise, fill in the exact name that will be output inside the <target> tag.';
$string['settingfullname'] = 'IMS description tag for the course full name';
$string['settingfullnamedescription'] = 'The full name is a required course field so you have to define the selected description tag in your IMS Enterprise file';
$string['settingshortname'] = 'IMS description tag for the course short name';
$string['settingshortnamedescription'] = 'The short name is a required course field so you have to define the selected description tag in your IMS Enterprise file';
$string['settingsummary'] = 'IMS description tag for the course summary';
$string['settingsummarydescription'] = 'Is an optional field, select \'Leave it empty\' if you dont\'t want to specify a course summary';
$string['sourcedidfallback'] = 'Use the \'sourcedid\' for a user\'s userid if the \'userid\' field is not found';
$string['sourcedidfallback_desc'] = 'In IMS data, the <sourcedid> field represents the persistent ID code for a person as used in the source system. The <userid> field is a separate field which should contain the ID code used by the user when logging in. In many cases these two codes may be the same - but not always.
Some student information systems fail to output the <userid> field. If this is the case, you should enable this setting to allow for using the <sourcedid> as the Moodle user ID. Otherwise, leave this setting disabled.';
$string['truncatecoursecodes'] = 'Truncate course codes to this length';
$string['truncatecoursecodes_desc'] = 'In some situations you may have course codes which you wish to truncate to a specified length before processing. If so, enter the number of characters in this box. Otherwise, leave the box blank and no truncation will occur.';
$string['updatecourses'] = 'Update course';
$string['updatecourses_desc'] = 'If enabled, the IMS Enterprise enrolment plugin can update course full and short names (if the "recstatus" flag is set to 2, which represents an update).';
$string['updateusers'] = 'Update user accounts when specified in IMS data';
$string['updateusers_desc'] = 'If enabled, IMS Enterprise enrolment data can specify changes to user accounts (if the "recstatus" flag is set to 2, which represents an update).';
$string['usecapitafix'] = 'Tick this box if using Capita (as their XML format is slightly different)';
$string['usecapitafix_desc'] = 'The student data system produced by Capita has been found to have one slight error in its XML output. If you are using Capita you should enable this setting - otherwise leave it un-ticked.';
$string['usersettings'] = 'User data options';
$string['zeroisnotruncation'] = '0 indicates no truncation';
$string['roles'] = 'Roles';
$string['ignore'] = 'Ignore';
$string['importimsfile'] = 'Import IMS Enterprise file';
$string['privacy:metadata'] = 'The IMS Enterprise file enrolment plugin does not store any personal data.';
$string['unenrolaction'] = 'Unenrol action';
$string['unenrolaction_desc'] = 'Action to be taken when a user is unenrolled from a course (only applies when the unenrol setting above is enabled).';
$string['disableenrolonly'] = 'Suspend enrolment only';
$string['disableenrolmentandremoveallroles'] = 'Suspend enrolment and remove roles';
$string['noaction'] = 'No action';
$string['removeenrolmentandallroles'] = 'Delete enrolment and roles';
File diff suppressed because it is too large Load Diff
+170
View File
@@ -0,0 +1,170 @@
<?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/>.
/**
* IMS Enterprise enrol plugin implementation.
*
* @package enrol_imsenterprise
* @copyright 2010 Eugene Venter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* Class for dealing with role mappings in IMS Enterprise.
*
* @copyright 2010 Eugene Venter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class imsenterprise_roles {
/** @var imscode => ims role name. Role name mapping. */
private $imsroles;
/**
* Constructor.
*/
public function __construct() {
$this->imsroles = array(
'01' => 'Learner',
'02' => 'Instructor',
'03' => 'Content Developer',
'04' => 'Member',
'05' => 'Manager',
'06' => 'Mentor',
'07' => 'Administrator',
'08' => 'TeachingAssistant',
);
// PLEASE NOTE: It may seem odd that "Content Developer" has a space in it
// but "TeachingAssistant" doesn't. That's what the spec says though!!!
}
/**
* Returns the mapped roles
*
* @return array of IMS roles indexed by IMS code.
*/
public function get_imsroles() {
return $this->imsroles;
}
/**
* This function is only used when first setting up the plugin, to
* decide which role assignments to recommend by default.
* For example, IMS role '01' is 'Learner', so may map to 'student' in Moodle.
*
* @param string $imscode
*/
public function determine_default_rolemapping($imscode) {
global $DB;
switch($imscode) {
case '01':
case '04':
$shortname = 'student';
break;
case '06':
case '08':
$shortname = 'teacher';
break;
case '02':
case '03':
$shortname = 'editingteacher';
break;
case '05':
case '07':
$shortname = 'admin';
break;
default:
return 0; // Zero for no match.
}
return (string)$DB->get_field('role', 'id', array('shortname' => $shortname));
}
}
/**
* Mapping between Moodle course attributes and IMS enterprise group description tags
*
* @package enrol_imsenterprise
* @copyright 2011 Aaron C Spike
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class imsenterprise_courses {
/** @var array IMS group description names */
private $imsnames;
/** @var array moodle course field names */
private $courseattrs;
/**
* Loads default
*/
public function __construct() {
$this->imsnames = array(
'short' => 'short',
'long' => 'long',
'full' => 'full',
'coursecode' => 'coursecode');
$this->courseattrs = array('shortname', 'fullname', 'summary');
}
/**
* Returns the assignable values for the course attribute
* @param string $courseattr The course attribute (shortname, fullname...)
* @return array Array of assignable values
*/
public function get_imsnames($courseattr) {
$values = $this->imsnames;
if ($courseattr == 'summary') {
$values = array_merge(array('ignore' => get_string('emptyattribute', 'enrol_imsenterprise')), $values);
}
return $values;
}
/**
* courseattrs getter
* @return array
*/
public function get_courseattrs() {
return $this->courseattrs;
}
/**
* This function is only used when first setting up the plugin, to
* decide which name assignments to recommend by default.
*
* @param string $courseattr
* @return string
*/
public function determine_default_coursemapping($courseattr) {
switch($courseattr) {
case 'fullname':
$imsname = 'short';
break;
case 'shortname':
$imsname = 'coursecode';
break;
default:
$imsname = 'ignore';
}
return $imsname;
}
}
+157
View File
@@ -0,0 +1,157 @@
<?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/>.
/**
* IMS Enterprise enrolments plugin settings and presets.
*
* @package enrol_imsenterprise
* @copyright 2010 Eugene Venter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
if ($ADMIN->fulltree) {
require_once($CFG->dirroot.'/enrol/imsenterprise/locallib.php');
$settings->add(new admin_setting_heading('enrol_imsenterprise_settings', '',
get_string('pluginname_desc', 'enrol_imsenterprise')));
// General settings.
$settings->add(new admin_setting_heading('enrol_imsenterprise_basicsettings',
get_string('basicsettings', 'enrol_imsenterprise'), ''));
$settings->add(new admin_setting_configtext('enrol_imsenterprise/imsfilelocation',
get_string('location', 'enrol_imsenterprise'), '', ''));
$settings->add(new admin_setting_configtext('enrol_imsenterprise/logtolocation',
get_string('logtolocation', 'enrol_imsenterprise'), '', ''));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/mailadmins',
get_string('mailadmins', 'enrol_imsenterprise'), '', 0));
// User data options.
$settings->add(new admin_setting_heading('enrol_imsenterprise_usersettings',
get_string('usersettings', 'enrol_imsenterprise'), ''));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/createnewusers',
get_string('createnewusers', 'enrol_imsenterprise'), get_string('createnewusers_desc', 'enrol_imsenterprise'), 0));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/imsupdateusers',
get_string('updateusers', 'enrol_imsenterprise'), get_string('updateusers_desc', 'enrol_imsenterprise'), 0));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/imsdeleteusers',
get_string('deleteusers', 'enrol_imsenterprise'), get_string('deleteusers_desc', 'enrol_imsenterprise'), 0));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/fixcaseusernames',
get_string('fixcaseusernames', 'enrol_imsenterprise'), '', 0));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/fixcasepersonalnames',
get_string('fixcasepersonalnames', 'enrol_imsenterprise'), '', 0));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/imssourcedidfallback',
get_string('sourcedidfallback', 'enrol_imsenterprise'), get_string('sourcedidfallback_desc', 'enrol_imsenterprise'), 0));
$settings->add(new admin_setting_heading('enrol_imsenterprise_usersettings_roles',
get_string('roles', 'enrol_imsenterprise'), get_string('imsrolesdescription', 'enrol_imsenterprise')));
if (!during_initial_install()) {
$coursecontext = context_course::instance(SITEID);
$assignableroles = get_assignable_roles($coursecontext);
$assignableroles = array('0' => get_string('ignore', 'enrol_imsenterprise')) + $assignableroles;
$imsroles = new imsenterprise_roles();
foreach ($imsroles->get_imsroles() as $imsrolenum => $imsrolename) {
$settings->add(new admin_setting_configselect('enrol_imsenterprise/imsrolemap'.$imsrolenum,
format_string('"'.$imsrolename.'" ('.$imsrolenum.')'), '',
(int)$imsroles->determine_default_rolemapping($imsrolenum), $assignableroles));
}
}
// Course data options.
$settings->add(new admin_setting_heading('enrol_imsenterprise_coursesettings',
get_string('coursesettings', 'enrol_imsenterprise'), ''));
$settings->add(new admin_setting_configtext('enrol_imsenterprise/truncatecoursecodes',
get_string('truncatecoursecodes', 'enrol_imsenterprise'), get_string('truncatecoursecodes_desc', 'enrol_imsenterprise'),
0, PARAM_INT, 2));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/createnewcourses',
get_string('createnewcourses', 'enrol_imsenterprise'), get_string('createnewcourses_desc', 'enrol_imsenterprise'), 0));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/updatecourses',
get_string('updatecourses', 'enrol_imsenterprise'), get_string('updatecourses_desc', 'enrol_imsenterprise'), 0));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/createnewcategories',
get_string('createnewcategories', 'enrol_imsenterprise'), get_string('createnewcategories_desc', 'enrol_imsenterprise'),
0));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/nestedcategories',
get_string('nestedcategories', 'enrol_imsenterprise'), get_string('nestedcategories_desc', 'enrol_imsenterprise'), 0));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/categoryidnumber',
get_string('categoryidnumber', 'enrol_imsenterprise'), get_string('categoryidnumber_desc', 'enrol_imsenterprise'), 0));
$settings->add(new admin_setting_configtext('enrol_imsenterprise/categoryseparator',
get_string('categoryseparator', 'enrol_imsenterprise'), get_string('categoryseparator_desc', 'enrol_imsenterprise'), '',
PARAM_TEXT, 3));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/imsunenrol',
get_string('allowunenrol', 'enrol_imsenterprise'), get_string('allowunenrol_desc', 'enrol_imsenterprise'), 0));
/* Action to take when a request to remove a user enrolment record is detected in the IMS file */
$options = [
ENROL_EXT_REMOVED_KEEP => get_string('noaction', 'enrol_imsenterprise'),
ENROL_EXT_REMOVED_UNENROL => get_string('removeenrolmentandallroles', 'enrol_imsenterprise'),
ENROL_EXT_REMOVED_SUSPEND => get_string('disableenrolonly', 'enrol_imsenterprise'),
ENROL_EXT_REMOVED_SUSPENDNOROLES => get_string('disableenrolmentandremoveallroles', 'enrol_imsenterprise'),
];
$settings->add(
new admin_setting_configselect('enrol_imsenterprise/unenrolaction',
get_string('unenrolaction', 'enrol_imsenterprise'),
get_string('unenrolaction_desc', 'enrol_imsenterprise'),
ENROL_EXT_REMOVED_UNENROL, $options)
);
if (!during_initial_install()) {
$imscourses = new imsenterprise_courses();
foreach ($imscourses->get_courseattrs() as $courseattr) {
// The assignable values of this course attribute.
$assignablevalues = $imscourses->get_imsnames($courseattr);
$name = get_string('setting' . $courseattr, 'enrol_imsenterprise');
$description = get_string('setting' . $courseattr . 'description', 'enrol_imsenterprise');
$defaultvalue = (string) $imscourses->determine_default_coursemapping($courseattr);
$settings->add(new admin_setting_configselect('enrol_imsenterprise/imscoursemap' . $courseattr, $name,
$description, $defaultvalue, $assignablevalues));
}
}
// Miscellaneous.
$settings->add(new admin_setting_heading('enrol_imsenterprise_miscsettings',
get_string('miscsettings', 'enrol_imsenterprise'), ''));
$settings->add(new admin_setting_configtext('enrol_imsenterprise/imsrestricttarget',
get_string('restricttarget', 'enrol_imsenterprise'), get_string('restricttarget_desc', 'enrol_imsenterprise'), ''));
$settings->add(new admin_setting_configcheckbox('enrol_imsenterprise/imscapitafix',
get_string('usecapitafix', 'enrol_imsenterprise'), get_string('usecapitafix_desc', 'enrol_imsenterprise'), 0));
$importurl = new moodle_url('/enrol/imsenterprise/importnow.php', array('sesskey' => sesskey()));
$importnowstring = get_string('aftersaving...', 'enrol_imsenterprise').' ';
$importnowstring .= html_writer::link($importurl, get_string('doitnow', 'enrol_imsenterprise'));
$settings->add(new admin_setting_heading('enrol_imsenterprise_doitnowmessage', '', $importnowstring));
}
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,676 @@
<?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/>.
namespace enrol_imsenterprise;
use core_course_category;
use enrol_imsenterprise_plugin;
use stdClass;
defined('MOODLE_INTERNAL') || die();
global $CFG;
require_once($CFG->dirroot . '/enrol/imsenterprise/locallib.php');
require_once($CFG->dirroot . '/enrol/imsenterprise/lib.php');
/**
* IMS Enterprise test case
*
* @package enrol_imsenterprise
* @category test
* @copyright 2019 Segun Babalola
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*
* @covers \enrol_imsenterprise_plugin
*/
class imsenterprise_unenrol_test extends \advanced_testcase {
/**
* @var $imsplugin enrol_imsenterprise_plugin IMS plugin instance.
*/
public $imsplugin;
/**
* Setup required for all tests.
*/
protected function setUp(): void {
$this->resetAfterTest(true);
$this->imsplugin = enrol_get_plugin('imsenterprise');
$this->set_test_config();
}
/**
* Sets the plugin configuration for testing
*/
public function set_test_config() {
$this->imsplugin->set_config('mailadmins', false);
$this->imsplugin->set_config('prev_path', '');
$this->imsplugin->set_config('createnewusers', true);
$this->imsplugin->set_config('imsupdateusers', true);
$this->imsplugin->set_config('createnewcourses', true);
$this->imsplugin->set_config('updatecourses', true);
$this->imsplugin->set_config('createnewcategories', true);
$this->imsplugin->set_config('categoryseparator', '');
$this->imsplugin->set_config('categoryidnumber', false);
$this->imsplugin->set_config('nestedcategories', false);
}
/**
* Creates an IMS enterprise XML file and adds it's path to config settings.
*
* @param bool|array $users false or array of users StdClass
* @param bool|array $courses false or of courses StdClass
* @param bool|array $usercoursemembership false or of courses StdClass
*/
public function set_xml_file($users = false, $courses = false, $usercoursemembership = false) {
$xmlcontent = '<enterprise>';
// Users.
if (!empty($users) && is_array($users)) {
foreach ($users as $user) {
$xmlcontent .= '<person' . (!empty($user->recstatus) ? ' recstatus="'.$user->recstatus.'"' : '').'>';
$xmlcontent .= '<sourcedid><source>TestSource</source><id>'.$user->idnumber.'</id></sourcedid>';
$xmlcontent .= '<userid' . (!empty($user->auth) ? ' authenticationtype="'.$user->auth.'"' : '');
$xmlcontent .= '>'.$user->username.'</userid>';
$xmlcontent .= '<name>'
.'<fn>'.$user->firstname.' '.$user->lastname.'</fn>'
.'<n><family>'.$user->lastname.'</family><given>'.$user->firstname.'</given></n>'
.'</name>'
.'<email>'.$user->email.'</email>';
$xmlcontent .= '</person>';
}
}
// Courses.
// Mapping based on default course attributes - IMS group tags mapping.
if (!empty($courses) && is_array($courses)) {
foreach ($courses as $course) {
$xmlcontent .= '<group' . (!empty($course->recstatus) ? ' recstatus="'.$course->recstatus.'"' : '').'>';
$xmlcontent .= '<sourcedid><source>TestSource</source><id>'.$course->idnumber.'</id></sourcedid>';
$xmlcontent .= '<description>'.(!empty($course->imsshort) ? '<short>'.$course->imsshort.'</short>' : '');
$xmlcontent .= (!empty($course->imslong) ? '<long>'.$course->imslong.'</long>' : '');
$xmlcontent .= (!empty($course->imsfull) ? '<full>'.$course->imsfull.'</full>' : '');
$xmlcontent .= '</description>';
// The orgunit tag value is used by moodle as category name.
$xmlcontent .= '<org>';
// Optional category name.
if (isset($course->category)) {
if (is_array($course->category)) {
foreach ($course->category as $category) {
$xmlcontent .= '<orgunit>' . $category . '</orgunit>';
}
} else if (is_object($course->category)) {
$xmlcontent .= '<orgunit>' . $course->category->name . '</orgunit>';
} else if (!empty($course->category)) {
$xmlcontent .= '<orgunit>' . $course->category . '</orgunit>';
}
}
$xmlcontent .= '</org>';
$xmlcontent .= '</group>';
}
}
// User course membership (i.e. roles and enrolments).
if (!empty($usercoursemembership) && is_array($usercoursemembership)) {
foreach ($usercoursemembership as $crsemship) {
// Only process records that have a source/id (i.e. course code) set in the IMS file.
// Note that we could also check that there is a corresponding $course with the course code given here,
// however it is possible that we want to test the behaviour of orphan membership elements in future,
// so leaving the check out for now.
if (isset($crsemship->crseidnumber) && isset($crsemship->member) && is_array($crsemship->member)
&& count($crsemship->member)) {
$xmlcontent .= '<membership><sourcedid><source>TestSource</source><id>'
.$crsemship->crseidnumber . '</id></sourcedid>';
foreach ($crsemship->member as $crsemember) {
if (!empty($crsemember->useridnumber)) {
$xmlcontent .= '<member>';
$xmlcontent .= '<sourcedid><source>TestSource</source><id>'. $crsemember->useridnumber
.'</id></sourcedid>';
// Indicates whether the member is a Person (1) or another Group (2).
// We're only handling user membership here, so hard-code value of 1.
$xmlcontent .= '<idtype>1</idtype>';
if (isset($crsemember->role) && is_array($crsemember->role)) {
foreach ($crsemember->role as $role) {
$xmlcontent .= '<role roletype="'.$role->roletype.'" recstatus="'.$role->recstatus.'">';
$xmlcontent .= '<userid/>';
$xmlcontent .= '<status>' . $role->rolestatus . '</status>';
$xmlcontent .= '</role>';
}
}
$xmlcontent .= '</member>';
}
}
$xmlcontent .= '</membership>';
}
}
}
$xmlcontent .= '</enterprise>';
// Creating the XML file.
$filename = 'ims_' . rand(1000, 9999) . '.xml';
$tmpdir = make_temp_directory('enrol_imsenterprise');
$xmlfilepath = $tmpdir . '/' . $filename;
file_put_contents($xmlfilepath, $xmlcontent);
// Setting the file path in CFG.
$this->imsplugin->set_config('imsfilelocation', $xmlfilepath);
}
/**
* Utility function for generating test user records
*
* @param int $numberofrecordsrequired - number of test users required
* @return array of StdClass objects representing test user records
*/
private function generate_test_user_records($numberofrecordsrequired) {
$users = [];
for ($i = 0; $i < $numberofrecordsrequired; $i++) {
$usernumber = $i + 101;
$users[] = (object)[
'recstatus' => enrol_imsenterprise_plugin::IMSENTERPRISE_ADD,
'idnumber' => $usernumber,
'username' => 'UID' .$usernumber,
'email' => 'user' . $usernumber . '@moodle.org',
'firstname' => 'User' . $usernumber . ' firstname',
'lastname' => 'User' . $usernumber . ' lastname'
];
}
return $users;
}
/**
* Utility function for generating test course records
*
* @param int $numberofrecordsrequired - number of test course records required
* @return array of StdClass objects representing test course records
*/
private function generate_test_course_records($numberofrecordsrequired) {
$courses = [];
for ($i = 0; $i < $numberofrecordsrequired; $i++) {
$coursenumber = $i + 101;
$courses[] = (object)[
'recstatus' => enrol_imsenterprise_plugin::IMSENTERPRISE_ADD,
'idnumber' => 'CID' . $coursenumber,
'imsshort' => 'Course ' . $coursenumber,
'category' => core_course_category::get_default()
];
}
return $courses;
}
/**
* Utility function for generating test membership structure for given users and courses.
* Linkmatrix is expected to be in [row, col] format, where courses are rows and users are columns.
* Each element of the link matrix is expected to contain <roletype>:<role status>:<role recstatus>.
*
* @param array $users
* @param array $courses
* @param array $linkmatrix - matrix/two dimensional array of required user course enrolments
* @return array
*/
private function link_users_with_courses($users, $courses, $linkmatrix) {
$memberships = [];
foreach ($courses as $i => $c) {
$membership = new stdClass();
$membership->member = [];
$membership->crseidnumber = $c->idnumber;
foreach ($users as $j => $u) {
if (isset($linkmatrix[$i][$j])) {
list($roletype, $rolestatus, $rolerecstatus) = explode(':', $linkmatrix[$i][$j]);
if (strlen($rolerecstatus) && strlen($roletype) && strlen($rolestatus)) {
$membership->member[] = (object)[
'useridnumber' => $u->idnumber,
'role' => [(object)[
'roletype' => $roletype,
'rolestatus' => $rolestatus,
'recstatus' => $rolerecstatus
]]
];
}
}
}
$memberships[] = $membership;
}
return $memberships;
}
/**
* Add new users, courses and enrolments
*/
public function test_users_are_enroled_on_courses(): void {
global $DB;
$prevnuserenrolments = $DB->count_records('user_enrolments');
$prevnusers = $DB->count_records('user');
$prevncourses = $DB->count_records('course');
$courses = $this->generate_test_course_records(1);
$users = $this->generate_test_user_records(1);
$coursemembership = $this->link_users_with_courses(
$users,
$courses,
[
['01:1:1'] // First course.
]
);
$this->set_xml_file($users, $courses, $coursemembership);
$this->imsplugin->cron();
$this->assertEquals(($prevnuserenrolments + 1), $DB->count_records('user_enrolments'));
$this->assertEquals(($prevnusers + 1), $DB->count_records('user'));
$this->assertEquals(($prevncourses + 1), $DB->count_records('course'));
}
/**
* Check that the unenrol actions are completely ignored when "unenrol" setting is disabled
*/
public function test_no_action_when_unenrol_disabled(): void {
global $DB;
$prevnuserenrolments = $DB->count_records('user_enrolments');
$prevnusers = $DB->count_records('user');
$prevncourses = $DB->count_records('course');
// Create user and course.
$courses = $this->generate_test_course_records(3);
$users = $this->generate_test_user_records(2);
$coursemembership = $this->link_users_with_courses(
$users,
$courses,
// Role types: 01=Learner, 02=Instructor, 03=Content Dev, 04=Member, 05=Manager, 06=Mentor, 07=Admin, 08=TA.
// Role statuses: 0=Inactive, 1=Active.
// Role recstatus: 1=Add, 2=Update, 3=Delete.
// Format of matrix elements: <roletype>:<role status>:<role recstatus>.
[
['01:1:1', '01:1:1'], // Course 1.
['01:1:1', '01:1:1'], // Course 2.
['::', '01:1:1'], // Course 3.
]
);
$this->set_xml_file($users, $courses, $coursemembership);
$this->imsplugin->cron();
$this->assertEquals(($prevnuserenrolments + 5), $DB->count_records('user_enrolments'));
$this->assertEquals(($prevnusers + 2), $DB->count_records('user'));
$this->assertEquals(($prevncourses + 3), $DB->count_records('course'));
// Disallow unenrolment, and check that unenroling has no effect.
$this->imsplugin->set_config('imsunenrol', 0);
$coursemembership = $this->link_users_with_courses(
$users,
$courses,
// Role types: 01=Learner, 02=Instructor, 03=Content Dev, 04=Member, 05=Manager, 06=Mentor, 07=Admin, 08=TA.
// Role statuses: 0=Inactive, 1=Active.
// Role recstatus: 1=Add, 2=Update, 3=Delete.
// Format of matrix elements: <roletype>:<role status>:<role recstatus>.
[
['01:1:3', '01:1:3'], // Course 1.
['::', '01:1:3'], // Course 2.
['::', '01:1:3'], // Course 3.
]
);
$this->set_xml_file($users, $courses, $coursemembership);
$this->imsplugin->cron();
$this->assertEquals(($prevnuserenrolments + 5), $DB->count_records('user_enrolments'));
$this->assertEquals(($prevnusers + 2), $DB->count_records('user'));
$this->assertEquals(($prevncourses + 3), $DB->count_records('course'));
}
/**
* When a user has existing roles and enrolments, they are unaffected by IMS instructions for other courses
*/
public function test_existing_roles_and_enrolments_unaffected(): void {
global $DB;
$this->imsplugin->set_config('imsunenrol', 1);
$this->imsplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
$prevnuserenrolments = $DB->count_records('user_enrolments');
$prevnusers = $DB->count_records('user');
$prevncourses = $DB->count_records('course');
$courses = $this->generate_test_course_records(2);
// Create_course seems to expect the category to be passed as ID, so extract from the object.
$course1 = $courses[0];
$course1->category = $course1->category->id;
$course1 = $this->getDataGenerator()->create_course($courses[0]);
// Enrol user1 on course1.
$DB->insert_record('enrol', (object)['enrol' => 'imsenterprise',
'courseid' => $course1->id, 'status' => 1, 'roleid' => 5
], true);
$user1 = $this->getDataGenerator()->create_and_enrol($course1, 'student',
['idnumber' => 'UserIDNumber100'], 'imsenterprise');
$user1->username = $user1->idnumber;
// Confirm user was added and that the enrolment happened.
$this->assertEquals(($prevnuserenrolments + 1), $DB->count_records('user_enrolments'));
$this->assertEquals(($prevnusers + 1), $DB->count_records('user'));
$this->assertEquals(($prevncourses + 1), $DB->count_records('course'));
// Capture DB id of enrolment record.
$initialusernerolment = $DB->get_record('user_enrolments', ['userid' => $user1->id],
'*', MUST_EXIST);
$initialroleassigned = $DB->get_record('role_assignments', ['userid' => $user1->id],
'*', MUST_EXIST);
// Add a new enrolment for the same user via IMS file.
$coursemembership = $this->link_users_with_courses(
[$user1],
$courses,
// Role types: 01=Learner, 02=Instructor, 03=Content Dev, 04=Member, 05=Manager, 06=Mentor, 07=Admin, 08=TA.
// Role statuses: 0=Inactive, 1=Active.
// Role recstatus: 1=Add, 2=Update, 3=Delete.
// Format of matrix elements: <roletype>:<role status>:<role recstatus>.
[
['::'], // Course 1.
['01:1:1'], // Course 2.
]
);
$this->set_xml_file([$user1], $courses, $coursemembership);
$this->imsplugin->cron();
$this->assertEquals(2, $DB->count_records('user_enrolments', ['userid' => $user1->id]));
$this->assertEquals(($prevncourses + 2), $DB->count_records('course'));
// Unenrol the user from course2 via IMS file.
$coursemembership = $this->link_users_with_courses(
[$user1],
$courses,
// Role types: 01=Learner, 02=Instructor, 03=Content Dev, 04=Member, 05=Manager, 06=Mentor, 07=Admin, 08=TA.
// Role statuses: 0=Inactive, 1=Active.
// Role recstatus: 1=Add, 2=Update, 3=Delete.
// Format of matrix elements: <roletype>:<role status>:<role recstatus>.
[
['::'], // Course 1.
['01:0:3'], // Course 2.
]
);
$this->set_xml_file([$user1], $courses, $coursemembership);
$this->imsplugin->cron();
$this->assertEquals(1, $DB->count_records('user_enrolments', ['userid' => $user1->id]));
$this->assertTrue($DB->record_exists('user_enrolments', ['id' => $initialusernerolment->id,
'userid' => $initialusernerolment->userid]));
$this->assertTrue($DB->record_exists('role_assignments', ['id' => $initialroleassigned->id,
'userid' => $initialusernerolment->userid]));
}
/**
* Enrolments alone are disabled
*/
public function test_disable_enrolments_only(): void {
global $DB;
$this->imsplugin->set_config('imsunenrol', 1);
$this->imsplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPEND);
$prevnuserenrolments = $DB->count_records('user_enrolments');
$prevnroles = $DB->count_records('role_assignments');
$prevnusers = $DB->count_records('user');
$prevncourses = $DB->count_records('course');
$courses = $this->generate_test_course_records(1);
$users = $this->generate_test_user_records(1);
// Add a new enrolment for the same user via IMS file.
$coursemembership = $this->link_users_with_courses(
$users,
$courses,
// Role types: 01=Learner, 02=Instructor, 03=Content Dev, 04=Member, 05=Manager, 06=Mentor, 07=Admin, 08=TA.
// Role statuses: 0=Inactive, 1=Active.
// Role recstatus: 1=Add, 2=Update, 3=Delete.
// Format of matrix elements: <roletype>:<role status>:<role recstatus>.
[
['01:1:1'], // Course 1.
]
);
$this->set_xml_file($users, $courses, $coursemembership);
$this->imsplugin->cron();
$this->assertEquals(($prevncourses + 1), $DB->count_records('course'));
$this->assertEquals(($prevnusers + 1), $DB->count_records('user'));
$this->assertEquals(($prevnuserenrolments + 1), $DB->count_records('user_enrolments'));
$this->assertEquals(($prevnroles + 1), $DB->count_records('role_assignments'));
// Capture DB ids.
$dbuser = $DB->get_record('user', ['idnumber' => $users[0]->idnumber], '*', MUST_EXIST);
$dbenrolment = $DB->get_record('user_enrolments',
['userid' => $dbuser->id, 'status' => ENROL_USER_ACTIVE],
'*', MUST_EXIST
);
$dbrole = $DB->get_record('role_assignments', ['userid' => $dbuser->id], '*', MUST_EXIST);
// Unenrol the user, check that the enrolment and role exist, but the enrolment is suspended.
$coursemembership = $this->link_users_with_courses(
$users,
$courses,
// Role types: 01=Learner, 02=Instructor, 03=Content Dev, 04=Member, 05=Manager, 06=Mentor, 07=Admin, 08=TA.
// Role statuses: 0=Inactive, 1=Active.
// Role recstatus: 1=Add, 2=Update, 3=Delete.
// Format of matrix elements: <roletype>:<role status>:<role recstatus>.
[
['01:0:3'], // Course 1.
]
);
$this->set_xml_file($users, $courses, $coursemembership);
$this->imsplugin->cron();
$this->assertEquals(($prevncourses + 1), $DB->count_records('course'));
$this->assertEquals(($prevnusers + 1), $DB->count_records('user'));
$this->assertEquals(($prevnuserenrolments + 1), $DB->count_records('user_enrolments'));
$this->assertEquals(($prevnroles + 1), $DB->count_records('role_assignments'));
$this->assertEquals(1, $DB->count_records('user_enrolments',
['userid' => $dbuser->id, 'id' => $dbenrolment->id, 'status' => ENROL_USER_SUSPENDED]));
$this->assertEquals(1, $DB->count_records('role_assignments',
['userid' => $dbuser->id, 'id' => $dbrole->id]));
}
/**
* Enrolments are disabled but retained) and roles removed
*/
public function test_disable_enrolments_and_remove_roles(): void {
global $DB;
$this->imsplugin->set_config('imsunenrol', 1);
$this->imsplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
$prevnuserenrolments = $DB->count_records('user_enrolments');
$prevnroles = $DB->count_records('role_assignments');
$prevnusers = $DB->count_records('user');
$prevncourses = $DB->count_records('course');
$courses = $this->generate_test_course_records(1);
$users = $this->generate_test_user_records(1);
// Add a new enrolment for the same user via IMS file.
$coursemembership = $this->link_users_with_courses(
$users,
$courses,
// Role types: 01=Learner, 02=Instructor, 03=Content Dev, 04=Member, 05=Manager, 06=Mentor, 07=Admin, 08=TA.
// Role statuses: 0=Inactive, 1=Active.
// Role recstatus: 1=Add, 2=Update, 3=Delete.
// Format of matrix elements: <roletype>:<role status>:<role recstatus>.
[
['01:1:1'], // Course 1.
]
);
$this->set_xml_file($users, $courses, $coursemembership);
$this->imsplugin->cron();
$this->assertEquals(($prevncourses + 1), $DB->count_records('course'));
$this->assertEquals(($prevnusers + 1), $DB->count_records('user'));
$this->assertEquals(($prevnuserenrolments + 1), $DB->count_records('user_enrolments'));
$this->assertEquals(($prevnroles + 1), $DB->count_records('role_assignments'));
// Capture DB ids.
$dbuser = $DB->get_record('user', ['idnumber' => $users[0]->idnumber], '*', MUST_EXIST);
$dbenrolment = $DB->get_record('user_enrolments',
['userid' => $dbuser->id, 'status' => ENROL_USER_ACTIVE],
'*', MUST_EXIST
);
$dbrole = $DB->get_record('role_assignments', ['userid' => $dbuser->id], '*', MUST_EXIST);
// Unenrol the user, check that the enrolment and role exist, but the enrolment is suspended.
$coursemembership = $this->link_users_with_courses(
$users,
$courses,
// Role types: 01=Learner, 02=Instructor, 03=Content Dev, 04=Member, 05=Manager, 06=Mentor, 07=Admin, 08=TA.
// Role statuses: 0=Inactive, 1=Active.
// Role recstatus: 1=Add, 2=Update, 3=Delete.
// Format of matrix elements: <roletype>:<role status>:<role recstatus>.
[
['01:0:3'], // Course 1.
]
);
$this->set_xml_file($users, $courses, $coursemembership);
$this->imsplugin->cron();
$this->assertEquals(($prevncourses + 1), $DB->count_records('course'));
$this->assertEquals(($prevnusers + 1), $DB->count_records('user'));
$this->assertEquals(($prevnuserenrolments + 1), $DB->count_records('user_enrolments'));
$this->assertEquals(($prevnroles), $DB->count_records('role_assignments'));
$this->assertEquals(1, $DB->count_records('user_enrolments',
['userid' => $dbuser->id, 'id' => $dbenrolment->id, 'status' => ENROL_USER_SUSPENDED]));
$this->assertEquals(0, $DB->count_records('role_assignments',
['userid' => $dbuser->id, 'id' => $dbrole->id]));
}
/**
* Enrolments and roles are deleted for specified user
*/
public function test_delete_roles_and_enrolments(): void {
global $DB;
$this->imsplugin->set_config('imsunenrol', 1);
$this->imsplugin->set_config('unenrolaction', ENROL_EXT_REMOVED_UNENROL);
$prevnuserenrolments = $DB->count_records('user_enrolments');
$prevnroles = $DB->count_records('role_assignments');
$prevnusers = $DB->count_records('user');
$prevncourses = $DB->count_records('course');
$courses = $this->generate_test_course_records(1);
$users = $this->generate_test_user_records(1);
// Add a new enrolment for the same user via IMS file.
$coursemembership = $this->link_users_with_courses(
$users,
$courses,
// Role types: 01=Learner, 02=Instructor, 03=Content Dev, 04=Member, 05=Manager, 06=Mentor, 07=Admin, 08=TA.
// Role statuses: 0=Inactive, 1=Active.
// Role recstatus: 1=Add, 2=Update, 3=Delete.
// Format of matrix elements: <roletype>:<role status>:<role recstatus>.
[
['01:1:1'], // Course 1.
]
);
$this->set_xml_file($users, $courses, $coursemembership);
$this->imsplugin->cron();
$this->assertEquals(($prevncourses + 1), $DB->count_records('course'));
$this->assertEquals(($prevnusers + 1), $DB->count_records('user'));
$this->assertEquals(($prevnuserenrolments + 1), $DB->count_records('user_enrolments'));
$this->assertEquals(($prevnroles + 1), $DB->count_records('role_assignments'));
// Capture DB ids.
$dbuser = $DB->get_record('user', ['idnumber' => $users[0]->idnumber], '*', MUST_EXIST);
$dbenrolment = $DB->get_record('user_enrolments',
['userid' => $dbuser->id, 'status' => ENROL_USER_ACTIVE],
'*', MUST_EXIST
);
$dbrole = $DB->get_record('role_assignments', ['userid' => $dbuser->id], '*', MUST_EXIST);
// Unenrol the user, check that the enrolment and role exist, but the enrolment is suspended.
$coursemembership = $this->link_users_with_courses(
$users,
$courses,
// Role types: 01=Learner, 02=Instructor, 03=Content Dev, 04=Member, 05=Manager, 06=Mentor, 07=Admin, 08=TA.
// Role statuses: 0=Inactive, 1=Active.
// Role recstatus: 1=Add, 2=Update, 3=Delete.
// Format of matrix elements: <roletype>:<role status>:<role recstatus>.
[
['01:1:3'], // Course 1.
]
);
$this->set_xml_file($users, $courses, $coursemembership);
$this->imsplugin->cron();
$this->assertEquals(($prevncourses + 1), $DB->count_records('course'));
$this->assertEquals(($prevnusers + 1), $DB->count_records('user'));
$this->assertEquals(($prevnuserenrolments), $DB->count_records('user_enrolments'));
$this->assertEquals(($prevnroles), $DB->count_records('role_assignments'));
$this->assertEquals(0, $DB->count_records('user_enrolments',
['userid' => $dbuser->id, 'id' => $dbenrolment->id, 'status' => ENROL_USER_SUSPENDED]));
$this->assertEquals(0, $DB->count_records('role_assignments',
['userid' => $dbuser->id, 'id' => $dbrole->id]));
}
}
+29
View File
@@ -0,0 +1,29 @@
<?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/>.
/**
* IMS Enterprise file enrolment plugin version specification.
*
* @package enrol_imsenterprise
* @copyright 2010 Eugene Venter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
$plugin->version = 2024042200; // The current plugin version (Date: YYYYMMDDXX).
$plugin->requires = 2024041600; // Requires this Moodle version.
$plugin->component = 'enrol_imsenterprise';