Using Cohort Values in Registration Form

Using Cohort Values in Registration Form

by Jakob Engelhardt -
Number of replies: 2
Hello everyone!

An integral part of our moodle installation is the ability for users to select a cohort in the registry. The cohorts can be selected using the dropdown in the registration form.

However, the website needs to be available in multiple languages so we have to translate the dropdown content. Using Multi-Lang filters like {mlang en} causes problems because the dropdown data must be exported for further usage (the export has to be in English).

Is it possible to pull the cohort names from the cohort lists instead? The dropdown would contain the cohort names in their respective languages, but we would refer to the English name in the export file. Is the function cohort_get_available_cohorts() getting the data we need? The function requires a context-ID - how/where can I get the correct context-ID?

I've put the code snippet below. The profile field company_classification is the dropdown field.

$classificationField = $mform->getElement('profile_field_company_classification');
$classificationField->removeOptions();

require_once($CFG->dirroot . '/cohort/lib.php');

$cohorts = cohort_get_available_cohorts($PAGE->context);

Average of ratings: -
In reply to Jakob Engelhardt

Re: Using Cohort Values in Registration Form

by Alex M -
cohort_get_cohorts(1) should work --- I think 1 is the global context, but I am not sure.
In reply to Alex M

Re: Using Cohort Values in Registration Form

by Alex M -
this seems to be the correct way:

$cohorts = cohort_get_cohorts(SYSCONTEXTID);