Skip to content

Commit

Permalink
Merge branch 'w11_MDL-31845_m23_dbenrolcat' of git://github.com/skoda…
Browse files Browse the repository at this point in the history
…k/moodle
  • Loading branch information
stronk7 committed Mar 13, 2012
2 parents 7ca5dd8 + b6f7dbe commit 65fc031
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion enrol/database/lang/en/enrol_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@
$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';
Expand Down
10 changes: 6 additions & 4 deletions enrol/database/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,8 @@ public function sync_courses($verbose = false) {
$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;
Expand Down Expand Up @@ -653,17 +655,17 @@ public function sync_courses($verbose = false) {
}
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;
}
}
Expand Down
2 changes: 2 additions & 0 deletions enrol/database/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
$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'), ''));
Expand Down
2 changes: 1 addition & 1 deletion enrol/database/version.php
Original file line number Diff line number Diff line change
Expand Up @@ -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?

0 comments on commit 65fc031

Please sign in to comment.