Auto assign cohort (deprecated for local_cohortauto)

Authentication ::: auth_mcae
Maintained by Dan Marsden, Catalyst IT
This Authentication plugin automatically assigns users into cohorts based on information in their user profile fields.
Latest release:
272 sites
7 downloads
51 fans
Current versions available: 6

PLEASE NOTE - this plugin has been deprecated and replaced by:
https://github.com/catalyst/moodle-local_cohortauto




---------------------------

Auto cohort authentication plugin

This authentication plugin automatically assigns users into cohorts.

Cohort name depends on user profile field.

Cohorts are created in CONTEXT_SYSTEM.

Installation

  • Download the archive and extract the files, or clone the repository from GitHub
  • Copy the 'mcae' folder into your_moodle/auth
  • Visit Site administration - Notifications page and follow the instructions

Configuration

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 field have 3 variants:

  • {{ email.full }} - full email
  • {{ email.username }} - only username
  • {{ email.domain }} - only domain
  • {{ email.rootdomain }} - root domain

By default moodle provides this fields

{{ 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 Checkbox
  • datetimetest - type Date/Time
  • droptest - type Dropdown menu
  • textinputtext - type Text input
  • and textareatest - type Text area

You be able to use this 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 is 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:

  • fieldname - Profile field name. The same as tag, but without '{{' and '}}'
  • delimiter - The boundary string. 1 - 5 signs.

Example:

User John set custom profile field "Known languages" to "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 stripped

Unassign

Unassign users from cohorts after profile change.

To use an unassign feature:

  • Go to Plugins - Authentication - Autoenrol cohort and enable unenrol function
  • Go to yourmoodle/auth/mcae/convert.php and convert cohorts you want to "auth_mcae".

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

Usage example

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:

  • When 1st course student logins, he enrol to cohort named "1 - student"
  • When 1st course teacher logins, he enrol to cohort named "1 - teacher"
  • When admin logins, he enrol to cohort named "none - admin" (Course not set, status - admin)

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 enrol to cohort named "Administrator"

Screenshots

Screenshot #0
Screenshot #1
Screenshot #2

Contributors

Dan Marsden (Lead maintainer)
Andrew Kama: Previous maintainer
Please login to view contributors details and/or to contact them

Comments RSS

Comments

  • Annick F
    Tue, 22 Jan 2013, 7:34 PM
    Is this plugin available for Moodle 2.4?

    Thanks
  • Simon Bryan
    Wed, 30 Jan 2013, 12:36 PM
    OK, this looks exactly what I need. I have a cohort called AllUsers and want all users automagically added to it when they register with Moodle.
    But I am confused as to what goes in the various fields. So to achieve this what values would I use - no issue in deleting that cohort as it has no users yet anyway if that is needed.
  • Simon Bryan
    Wed, 30 Jan 2013, 12:43 PM
    OK, took a wild guess and just added my AllUsers cohort to the first box and bingo - too easy - thanks
  • Mark Andrews
    Thu, 7 Feb 2013, 12:03 AM
    Hey Andrew - Just tested on 2.4 seems to be working for me! - only issue is that the 'cohort operations' & 'cohort viewer' links are displayed at the root of the settings menu would these be perhaps better placed within the autoenrol cohort settings or within users > accounts?

    Really useful plugin though!
  • Educational Technology Leaders LLC
    Fri, 15 Mar 2013, 12:30 PM
    Great plugin, very useful. I was able to use it with Moodle 2.4.1 but I have to add the line:

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

    at the beginning of auth/mcae/auth.php as it was posted by Francis Vendrell. Thanks again
  • Alan Hare
    Tue, 16 Apr 2013, 12:43 AM
    Very nice plugin, but received error with 2.5 when selecting [Cohort Viewer] menu option

    Error reading from database
    More information about this error

    Debug info: SQLState: 42000

    Error Code: 195

    Message: [Microsoft][SQL Server Native Client 11.0][SQL Server]'CONCAT' is not a recognized built-in function name.


    SELECT u.id AS uid, CONCAT(u.firstname, ' ', u.lastname) AS usrname FROM mdl_cohort_members AS cm JOIN mdl_user AS u ON u.id = cm.userid WHERE cm.cohortid = '0' ORDER BY usrname
    [array (
    0 => 0,
    )]
    Error code: dmlreadexception
    Stack trace:
    ◦line 426 of \lib\dml\moodle_database.php: dml_read_exception thrown
    ◦line 260 of \lib\dml\sqlsrv_native_moodle_database.php: call to moodle_database->query_end()
    ◦line 367 of \lib\dml\sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database->query_end()
    ◦line 779 of \lib\dml\sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database->do_query()
    ◦line 827 of \lib\dml\sqlsrv_native_moodle_database.php: call to sqlsrv_native_moodle_database->get_recordset_sql()
    ◦line 37 of \auth\mcae\view.php: call to sqlsrv_native_moodle_database->get_records_sql()
  • Alan Hare
    Tue, 16 Apr 2013, 1:00 AM
    FIXED: Changed line (36) in /auth/mcae/view.php to read

    From:
    $sql = "SELECT u.id AS uid, CONCAT(u.firstname, ' ', u.lastname) AS usrname FROM {cohort_members} AS cm JOIN {user} AS u ON u.id = cm.userid WHERE cm.cohortid = ? ORDER BY usrname";

    TO:
    $sql = "SELECT u.id AS uid, (u.firstname + ' ' + u.lastname) AS usrname FROM {cohort_members} AS cm JOIN {user} AS u ON u.id = cm.userid WHERE cm.cohortid = ? ORDER BY usrname";
  • Sam Stegers
    Thu, 6 June 2013, 10:14 PM
    Great plugin indeed!!

    However when change the value in the profile field based on which the autoenrol occurs, the user is nicely enrolled into the new cohort.

    BUT!!

    The user also stays enrolled in the previous cohort, thus the user is now enrolled in the "old" cohort and in the "new" cohort.

    Would it be possible to add this to the plugin? Perhaps a setting where you can define is the plugin should or should not unenrol users when the profile fields are changed.

    Highest regards,

    Sam
  • Andrew Kama
    Fri, 7 June 2013, 2:57 PM
    Hi Sam!

    To enable autounenroll users:
    1. Go to moodle/auth/mcae/convert.php page
    2. Select cohorts you want and convert to "auth_mcae"
    3. At the plugin configuration page check "Enable / Disable automatic unenrol" option.

    If "Enable / Disable automatic unenrol" option enabled:
    1. Manually created cohorts are managed by admin
    2. Automatically created cohorts are managed by plugin
    3. To view cohort members go to moodle/auth/mcae/view.php page
  • John Anderson
    Wed, 19 June 2013, 9:11 AM
    Can I use this to auto enrol a user to a cohort based on email domain? Or does it have to be a profile field ?
  • John Anderson
    Thu, 20 June 2013, 8:55 AM
    I cannot understand the instructions. Could someone who has had success with this plugin provide their examples? I would like to help with the documentation, after I have a working example.
  • Kevin TREUSSIER
    Wed, 3 July 2013, 4:02 PM
    Very great Plugin !

    It's exactly what I need to create cohort corresponding to groups that exist in a shibboleth attributes that I receipt.

    I just need 1 improvement if it's possible :
    The field I request contain multi-values, separate by a ";" (in exemple "gs2;GIPAD-GS2", or "gs2;AII-GS2")
    Is it possible to split this cohort in 2 or more cohorts, defining by a separator parameter (in my case ";" to obtain 3 cohorts ("gs2", "GIPAD-GS2" and "AII-GS2") rather than 2 ("gs2;GIPAD-GS2" and "gs2;AII-GS2")) ?

    Thanks a lot for this plugin.

    Kevin
  • Kevin TREUSSIER
    Mon, 12 Aug 2013, 6:59 PM
    Hello,

    Thanks a lot Andrew for this new release with the improvement I need.
    It is exactly what I want and it works great !

    Kevin
  • chispol rios
    Tue, 20 Aug 2013, 7:48 AM
    Hi, is there more documentation related this plugin?
  • Andrew
    Thu, 22 Aug 2013, 4:37 AM
    Fantastic plugin.
Please login to post comments