MDL-31845 add "Local category field" option in database enrol plugin

This patch uses code from the original patch by Michael Aherne, most of the credit goes to him.
This commit is contained in:
Petr Skoda 2012-03-10 14:01:03 +01:00
parent 23778a4dfa
commit e042c58df1
4 changed files with 10 additions and 5 deletions

View file

@ -622,6 +622,8 @@ class enrol_database_plugin extends enrol_plugin {
$idnumber = strtolower($this->get_config('newcourseidnumber'));
$category = strtolower($this->get_config('newcoursecategory'));
$localcategoryfield = $this->get_config('localcategoryfield', 'id');
$sqlfields = array($fullname, $shortname);
if ($category) {
$sqlfields[] = $category;
@ -653,9 +655,9 @@ class enrol_database_plugin extends enrol_plugin {
}
continue;
}
if ($category and !$DB->record_exists('course_categories', array('id'=>$fields[$category]))) {
if ($category and !$coursecategory = $DB->get_record('course_categories', array($localcategoryfield=>$fields[$category]), 'id')) {
if ($verbose) {
mtrace(' error: invalid category id, can not create course: '.$fields[$shortname]);
mtrace(' error: invalid category '.$localcategoryfield.', can not create course: '.$fields[$shortname]);
}
continue;
}
@ -663,7 +665,7 @@ class enrol_database_plugin extends enrol_plugin {
$course->fullname = $fields[$fullname];
$course->shortname = $fields[$shortname];
$course->idnumber = $idnumber ? $fields[$idnumber] : NULL;
$course->category = $category ? $fields[$category] : NULL;
$course->category = $category ? $coursecategory->id : NULL;
$createcourses[] = $course;
}
}