How to get a cohort being syncronised with a ldap server ?

Re: How to get a cohort being synchronised with a ldap server ?

by Guybrush Threepwood -
Number of replies: 1

Hi!


Reading Visvanath Ratnaweera's deep dive (https://moodle.org/mod/forum/discuss.php?d=378935), it helped me to point what was wrong in my configuration: in my Moodle auth_ldap configuration, memberattribute was empty. I set it to "member" and now cohorts are created in populated correctly.

Now I want to have the "displayName" attribute of the groupe to be used instead of the name (CN).

The plugin dot now allow to change this unfortunately.

Looking into the code, it looks like the name of the group is specified on line 163 in localib.php:

array_push($fresult, ($groups[$i][$this->config->group_attribute][0]));


How to replace "groupe_attribute", that is CN, with the "displayName" attribute?

In reply to Guybrush Threepwood

Re: How to get a cohort being synchronised with a ldap server ?

by Guybrush Threepwood -

I managed the change in code to use the DisplayName (if set) of a group instead of the CN.

In locallib.php.

In function ldap_get_grouplist

line 148:

$ldapresult = ldap_search($ldapconnection, $context, $filter, array ($this->config->group_attribute));

becomes

$ldapresult = ldap_search($ldapconnection, $context, $filter, array ($this->config->group_attribute, "displayName"));


line 151:

$ldapresult = ldap_list($ldapconnection, $context, $filter, array ($this->config->group_attribute));

becomes

$ldapresult = ldap_list($ldapconnection, $context, $filter, array ($this->config->group_attribute, "displayName"));


line 162:

array_push($fresult, ($groups[$i][$this->config->group_attribute][0]));

becomes

array_push($fresult, ($groups[$i]));


in function sync_cohorts_by_group

replace line 639:

foreach ($ldapgroups as $groupname) {

with

foreach ($ldapgroups as $ldapgroup) {
   $groupname = $ldapgroup[$this->config->group_attribute][0];
   if($ldapgroup["displayname"][0]===NULL){
    $displayName = $groupname;
   }
   else{
    $displayName = $ldapgroup["displayname"][0];
   }

could be improved with the use of a variable for the displayname of the cohort...

Average of ratings: Useful (1)