Exclude Admin from showing in Members list

Permalink 1 user found helpful
A few people have posted this before but there were no responses. I have a members list on our website but the admin accounts are showing. I would like to exclude those members from the list. Has anyone been able to figure out how to do this? Whether it be by excluding certain members or by excluding an entire group. I've been messing around with if statements in the members.php file but I have not been very successful. BTW, I'm a PHP newbie which might have something to do with it. Any help would be greatly appreciated. Thank you!

ckwill90
 
chemmett replied on at Permalink Best Answer Reply
chemmett
Easiest/cleanest way is to override the controller file. This is assuming you're running 5.6.0.2.

1. Copy /concrete/controllers/members.php to /controllers/members.php

2. Edit /controllers/members.php (mostly empty) and add this code inside the class:
public function view() {
   $userList = new UserList(); 
   $userList->sortBy('uName', 'asc'); 
   $keywords = $this->get('keywords');
   if ($keywords != '') {
      $userList->filterByKeywords($keywords);
   }
   $userList->filterByGroup('Administrators',false);
   $users = $userList->getPage();
   $this->set('userList', $userList);                  
   $this->set('users', $users);
   $this->set('attribs', UserAttributeKey::getMemberListList());
   $this->set('keywords', htmlentities($keywords, ENT_COMPAT, APP_CHARSET));
   $this->addHeaderItem(Loader::helper('html')->css('ccm.profile.css'));
}


This is mostly copying the existing view() function in the Concrete5_Controller_Members class, but adding the "filterByGroup" clause that will make it only return users that are NOT in the "Administrators" group. Hope that helps!
ckwill90 replied on at Permalink Reply
ckwill90
Thank you so much for the quick reply! It did the trick. One thing I ran into is if a user is a part of a different group, say "staff", they are suppressed as well. The only users who show are those that do not belong to a group. Any idea why that is? Is there something I need to add to show the other groups?

Again, thank you so much for your help. I really appreciate it! :)
jwidavid replied on at Permalink Reply
I'd like to add that this is still an issue. I was under the impression that

$userList->filterByGroup('Administrators',false);

would return all users who were not in the group "Administrators". But all it does is result in a list of users who aren't in any group at all.


EDIT:
I did come up with a solution for this problem. Forgive me if this is not the "proper" way.

If you want:
$userList->filterByGroup('Administrators',false);

to return a list of all users who are not in the group "Administrators" then you can use the code below. Replace the filterByGroup function with this code in the user_list.php file.

public function filterByGroup($groupName='', $inGroup = true){ 
    $group=Group::getByName($groupName); 
    $tbl='ug_'.$group->getGroupID();
    $this->addToQuery("left join UserGroups $tbl on {$tbl}.uID = u.uID ");    
    if ($inGroup) {
        $this->filter(false, "{$tbl}.gID=".intval($group->getGroupID()) );
    } else {
        $this->filter(false, "{$tbl}.gID!=".$group->getGroupID()." UNION SELECT DISTINCT u.uID, u.uName 
        FROM Users u left join UserGroups $tbl ON u.uID={$tbl}.uID WHERE {$tbl}.gID is null");
    }
}


For my purposes, I created a new user_list.php and placed it in the /models directory so as to not overwright the core file. I also had to change the class name from "Concrete5_Model_UserList" to "UserList".

Again, forgive me if something I did was "incorrect". What I DO know is that I searched the forums for a solution to this problem and could not find one so I made my own.
afixia replied on at Permalink Reply
afixia
I'm not the best at SQL either, but why not this?
$this->filter(false, "{$tbl}.gID != ".intval($group->getGroupID()) );


So now
public function filterByGroup($groupName='', $inGroup = true){ 
      $group=Group::getByName($groupName); 
      $tbl='ug_'.$group->getGroupID();
      $this->addToQuery("left join UserGroups $tbl on {$tbl}.uID = u.uID ");    
      if ($inGroup) {
         $this->filter(false, "{$tbl}.gID=".intval($group->getGroupID()) );
      } else {
         //$this->filter(false, "{$tbl}.gID is null"); ORIGINAL CODE
         //$this->filter(false, "{$tbl}.gID!=".$group->getGroupID()." UNION SELECT DISTINCT u.uID, u.uName FROM Users u left join UserGroups $tbl ON u.uID={$tbl}.uID WHERE {$tbl}.gID is null"); YOUR SUGGESTED CHANGE
         $this->filter(false, "{$tbl}.gID != ".intval($group->getGroupID()) ); //MY CODE
      }
   }