コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 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;
 }
コード例 #3
0
 public static function doUpdateMember($objMember, $uid, $mail, $firstname, $lastname, $arrSelectedLdapMemberGroups)
 {
     $arrMemberGroups = deserialize($objMember->groups, true);
     $objLocalLdapMemberGroups = \MemberGroupModel::findBy(array('(tl_member_group.ldapGid > 0)'), null, array());
     $arrLdapMemberGroups = LdapMemberModel::getLdapMemberGroupsByUid($uid);
     if ($objLocalLdapMemberGroups !== null) {
         $arrLocalLdapMemberGroups = $objLocalLdapMemberGroups->fetchEach('ldapGid');
         $objMember->ldapUid = $uid;
         $objMember->email = $mail;
         $objMember->firstname = $firstname;
         $objMember->lastname = $lastname;
         $objMember->username = $GLOBALS['TL_CONFIG']['ldap_uid'] == 'mail' ? $objMember->email : $objMember->ldapUid;
         // merge non ldap contao groups with assigned (and active!) remote ldap groups
         $objMember->groups = serialize(array_merge(array_diff($arrMemberGroups, array_keys($arrLocalLdapMemberGroups)), LdapMemberGroupModel::getLocalMemberGroupIds(array_intersect($arrLdapMemberGroups, $arrSelectedLdapMemberGroups))));
         if (isset($GLOBALS['TL_HOOKS']['ldapUpdateMember']) && is_array($GLOBALS['TL_HOOKS']['ldapUpdateMember'])) {
             foreach ($GLOBALS['TL_HOOKS']['ldapUpdateMember'] as $callback) {
                 $objMember = call_user_func(array($callback[0], $callback[1]), $objMember);
             }
         }
         $objMember->save();
     }
 }