New feature: Course enrollable control with date range

This commit is contained in:
patrickslee 2005-10-04 01:59:19 +00:00
parent 1910d66ce9
commit f89033b111
10 changed files with 107 additions and 2 deletions

View File

@ -15,6 +15,21 @@
if (!isset($form->theme)) {
$form->theme = '';
}
if (!isset($form->enrollable)) {
$form->enrollable = 1;
}
if (!isset($form->enrolstartdate)) {
$form->enrolstartdate = 0;
}
if (!$form->enrolstartdate) {
$form->enrolstartdisabled = 1;
}
if (!isset($form->enrolenddate)) {
$form->enrolenddate = 0;
}
if (!$form->enrolenddate) {
$form->enrolenddisabled = 1;
}
if (!isset($form->enrolperiod)) {
$form->enrolperiod = 0;
}
@ -94,6 +109,46 @@
helpbutton("coursestartdate", get_string("startdate"));
?></td>
</tr>
<tr valign="top">
<td align="right"><?php print_string("enrollable") ?>:</td>
<td><?php
unset($choices);
$choices["0"] = get_string("no");
$choices["1"] = get_string("yes");
$choices["2"] = get_string("enroldate");
choose_from_radio ($choices, "enrollable", "$form->enrollable", "");
helpbutton("courseenrollable", get_string("enrollable"));
?></td>
</tr>
<tr valign="top" id="daterange">
<td align="right"><?php print_string("enroldate") ?>:</td>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td align="right"><?php print_string('enrolstartdate') ?>: </td>
<td><?php
print_date_selector("enrolstartday", "enrolstartmonth", "enrolstartyear", $form->enrolstartdate);
print_string('disable');
echo ': ';
print_checkbox('enrolstartdisabled', 1, "$form->enrolstartdisabled");
?></td>
</tr>
<tr>
<td height="18" colspan="2"> </td>
</tr>
<tr>
<td align="right"><?php print_string('enrolenddate') ?>: </td>
<td><?php
print_date_selector("enrolendday", "enrolendmonth", "enrolendyear", $form->enrolenddate);
print_string('disable');
echo ': ';
print_checkbox('enrolenddisabled', 1, "$form->enrolenddisabled");
if (isset($err["enroldate"])) formerr($err["enroldate"]);
?></td>
</tr>
</table>
</td>
</tr>
<tr valign="top">
<td align="right"><?php print_string("enrolperiod") ?>:</td>
<td>

View File

