mirror of
https://github.com/moodle/moodle.git
synced 2025-04-20 07:56:06 +02:00
Various fixes, especially related to using timestart and timeend
for new enrolments
This commit is contained in:
parent
9ddc0efd8e
commit
76b60bb897
@ -138,8 +138,15 @@ function print_entry($course) {
|
||||
exit;
|
||||
|
||||
} else {
|
||||
if ($course->enrolperiod == 0) {
|
||||
$timestart = 0;
|
||||
$timeend = 0;
|
||||
} else {
|
||||
$timestart = time();
|
||||
$timeend = time() + $course->enrolperiod;
|
||||
}
|
||||
|
||||
if (! enrol_student($USER->id, $course->id)) {
|
||||
if (! enrol_student($USER->id, $course->id, $timestart, $timeend)) {
|
||||
error("An error occurred while trying to enrol you.");
|
||||
}
|
||||
add_to_log($course->id, "course", "enrol", "view.php?id=$course->id", "$USER->id");
|
||||
@ -268,6 +275,20 @@ function process_config($config) {
|
||||
*
|
||||
*/
|
||||
function cron() {
|
||||
// Delete students from all courses where their enrolment period has expired
|
||||
|
||||
$select = "timeend > '0' AND timeend < '" . time() . "'";
|
||||
|
||||
if ($students = get_records_select('user_students', $select)) {
|
||||
foreach ($students as $student) {
|
||||
unenrol_student($student->userid, $student->course);
|
||||
}
|
||||
}
|
||||
if ($teachers = get_records_select('user_teachers', $select)) {
|
||||
foreach ($teachers as $teacher) {
|
||||
remove_teacher($teacher->userid, $teacher->course);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,17 +41,22 @@ function check_entry($form, $course) {
|
||||
/**
|
||||
* Override the base cron() function to read in a file
|
||||
*
|
||||
* Comma separated file assumed to have four fields per line:
|
||||
* operation, role, idnumber(user), idnumber(course)
|
||||
* Comma separated file assumed to have four or six fields per line:
|
||||
* operation, role, idnumber(user), idnumber(course) [, starttime, endtime]
|
||||
* where:
|
||||
* operation = add | del
|
||||
* role = student | teacher | teacheredit
|
||||
* idnumber(user) = idnumber in the user table NB not id
|
||||
* idnumber(course) = idnumber in the course table NB not id
|
||||
* starttime = start time (in seconds since epoch) - optional
|
||||
* endtime = end time (in seconds since epoch) - optional
|
||||
*/
|
||||
function cron() {
|
||||
global $CFG;
|
||||
|
||||
/// call the base class
|
||||
parent::cron();
|
||||
|
||||
if (empty($CFG->enrol_flatfilelocation)) {
|
||||
$filename = "$CFG->dataroot/1/enrolments.txt"; // Default location
|
||||
} else {
|
||||
@ -73,7 +78,7 @@ function check_entry($form, $course) {
|
||||
|
||||
|
||||
/// If a line is incorrectly formatted ie does not have 4 comma separated fields then ignore it
|
||||
if ( count($fields) != 4) {
|
||||
if (count($fields) != 4 and count($fields) !=6) {
|
||||
if ( count($fields) > 1 or strlen($fields[0]) > 1) { // no error for blank lines
|
||||
$this->log .= "$line: Line incorrectly formatted - ignoring\n";
|
||||
}
|
||||
@ -85,9 +90,19 @@ function check_entry($form, $course) {
|
||||
$fields[1] = trim(strtolower($fields[1]));
|
||||
$fields[2] = trim($fields[2]);
|
||||
$fields[3] = trim($fields[3]);
|
||||
|
||||
$this->log .= "$line: $fields[0] $fields[1] $fields[2] $fields[3] ";
|
||||
|
||||
if (!empty($fields[5])) {
|
||||
$fields[4] = (int)trim($fields[4]);
|
||||
$fields[5] = (int)trim($fields[5]);
|
||||
$this->log .= "$fields[4] $fields[5]";
|
||||
} else {
|
||||
$fields[4] = 0;
|
||||
$fields[5] = 0;
|
||||
}
|
||||
|
||||
|
||||
$this->log .= "$line: $fields[0] $fields[1] $fields[2] $fields[3]: ";
|
||||
$this->log .= ":";
|
||||
|
||||
|
||||
|
||||
@ -116,12 +131,17 @@ function check_entry($form, $course) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if ($fields[4] > $fields[5]) {
|
||||
$this->log .= "Start time was later than end time - ignoring line\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
unset($elog);
|
||||
switch ($fields[1]) {
|
||||
case "student":
|
||||
if ($fields[0] == "add") {
|
||||
if (! enrol_student($user->id, $course->id)) {
|
||||
if (! enrol_student($user->id, $course->id, $fields[4], $fields[5])) {
|
||||
$elog = "Error enrolling in course\n";
|
||||
}
|
||||
} else {
|
||||
@ -133,7 +153,7 @@ function check_entry($form, $course) {
|
||||
|
||||
case "teacher":
|
||||
if ($fields[0] == "add") {
|
||||
if (! add_teacher($user->id, $course->id, 0)) {
|
||||
if (! add_teacher($user->id, $course->id, 0, '', $fields[4], $fields[5])) {
|
||||
$elog = "Error adding teacher to course\n";
|
||||
}
|
||||
} else {
|
||||
@ -145,7 +165,7 @@ function check_entry($form, $course) {
|
||||
|
||||
case "teacheredit":
|
||||
if ($fields[0] == "add") {
|
||||
if (! add_teacher($user->id, $course->id, 1)) {
|
||||
if (! add_teacher($user->id, $course->id, 1, '', $fields[4], $fields[5])) {
|
||||
$elog = "Error adding teacher to course\n";
|
||||
}
|
||||
} else {
|
||||
|
@ -3,3 +3,4 @@ add, teacher, 6, CF101
|
||||
add, teacheredit, 7, CF101
|
||||
del, student, 8, CF101
|
||||
del, student, 17, CF101
|
||||
add, student, 21, CF101, 1091115000, 1091215000
|
||||
|
@ -78,6 +78,10 @@ function get_access_icons($course) {
|
||||
$strrequirespayment = get_string("requirespayment");
|
||||
$strcost = get_string("cost");
|
||||
|
||||
if (empty($CFG->enrol_paypalcurrency)) {
|
||||
$CFG->enrol_paypalcurrency = 'USD';
|
||||
}
|
||||
|
||||
switch ($CFG->enrol_paypalcurrency) {
|
||||
case 'EUR': $currency = '€'; break;
|
||||
case 'CAD': $currency = '$'; break;
|
||||
@ -87,7 +91,7 @@ function get_access_icons($course) {
|
||||
}
|
||||
|
||||
$str .= "<p>$strcost: <a title=\"$strrequirespayment\" href=\"$CFG->wwwroot/course/view.php?id=$course->id\">";
|
||||
$str .= "$currency $cost</a></p>";
|
||||
$str .= "$currency".format_float($cost,2).'</a></p>';
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user