Uploading Cohorts

An administrator can upload multiple cohorts from a CSV (comma separated values) formatted text file. Cohorts can be created in both the system (site-wide) context or in the course category context. Once a cohort has been created, new users can be assigned to it.

Step-by-step Guide

To upload cohorts:

  1. Create a CSV file for uploading (the file format is explained later in this document)

  2. Go to Site administration > Users > Accounts > Cohorts > Upload cohorts

  3. Add the file to upload

  4. Upload cohort preview - review settings and check for any errors. If errors are reported with the file, correct as needed.

  5. Upload cohorts - click "Upload cohorts"

  6. Upload cohorts results - shows how many cohorts were created

  7. Upload cohorts results - click "Continue"

  8. Returns to Upload users screen

Settings

File

The CSV formatted text file containing cohort data to be uploaded. See the File format for the upload cohorts file section for more detailed information about the cohorts upload file.

CSV delimiter

The character used as a delimiter between fields in the cohort upload file. The delimiter separates the various fields on a single line. By default, a comma (',') is used as the delimiter; however, other options are available.

, - uses the comma character as the field delimiter
; - uses the semicolon character as the field delimiter
: - uses the colon character as the field delimiter
\t - uses \t (tab) as the field delimiter

Encoding

You can specify the character encoding of the upload cohorts file. The default character encoding is UTF-8.

Default context


You can specify the default context to use from a list of available contexts. The default context is the System context (i.e. for the entire system). A list of course categories will be listed and one of those course categories can be selected as the default context if one is not provided in the upload cohorts file. If the contextid (or one of the available fields to lookup the contextid) is provided, then that value will be used; however, if a contextid is not provided for a particular cohort the default context will be used.

File Format

The upload cohorts CSV text file has fields separated by a comma (or other delimiter). The first line contains valid field names (preferrably lower case). The rest of the lines (records) contain information about each new cohort.

Tip #1: Avoid special characters in field information like quotes or other commas. Test a file with only one record before a large upload.

Tip #2: You can use a spreadsheet program to create the file with the required columns and fields. Then save the file as "CSV (comma delimited)". These files can then be opened with simple text editors for verification.

Sample File

Here is an example of a simple valid upload cohorts file.Ā Column headers on the first line of the file are only highlighted in bold in this example to distinguish it from the rest of the of the data/user details.

name,idnumber,description
Class of 2019,2019,Members of the Class of 2019
Class of 2020,2020,Members of the Class of 2020

Valid Fields

Required Fields

The following field is required in all CSV files.

  • name - the name of the cohort to be created

Optional Fields

The following fields are optional.

  • contextid - used to specify the context id number of the cohorts you are uploading. For example, the context id number of a particular course category.

  • idnumber - used to provide an id number for the cohorts you are uploading

  • description - used to provide a description for the cohorts you are uploading

  • descriptionformat - used to specify the text format of the description. By default, the descriptionformat is set to the recommended value of 1 (FORMAT_HTML); however, values of 0 (FORMAT_MOODLE) and 2 (FORMAT_PLAIN) are also available. These format values are defined in lib/weblib.php.

  • visible - used to specify whether the cohorts you are uploading should be visible (1) or not (0).

Additional Fields

If needed, there are some additional fields that while not normally used can be utilized. Additional fields typically require looking up information in other tables (such as the course categories or context tables). The additional fields provide an alternative way of finding the course category context id. A bit of extra caution is recommended in using these additional fields. The list of additional fields includes:

  • context - used to specify the name of the context name for each of the cohorts you are uploading.

  • category - used to specify the name of the category name for each of the cohorts you are uploading. For example, the category name of a particular course category.

  • category_id - used to specify the course category id (not idnumber) of the category for each of the cohorts you are uploading. For example, the course category id of a particular course category.

  • category_idnumber - used to specify the course category idnumber (not id) of the category for each of the cohorts you are uploading. For example, the course category idnumber of a particular course category.

  • category_path - used to specify the course category path of the category for each of the cohorts you are uploading. For example, the course category path of a particular course category.