Merge branch 'MDL-65404-master' of https://github.com/aanabit/moodle

This commit is contained in:
Adrian Greeve 2019-08-20 10:13:31 +08:00
commit 0ee9c67dfb
4 changed files with 42 additions and 4 deletions

View File

@ -1039,6 +1039,7 @@ if ($formdata = $mform2->is_cancelled()) {
if ($roleid) {
// Find duration and/or enrol status.
$timeend = 0;
$timestart = $today;
$status = null;
if (isset($user->{'enrolstatus'.$i})) {
@ -1054,16 +1055,23 @@ if ($formdata = $mform2->is_cancelled()) {
}
}
if (!empty($user->{'enroltimestart'.$i})) {
$parsedtimestart = strtotime($user->{'enroltimestart'.$i});
if ($parsedtimestart !== false) {
$timestart = $parsedtimestart;
}
}
if (!empty($user->{'enrolperiod'.$i})) {
$duration = (int)$user->{'enrolperiod'.$i} * 60*60*24; // convert days to seconds
if ($duration > 0) { // sanity check
$timeend = $today + $duration;
$timeend = $timestart + $duration;
}
} else if ($manualcache[$courseid]->enrolperiod > 0) {
$timeend = $today + $manualcache[$courseid]->enrolperiod;
$timeend = $timestart + $manualcache[$courseid]->enrolperiod;
}
$manual->enrol_user($manualcache[$courseid], $user->id, $roleid, $today, $timeend, $status);
$manual->enrol_user($manualcache[$courseid], $user->id, $roleid, $timestart, $timeend, $status);
$a = new stdClass();
$a->course = $shortname;

View File

@ -204,7 +204,7 @@ function uu_validate_user_upload_columns(csv_import_reader $cir, $stdfields, $pr
// hack: somebody wrote uppercase in csv file, but the system knows only lowercase profile field
$newfield = $lcfield;
} else if (preg_match('/^(sysrole|cohort|course|group|type|role|enrolperiod|enrolstatus)\d+$/', $lcfield)) {
} else if (preg_match('/^(sysrole|cohort|course|group|type|role|enrolperiod|enrolstatus|enroltimestart)\d+$/', $lcfield)) {
// special fields for enrolments
$newfield = $lcfield;

View File

@ -145,3 +145,30 @@ Feature: Upload users
And I should see "Users created: 4"
And I press "Continue"
And I log out
@javascript
Scenario: Upload users setting their enrol date and period
Given the following "courses" exist:
| fullname | shortname | category |
| Maths | math102 | 0 |
# Upload the users.
And I change window size to "large"
And I log in as "admin"
And I navigate to "Users > Accounts > Upload users" in site administration
When I upload "lib/tests/fixtures/upload_users_enrol_date_period.csv" file to "File" filemanager
And I press "Upload users"
Then I should see "Upload users preview"
And I press "Upload users"
# Check user enrolment start date and period
And I am on "Maths" course homepage
Then I navigate to course participants
And I click on "Manual enrolments" "link" in the "Student One" "table_row"
Then I should see "1 January 2019" in the "Enrolment starts" "table_row"
And I should not see "Enrolment ends"
And I click on "Close" "button"
And I click on "Manual enrolments" "link" in the "Student Two" "table_row"
Then I should see "2 January 2020" in the "Enrolment starts" "table_row"
And I should see "12 January 2020" in the "Enrolment ends" "table_row"
And I click on "Close" "button"
And I log out

View File

@ -0,0 +1,3 @@
username,password,firstname,lastname,email,course1,enroltimestart1,enrolperiod1
student1,Student1#,Student,One,student1@example.com,math102,2019-01-01,
student2,Student2#,Student,Two,student2@example.com,math102,2020-01-02,10
1 username password firstname lastname email course1 enroltimestart1 enrolperiod1
2 student1 Student1# Student One student1@example.com math102 2019-01-01
3 student2 Student2# Student Two student2@example.com math102 2020-01-02 10