mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
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:
parent
23778a4dfa
commit
e042c58df1
4 changed files with 10 additions and 5 deletions
|
@ -44,12 +44,13 @@ $string['defaultrole'] = 'Default role';
|
|||
$string['defaultrole_desc'] = 'The role that will be assigned by default if no other role is specified in external table.';
|
||||
$string['ignorehiddencourses'] = 'Ignore hidden courses';
|
||||
$string['ignorehiddencourses_desc'] = 'If enabled users will not be enrolled on courses that are set to be unavailable to students.';
|
||||
$string['localcategoryfield'] = 'Local category field';
|
||||
$string['localcoursefield'] = 'Local course field';
|
||||
$string['localrolefield'] = 'Local role field';
|
||||
$string['localuserfield'] = 'Local user field';
|
||||
$string['newcoursetable'] = 'Remote new courses table';
|
||||
$string['newcoursetable_desc'] = 'Specify of the name of the table that contains list of courses that should be created automatically. Empty means no courses are created.';
|
||||
$string['newcoursecategory'] = 'New course category id field';
|
||||
$string['newcoursecategory'] = 'New course category field';
|
||||
$string['newcoursefullname'] = 'New course full name field';
|
||||
$string['newcourseidnumber'] = 'New course ID number field';
|
||||
$string['newcourseshortname'] = 'New course short name field';
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -66,6 +66,8 @@ if ($ADMIN->fulltree) {
|
|||
$options = array('id'=>'id', 'shortname'=>'shortname', 'fullname'=>'fullname');
|
||||
$settings->add(new admin_setting_configselect('enrol_database/localrolefield', get_string('localrolefield', 'enrol_database'), '', 'shortname', $options));
|
||||
|
||||
$options = array('id'=>'id', 'idnumber'=>'idnumber');
|
||||
$settings->add(new admin_setting_configselect('enrol_database/localcategoryfield', get_string('localcategoryfield', 'enrol_database'), '', 'id', $options));
|
||||
|
||||
|
||||
$settings->add(new admin_setting_heading('enrol_database_remoteheader', get_string('settingsheaderremote', 'enrol_database'), ''));
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2012022700; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->version = 2012031000; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2012022300; // Requires this Moodle version
|
||||
$plugin->component = 'enrol_database'; // Full name of the plugin (used for diagnostics)
|
||||
//TODO: should we add cron sync?
|
Loading…
Add table
Add a link
Reference in a new issue