This authentication plugin automatically enrolls users into cohorts.
Cohort name depends on user profile field.
Cohorts are created in CONTEXT_SYSTEM.
If you use an Email based self registration or similar plugin and users enrolls into cohort after second login copy/paste this code into moodle/themes/your_theme/layout/general.php (or default.php)
NOTE: Enable and configure mcae plugin first!
<?php
global $SESSION, $USER;
if ($USER->id != 0) { // Only for autenticated users
$mcae = get_auth_plugin('mcae'); //Get mcae plugin
if (isset($SESSION->mcautoenrolled)) {
if (!$SESSION->mcautoenrolled) {
$mcae->user_authenticated_hook($USER,$USER->username,""); //Autoenrol if mcautoenrolled FALSE
}
} else {
$mcae->user_authenticated_hook($USER,$USER->username,""); //Autoenrol if mcautoenrolled NOT SET
}
}
?>
Template for cohort name
1 template per line.
In the template you may use any characters (except '{' and '}') and profile field values. To insert a profile field value, use {{ field_name }}
tag.
An email fields have 4 variants:
{{ email.full }}
- full email{{ email.username }}
- only username{{ email.domain }}
- only domain{{ email.rootdomain }}
- root domain{{ id }}, {{ auth }}, {{ confirmed }}, {{ policyagreed }}, {{ deleted }}, {{ suspended }}, {{ mnethostid }}, {{ username }}, {{ idnumber }}, {{ firstname }}, {{ lastname }}, {{ email.full }}, {{ email.username }}, {{ email.domain }}, {{ email.rootdomain }}, {{ emailstop }}, {{ icq }}, {{ skype }}, {{ yahoo }}, {{ aim }}, {{ msn }}, {{ phone1 }}, {{ phone2 }}, {{ institution }}, {{ department }}, {{ address }}, {{ city }}, {{ country }}, {{ lang }}, {{ calendartype }}, {{ theme }}, {{ timezone }}, {{ firstaccess }}, {{ lastaccess }}, {{ lastlogin }}, {{ currentlogin }}, {{ lastip }}, {{ secret }}, {{ picture }}, {{ url }}, {{ descriptionformat }}, {{ mailformat }}, {{ maildigest }}, {{ maildisplay }}, {{ autosubscribe }}, {{ trackforums }}, {{ timecreated }}, {{ timemodified }}, {{ trustbitmask }}, {{ imagealt }}, {{ lastnamephonetic }}, {{ firstnamephonetic }}, {{ middlename }}, {{ alternatename }}, {{ lastcourseaccess }}, {{ currentcourseaccess }}, {{ groupmember }}
Additional tags become available if you have some custom profile fields. For example if you create custom profile fields
checkboxtest
- type Checkboxdatetimetest
- type Date/Timedroptest
- type Dropdown menutextinputtext
- type Text inputtextareatest
- type Text areaYou are able to use these tags: {{ profile.checkboxtest }}, {{ profile.datetimetest }}, {{ profile.droptest }}, {{ profile.textinputtext }}, {{ profile_field_checkboxtest }}, {{ profile_field_datetimetest }}, {{ profile_field_droptest }}, {{ profile_field_textareatest.text }}, {{ profile_field_textareatest.format }}, {{ profile_field_textinputtext }}
Note: Profile field templates are case sensitive.
{{ username }}
and{{ UserName }}
are two different fields!
Split arguments: Synopsis: %split(fieldname|delimiter)
Returns multiple cohorts, each of which is formed by splitting field on boundaries formed by the delimiter.
Arguments:
Example:
User John fills the custom profile field "Known languages" with the value "English, Spanish, Chinese"
Main template contains string "Language - %split(knownlanguage|, )"
John will be enrolled in 3 cohorts: Language - English, Language - Spanish and Language - Chinese
Replace empty field
If profile field is empty then it's replaced with this value.
Replacement array
You can change the cohort name after it's generation.
1 replacement per line, format - old value|new value
very long cohort name|shortname
Note: The name must not be longer than 100 characters or it will be truncated
Unenroll
Unenroll users from cohorts after profile change.
To use an unenroll feature:
Convert only cohorts that are created by the "auth_mcae" module!
At yourmoodle/auth/mcae/convert.php page you may view, delete or convert cohorts into "manual" or "auth_mcae" mode.
Ignore users
List of users to ignore. Comma separated usernames.
admin,test,manager,teacher1,teacher2
You have a custom profile fields "status" (student, teacher or admin) and "course".
You wnat to enrol many users into cohorts like "course - status" than enrol cohorts into courses.
At configuration page set:
Main template to {{ profile_field_course }} - {{ profile_field_status }}
Empty field text to none
Result:
To rename "none - admin" cohort to "Administration" you must set a replacement array field at the configuration page In our case: none - admin|Administrator
Result:
When admin logins, he's enrolled in a cohort named "Administrator"