MDL-29325 imsenterprise enrolment - allow more flexible naming of courses - thanks to Adam Barbary for patch

This commit is contained in:
Dan Marsden 2011-12-02 22:57:29 +13:00 committed by Aparup Banerjee
parent 5c8e2b97d3
commit 903ab24de4

View file

@ -315,9 +315,12 @@ function process_group_tag($tagcontents) {
if (preg_match('{<sourcedid>.*?<id>(.+?)</id>.*?</sourcedid>}is', $tagcontents, $matches)) {
$group->coursecode = trim($matches[1]);
}
if (preg_match('{<description>.*?<short>(.*?)</short>.*?</description>}is', $tagcontents, $matches)) {
if (preg_match('{<description>.*?<long>(.*?)</long>.*?</description>}is', $tagcontents, $matches)){
$group->description = trim($matches[1]);
}
if (preg_match('{<description>.*?<short>(.*?)</short>.*?</description>}is', $tagcontents, $matches)) {
$group->shortName = trim($matches[1]);
}
if (preg_match('{<org>.*?<orgunit>(.*?)</orgunit>.*?</org>}is', $tagcontents, $matches)) {
$group->category = trim($matches[1]);
}
@ -355,11 +358,23 @@ function process_group_tag($tagcontents) {
if (!$createnewcourses) {
$this->log_line("Course $coursecode not found in Moodle's course idnumbers.");
} else {
// Set shortname to description or description to shortname if one is set but not the other.
if (!isset($group->description) && !isset($group->shortName)) {
// If neither short nor long description are set let if fail
$this->log_line("Neither long nor short name are set for $coursecode");
} else if (!isset($group->description)) {
// If short and ID exist, then give the long short's value, then give short the ID's value
$group->description = $group->shortName;
$group->shortName = $coursecode;
} else if (!isset($group->shortName)) {
// If long and ID exist, then map long to long, then give short the ID's value.
$group->shortName = $coursecode;
}
// Create the (hidden) course(s) if not found
$courseconfig = get_config('moodlecourse'); // Load Moodle Course shell defaults
$course = new stdClass();
$course->fullname = $group->description;
$course->shortname = $coursecode;
$course->shortname = $group->shortName;;
$course->idnumber = $coursecode;
$course->format = $courseconfig->format;
$course->visible = $courseconfig->visible;