Skip to content

Commit

Permalink
MDL-10396:
Browse files Browse the repository at this point in the history
Add an option and a check to (optionally) prevent users being enrolled
in hidden courses.
  • Loading branch information
thepurpleblob committed Jul 20, 2007
1 parent 0dc4f14 commit 14f42ba
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
28 changes: 27 additions & 1 deletion enrol/database/config.html
@@ -1,3 +1,7 @@
<?php
$yesno = array('0'=>get_string('no'), '1'=>get_string('yes'));
?>

<table cellspacing="0" cellpadding="5" border="0" class="boxaligncenter">
<tr>
<th colspan="2" scope="col">
Expand Down Expand Up @@ -174,14 +178,15 @@
<td align="right">enrol_db_autocreate:</td>
<td>
<?php
choose_from_menu(array('0'=>'no','1'=>'yes'), "enrol_db_autocreate", $frm->enrol_db_autocreate, "");
choose_from_menu($yesno, "enrol_db_autocreate", $frm->enrol_db_autocreate, "");
if (isset($err["enrol_db_autocreate"])) formerr($err["enrol_db_autocreate"]);
?>
</td>
<td>
<?php print_string("autocreate","enrol_database") ?>
</td>
</tr>

<tr>
<td align="right">enrol_db_category:</td>
<td>
Expand All @@ -208,4 +213,25 @@
</td>
</tr>

<tr>
<th colspan="2" scope="col">
<?php print_string("general_options", "enrol_database") ?>
</th>
</tr>

<tr>
<td align="right">enrol_db_ignorehiddencourse:</td>
<td>
<?php
choose_from_menu($yesno, "enrol_db_ignorehiddencourse", $frm->enrol_db_ignorehiddencourse, "");
if (isset($err['enrol_db_ignorehiddencourse'])) {
formerr($err['enrol_db_ignorehiddencourse']);
}
?>
</td>
<td>
<?php print_string('ignorehiddencourse', 'enrol_database' ); ?>
</td>
</tr>

</table>
14 changes: 13 additions & 1 deletion enrol/database/enrol.php
Expand Up @@ -110,6 +110,12 @@ function setup_enrolments(&$user) {
}
}

// if the course is hidden and we don't want to enrol in hidden courses
// then just skip it
if (!$course->visible and $CFG->enrol_db_ignorehiddencourse) {
continue;
}

/// If there's no role specified, we get the default course role (usually student)
if ($use_default_role) {
$role = get_default_course_role($course);
Expand Down Expand Up @@ -412,7 +418,8 @@ function config_form($frm) {
'enrol_remotecoursefield', 'enrol_remoteuserfield',
'enrol_db_autocreate', 'enrol_db_category', 'enrol_db_template',
'enrol_db_localrolefield', 'enrol_db_remoterolefield',
'enrol_remotecoursefield', 'enrol_remoteuserfield');
'enrol_remotecoursefield', 'enrol_remoteuserfield',
'enrol_db_ignorehiddencourse');

foreach ($vars as $var) {
if (!isset($frm->$var)) {
Expand Down Expand Up @@ -505,6 +512,11 @@ function process_config($config) {
}
set_config('enrol_db_remoterolefield', $config->enrol_db_remoterolefield);

if (!isset($config->enrol_db_ignorehiddencourse)) {
$config->enrol_db_ignorehiddencourse = '';
}
set_config('enrol_db_ignorehiddencourse', $config->enrol_db_ignorehiddencourse );

return true;
}

Expand Down
1 change: 1 addition & 0 deletions lang/en_utf8/enrol_database.php
Expand Up @@ -21,6 +21,7 @@
$string['enrol_database_autocreation_settings'] = 'Auto-creation of new courses';
$string['general_options'] = 'General Options';
$string['host'] = 'Database server hostname.';
$string['ignorehiddencourse'] = 'If set to yes users will not be enroled on courses that are set to be unavailable to students.';
$string['localcoursefield'] = 'The name of the field in the course table that we are using to match entries in the remote database (eg idnumber).';
$string['localrolefield'] = 'The name of the field in the roles table that we are using to match entries in the remote database (eg shortname).';
$string['localuserfield'] = 'The name of the field in the user table that we are using to match entries in the remote database (eg idnumber).';
Expand Down

0 comments on commit 14f42ba

Please sign in to comment.