Moodle Plugins directory: Smart Cohort | Moodle.org

Smart Cohort
We developed the Smart Cohort module based on our years of experience in Moodle operation and development. Course creators, site administrators and teachers are surely familiar with cohorts in the system that allow new colleagues / students to be easily enrolled in the appropriate courses. The users only have to be added to the group and the rest is automatically arranged by the system.
The Smart Cohort Module allows authorized users to define filtering criteria and to specify which cohort the filtered users would be added to. This add-on works well with any authentication plugins, so when the user is created or its data gets updated, the system checks for which groups to add to or remove the user from based on the filtering criteria.
The module was originally developed for our partners, but we feel like that this community would also find it useful, so we've made it available to you for free. With the help of this module it's easier for our partners to identify courses based on area, job, position, and they do not have to deal with managing cohorts.
Can a deletion of users who no longer meet the criteria of the cohort be considered in a future development?
Indeed, I use Azure AD and the Microsoft Dev Center to manage my users.
when a student leaves a training, I remove them from Azure AD but they remain enrolled in the cohort.
Additionally, the email filter does not work. It is possible to create filters in the Smartcohort plugin as follows: if the value of the "Email Address" field is equal to, different from, begins with, or ends with a certain value.
I am trying to exclude ALL users who do not have an email address ending in "@my-organization.com" using a filter to populate a cohort named "External Users." However, if I use the "different from" filter (than "@my-organization.com"), it considers all Moodle emails, as they are all different from "@my-organization.com". This results in all Moodle users being added to the cohort, which is not the desired outcome.
If we look at how Moodle's "native" filters work (users -> batch actions on users), it is possible to achieve the desired result by using the "does not contain" filter with "@my-organization.com". I do get the list of external users that I am trying to automatically place in a cohort.
This filter is unusable to properly filter email addresses. It should behave like Moodle's filter.
I just wanted to let you know that a patch is now available for the Smart Cohort plugin. This patch addresses two issues that have been reported:
1. the not equal filter was not properly handling email addresses, leading to incorrect results :
I added the following code block to handle the "not equals" operator for the email field
if (!empty($queryParams) && $rule->field == 'email' && $operator == '<>') {
$sql .= " AND u.email NOT LIKE '" . implode('', $queryParams) . "'";
$queryWhere == false;
}
the code checks if there are non-empty query parameters and if the current field is the email field with the "not equals" operator,It appends an additional condition to the SQL query using NOT LIKE to exclude the specified email(s) from the results.
The $queryWhere variable is set to false to indicate that an additional condition has been added.
link to the pull request :
https://github.com/cnw-co/moodle-local_cnw_smartcohort/pull/6
2. Display filters when deleting were not working as expected:
I modified the parameter $with_deleted from false to true in the if statement:
if ($with_deleted == true) {
return $DB->get_records_sql("SELECT * FROM {cnw_sc_filters} WHERE deleted_flag = 0");
} else {
return $DB->get_records('cnw_sc_filters');
}
This change ensures that when the $with_deleted parameter is set to true, the function retrieves all records from the cnw_sc_filters table, including those with a deleted_flag value of 0 (not deleted).
link to the pull request :
https://github.com/cnw-co/moodle-local_cnw_smartcohort/pull/7
We plan to add an or operator in a later release, until then most filtering cases requiring it can be done with more rules.
Thank you for reporting these issues!
The one with the active filter removal was fixed. We could not reproduce the other one. Could you give us more details, please?
Can you provide a cronlog and tasklog for me?
My e-mail address is: moodle (at) cnw (dot) com
Thanks!
I’ve recently installed the Smart Cohort Plugin. When I create a rule they always remain “in progress”.
Looking at the task log it fails due to trying to order by Name which is an unknown field.
My Moodle version is 4.0.2 and I downloaded the smart cohort plugin version 2.0.5 (2023081800)
I can send through a task log. It won't let me post it here.
These are the 25 cohorts that appear on page 1 when viewing System Cohorts (Accounts > System Cohorts) and those on page 2 and beyond don't appear in the plugin's drop down list of cohorts that rules can be applied to.
Can this be extended so rules can be applied to all cohorts within moodle?
Many thanks.
Plugin version 2.05 (2023081800)
Moodle version 4.0.4 (Build: 20220912)
We have been using the Smart Cohort plugin for some time now, many thanks to the developers! Managers have the ability to manage Smart Cohorts and can do so by pasting the link into the address bar of their browser. However, they do not see the link to this page in "Site Administration". Is this intentional or is there a bug in my system? If you have had this problem, has anyone been able to fix it?
Moodle 4.1
Plugin 1.0.0 (2019050603).
Any help is appreciated!