@ -60,6 +60,18 @@
$form->startdate = make_timestamp($form->startyear, $form->startmonth, $form->startday);
if (empty($form->enrolstartdisabled)) {
$form->enrolstartdate = make_timestamp($form->enrolstartyear, $form->enrolstartmonth, $form->enrolstartday);
} else {
$form->enrolstartdate = 0;
}
if (empty($form->enrolenddisabled)) {
$form->enrolenddate = make_timestamp($form->enrolendyear, $form->enrolendmonth, $form->enrolendday);
} else {
$form->enrolenddate = 0;
}
$form->format = optional_param('format', 'social', PARAM_ALPHA);
validate_form($course, $form, $err);
@ -267,6 +279,10 @@
function validate_form($course, &$form, &$err) {
if (empty($form->enrolenddisabled) && $form->enrolenddate <= $form->enrolstartdate) {
$err["enroldate"] = get_string("enrolenddaterror");
}
if (empty($form->fullname))
$err["fullname"] = get_string("missingfullname");

View File

@ -59,6 +59,15 @@
}
}
/// Check if the course is enrollable
if (!$course->enrollable ||
($course->enrollable == 2 && $course->enrolstartdate > 0 && $course->enrolstartdate > time()) ||
($course->enrollable == 2 && $course->enrolenddate > 0 && $course->enrolenddate <= time())
) {
print_header_simple();
notice(get_string('notenrollable'), $CFG->wwwroot);
}
/// Check the submitted enrollment key if there is one
if ($form = data_submitted()) {

View File

@ -0,0 +1 @@
<p>Whether this course is enrollable or not. With a third option of allowing enrolment within a range of date.</p>

View File

@ -427,6 +427,8 @@ $string['messageselect'] = 'Select this user as an email recipient';
$string['messageselectadd'] = 'Add / send message';
$string['enable'] = 'Enable';
$string['encryptedcode'] = 'Encrypted code';
$string['enroldate'] = 'Date range';
$string['enrollable'] = 'Course enrollable';
$string['enrolledincourse'] = 'Enrolled in course \"$a\"';
$string['enrolledincoursenot'] = 'Not enrolled in course \"$a\"';
$string['enrollfirst'] = 'You have to enrol in one of the courses before you can use the site activities';
@ -445,6 +447,9 @@ $string['enrolmentnotyet'] = 'Sorry, you can not access this course until <br />
$string['enrolments'] = 'Enrolments';
$string['enrolmentstart'] = 'Enrolment Started';
$string['enrolperiod'] = 'Enrolment duration';
$string['enrolenddate'] = 'End date';
$string['enrolenddaterror'] = 'Enrolment end date cannot be earlier than start date';
$string['enrolstartdate'] = 'Start date';
$string['entercourse'] = 'Click to enter this course';
$string['enteremailaddress'] = 'Enter in your email address to reset your
password and have the new password sent to you via email.';
@ -863,6 +868,7 @@ $string['nostudentsingroup'] = 'There are no students in this group yet';
$string['nosuchemail'] = 'No such email address';
$string['notavailable'] = 'Not available';
$string['noteachersyet'] = 'No teachers in this course yet';
$string['notenrollable'] = 'This course is not enrollable at the moment.';
$string['notenrolled'] = '$a is not enrolled in this course.';
$string['noteuserschangednonetocourse'] = 'Note: course users need to be restored when restoring user data (in activities, files or messages). This setting has been changed for you.';
$string['nothingnew'] = 'Nothing new since your last login';

View File

@ -1643,6 +1643,12 @@ function main_upgrade($oldversion=0) {
insert_record('config', $new);
}
if ($oldversion < 2005100400) {
table_column('course','','enrollable','tinyint','1','unsigned','1');
table_column('course','','enrolstartdate','int');
table_column('course','','enrolenddate','int');
}
return $result;
}

View File

@ -82,6 +82,9 @@ CREATE TABLE `prefix_course` (
`expirynotify` tinyint(1) unsigned NOT NULL default '0',
`expirythreshold` int(10) unsigned NOT NULL default '0',
`notifystudents` tinyint(1) unsigned NOT NULL default '0',
`enrollable` tinyint(1) unsigned NOT NULL default '1',
`enrolstartdate` int(10) unsigned NOT NULL default '0',
`enrolenddate` int(10) unsigned NOT NULL default '0',
PRIMARY KEY (`id`),
KEY `category` (`category`),
KEY `idnumber` (`idnumber`),

View File

@ -1384,6 +1384,12 @@ function main_upgrade($oldversion=0) {
$new->value = 0;
insert_record('config', $new);
}
if ($oldversion < 2005100400) {
table_column('course','','enrollable','integer','1','unsigned','1');
table_column('course','','enrolstartdate','integer');
table_column('course','','enrolenddate','integer');
}
return $result;
}

View File

@ -52,7 +52,10 @@ CREATE TABLE prefix_course (
restrictmodules integer NOT NULL default '0',
expirynotify integer NOT NULL default '0',
expirythreshold integer NOT NULL default '0',
notifystudents integer NOT NULL default '0'
notifystudents integer NOT NULL default '0',
enrollable integer NOT NULL default '1',
enrolstartdate integer NOT NULL default '0',
enrolenddate integer NOT NULL default '0'
);
CREATE UNIQUE INDEX prefix_course_category_sortorder_uk ON prefix_course (category,sortorder);

View File

@ -6,7 +6,7 @@
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
$version = 2005100300; // YYYYMMDD = date
$version = 2005100400; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.6 development'; // Human-friendly version name