Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MDL-28705 enrol_imsenterprise Make name mapping configurable

  • Loading branch information...
commit a65c11b0cae537a5dc44dd3f5e0714cdd8ec4571 1 parent b1cabb4
@acspike acspike authored dmonllao committed
View
28 enrol/imsenterprise/lib.php
@@ -97,6 +97,8 @@ function cron() {
// Make sure we understand how to map the IMS-E roles to Moodle roles
$this->load_role_mappings();
+ // Make sure we understand how to map the IMS-E course names to Moodle course names
+ $this->load_course_mappings();
$md5 = md5_file($filename); // NB We'll write this value back to the database at the end of the cron
$filemtime = filemtime($filename);
@@ -377,13 +379,13 @@ function process_group_tag($tagcontents) {
// If long and ID exist, then map long to long, then give short the ID's value.
$group->shortname = $coursecode;
}
+ $group->full = format_text($group->full, FORMAT_HTML);
+
// Create the (hidden) course(s) if not found
$courseconfig = get_config('moodlecourse'); // Load Moodle Course shell defaults
$course = new stdClass();
- $course->fullname = $group->longname;
- $course->shortname = $group->shortname;
- if (!empty($group->full)) {
- $course->summary = format_text($group->full, FORMAT_HTML);
+ foreach ($this->coursemappings as $coursename => $imsname) {
+ $course->$coursename = $group->$imsname;
}
$course->idnumber = $coursecode;
$course->format = $courseconfig->format;
@@ -792,6 +794,23 @@ function load_role_mappings() {
}
/**
+ * Load the name mappings (from the config), so we can easily refer to
+ * how an IMS-E course properties corresponds to a Moodle course properties
+ */
+ function load_course_mappings() {
+ require_once('locallib.php');
+
+ $imsnames = new imsenterprise_names();
+ $coursenames = $imsnames->get_coursenames();
+ $imsnames = $imsnames->get_imsnames();
+
+ $this->coursemappings = array();
+ foreach($coursenames as $coursename) {
+ $this->coursemappings[$coursename] = $this->get_config('imsrolemap' . $coursename);
+ }
+ }
+
+ /**
* Called whenever anybody tries (from the normal interface) to remove a group
* member which is registered as being created by this component. (Not called
* when deleting an entire group or course at once.)
@@ -804,6 +823,7 @@ function enrol_imsenterprise_allow_group_member_remove($itemid, $groupid, $useri
return false;
}
+
} // end of class
View
43 enrol/imsenterprise/locallib.php
@@ -82,3 +82,46 @@ function determine_default_rolemapping($imscode) {
} // class
+
+class imsenterprise_names {
+ private $imsnames;
+ private $coursenames;
+
+ function __construct() {
+ $this->imsnames = array(
+ 'long'=>'long',
+ 'short'=>'short',
+ 'full'=>'full',
+ 'coursecode'=>'coursecode',
+ );
+ $this->coursenames = array('fullname', 'shortname', 'summary');
+ }
+
+ function get_imsnames() {
+ return $this->imsnames;
+ }
+
+ function get_coursenames() {
+ return $this->coursenames;
+ }
+
+ /**
+ * This function is only used when first setting up the plugin, to
+ * decide which name assignments to recommend by default.
+ */
+ function determine_default_namemapping($coursename) {
+ switch($coursename) {
+ case 'fullname':
+ $imsname = 'short';
+ break;
+ case 'shortname':
+ $imsname = 'coursecode';
+ break;
+ default:
+ return 'ignore'; // Zero for no match
+ }
+ return $imsname;
+ }
+
+
+} // class
View
10 enrol/imsenterprise/settings.php
@@ -75,6 +75,16 @@
$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/imsunenrol', get_string('allowunenrol', 'enrol_imsenterprise'), get_string('allowunenrol_desc', 'enrol_imsenterprise'), 0));
+
+ $settings->add(new admin_setting_heading('enrol_imsenterprise_coursesettings_names', get_string('names', 'enrol_imsenterprise'), get_string('imsnamesdescription', 'enrol_imsenterprise')));
+
+ if (!during_initial_install()) {
+ $imsnames = new imsenterprise_names();
+ $assignablenames = array('ignore' => get_string('ignore', 'enrol_imsenterprise')) + $imsnames->get_imsnames();
+ foreach ($imsnames->get_coursenames() as $coursename) {
+ $settings->add(new admin_setting_configselect('enrol_imsenterprise/imsnamemap'.$coursename, get_string($coursename, 'enrol_imsenterprise'), '', (string)$imsnames->determine_default_namemapping($coursename), $assignablenames));
+ }
+ }
//--- miscellaneous -------------------------------------------------------------------------------------
$settings->add(new admin_setting_heading('enrol_imsenterprise_miscsettings', get_string('miscsettings', 'enrol_imsenterprise'), ''));
Please sign in to comment.
Something went wrong with that request. Please try again.