This document will provide the information needed to setup an enrollment .csv file and successfully enroll users into courses by using the .csv flat file type for enrolments. Flat file enrolment allows you to enroll users in bulk without having to manually enter the information from the user interface. The file created is saved as a comma separated value (.csv)
The article has been split into different sections to make it easier to follow along.
Sections/Summary of the Steps
Before getting into the details of flat file enrolments, please note the following Sections/Steps.
- Section 1: Setting up the .csv file
- Section 2: Verify Users Already Exist
- Section 3: User ID Numbers
- Section 4: Example of .csv file formats
- Section 5: Configuring the flat file enrolments
This article will also expand upon the following.
Section 1: Setting up the .csv file
You will need to structure your excel spreadsheet with the following required fields. There are 4 required fields that are necessary with 2 that are optional (starttime, endtime)(see below for list) all the other fields of operation, role, user idnumber, course idnumber are required.
The field names provide the functionally of:
• operation - add | del
• role - student | teacher | teacheredit
• user idnumber - idnumber in the user table NB not id
• course idnumber - idnumber in the course table NB not id
• starttime - start time (in seconds since epoch) – optional
• endtime - end time (in seconds since epoch) – optional
There are a number of roles that can be entered into the file under the role field.(see below) Bold-indicates how to enter the role into the field.
• Manager - Default:manager
• Course creatorDefault: coursecreator
• TeacherDefault: editingteacher
• Non-editing teacherDefault: teacher
• StudentDefault: student
• GuestDefault: guest
• Authenticated userDefault: user
• Authenticated user on frontpageDefault: frontpage
Section 2: Verify Users Already Exist
Make sure users have already been created. If not, create users first.
Section 3: User ID Numbers
If you don’t have user id numbers issued, you will need to in order to successfully enroll using a .csv flatfile. Additionally,it is important to note that the user idnumber has to be added in this location in order to populate as an enrolled user. Please follow the below breadcrumb:
Edit user profile fields by going from the:
Administration block > Site Administration > Users > Accounts > Browse list of users > click edit beside the user
Click on the Optional title and go to the ID Number field and enter a user ID number
Section 4: Examples of .csv File Enrolments
The first example here shows the operation of how to add a student, teacher or any other role if needed. The second example shows the operation of how to delete a student, teacher or any other role.
Figure 1: Sample .csv file for adding enrolments (this is how the .csv file should look)
Figure 2: Sample .csv file for deleting enrolled users (this is how the .csv file should look)
Section 5: Configuring the Flat File Enrolments
Now that your data has been saved in the .csv format, we need to place the flat file on the ftp site in the following directory
Example: /home/ftpsitename/moodledata/flatfile/enrollments/enrollments_2.csv ( Moodle needs to know where the file is located when uploading).
Next go to: Administration block > Site administration > Plugins > Enrolments > Flat file (CSV)
In the File location field specify the path ie: /home/ftpsitename/moodledata/flatfile/enrollments/enrollments_2.csv
NOTE 1: File must be in a comma delimited .csv format in order to upload successfully. Then Save Changes.
NOTE 2: CRON must also run in order to see changes. ( will take place automatically)
Figure 3: Example of users were added to the course via flatfile in the following roles of Student and Teacher. This area can be reached by entering a course > Administration block > Course Administration > Users > Enrolled users
Figure 4: When a .csv file is run with deleted enrollments you will notice that only the role itself is removed and the user becomes suspended.This area can be reached by entering a course > Administration block > Course Administration > Users > Enrolled users
Figure 5: Provides an example of what the Student will experience if removed from a course as access will no longer be granted.
Best Practices and Common Mistakes
1. File must be 'Saved As' with an extension of .csv
2. Make sure users have already been created.
3. ID number field must be filled in.
4. File does not appear in location but access (login) to the server is possible? Try switching from a full path to a relative path