Upload cohorts

From MoodleDocs
(Redirected from cohort/upload)

An administrator can upload multiple cohorts from a CSV (comma separated values) formatted text file in Administration > Site administration > Users > Accounts > Cohorts > Upload cohorts. 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 added to it from the Upload users page, using an appropriately formatted .CSV file.

Upload cohort process

Here is an outline of the process:

  1. Create cohort file for uploading (CSV text file with a 'name' column and the name of each new cohort on a new line)
  2. Go to Administration > Site administration > Users > Accounts > Cohorts > Upload cohorts'
  3. Add 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. site-wide). 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 for the upload cohorts file

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

:Tip: Avoid special characters in field information like quotes or other commas. Test a file with only one record before a large upload. :Tip: 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.

Valid upload file for testing

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 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

Fields that can be included

  • Required fields:
name - the name of the cohort to be created
  • Optional fields: To provide values other than the default include one or more of the following optional fields:
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.

See also