/** * Create/Update ldap group as tl_member_group * @param serialized array $varValue * @return serialized array $varValue */ public static function updateMemberGroups($varValue) { $arrSelectedLdapMemberGroups = deserialize($varValue, true); if (!empty($arrSelectedLdapMemberGroups)) { $arrLdapMemberGroups = LdapMemberGroupModel::getLdapMemberGroups(); if (!is_array($arrLdapMemberGroups) || empty($arrLdapMemberGroups)) { return $varValue; } // ldap groups foreach ($arrLdapMemberGroups as $k => $v) { // selected ldap groups in settings foreach ($arrSelectedLdapMemberGroups as $gid) { if (isset($v['gidnumber']) && $v['gidnumber'][0] == $gid) { $objMemberGroup = \MemberGroupModel::findBy('ldapGid', $gid); if ($objMemberGroup === null) { $objMemberGroup = new \MemberGroupModel(); $objMemberGroup->ldapGid = $gid; } $objMemberGroup->tstamp = time(); // name if (isset($v['cn'])) { $objMemberGroup->name = $v['cn'][0]; } else { $objMemberGroup->name = $gid; } $objMemberGroup->save(); } } } LdapMember::updateMembers($arrSelectedLdapMemberGroups); } return $varValue; }
public static function getLdapMemberGroupsByUid($uid) { $arrMemberGroups = LdapMemberGroupModel::getLdapMemberGroups(); $arrOptions = array(); if (!is_array($arrMemberGroups) || empty($arrMemberGroups)) { return $arrOptions; } foreach ($arrMemberGroups as $key => $group) { if (!isset($group['memberuid']) || !is_array($group['memberuid'])) { continue; } $idx = array_search($uid, $group['memberuid']); if (!$idx || !isset($group['gidnumber'][0])) { continue; } $arrOptions[] = $group['gidnumber'][0]; } return $arrOptions; }