Merge branch 'w11_MDL-31845_m23_dbenrolcat' of git://github.com/skodak/moodle

This commit is contained in:
Eloy Lafuente (stronk7) 2012-03-13 13:36:48 +01:00
commit 65fc03100d
4 changed files with 11 additions and 6 deletions

View File

@ -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';

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,17 +655,17 @@ 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;
}
$course = new stdClass();
$course->fullname = $fields[$fullname];
$course->shortname = $fields[$shortname];
$course->idnumber = $idnumber ? $fields[$idnumber] : NULL;
$course->category = $category ? $fields[$category] : NULL;
$course->idnumber = $idnumber ? $fields[$idnumber] : '';
$course->category = $category ? $coursecategory->id : NULL;
$createcourses[] = $course;
}
}

View File

@ -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'), ''));

View File

@ -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?