Filtering groups in the members page

Permalink
Hi,

Once you have your members listed in the members page, how do you filter them by group ala Users and Groups or the concrete5.org website.

Is there some kind of search facility checkbox arrangement type thing that will do the filtering and sorting?

Nige

nige
 
codingpenguins replied on at Permalink Reply
If your a coder this should be easy. just add a combobox that displays a list of all the groups in \concrete5\single_pages\members.php. If you want the code for this let me know. Just pass the $groupID on get and "" if the user does not select anything.


For the \concrete5\controllers\members.php file you should just add

if ($groupID!= "") {
   $userList->filterByGroup($groupID)
}


right below the first "if" statement.

Not sure if this is what you were asking for...
nige replied on at Permalink Reply
nige
Hi and thanks for your reply.

This is what I am after and thanks a lot.

Unfortunately Im not a coder but I can follow instructions and this looks to be possible for me.

I just want to be able to filter out the members according to their group designation.

If you do have the code I would appreciate that if it is a bit tricky. Also exactly where to stick it.

Also you mention stick in a combo box. Where do I get an instant combo box, is there an addon?

Nige
codingpenguins replied on at Permalink Best Answer Reply
This is the code I would use - did not test but im pretty sure it will work.

in the /concrete5/single_pages/members.php After the line
<input name="keywords" type="text" value="<?php echo $keywords?>" size="20" />

add the code below following this line
<?php
$db = Loader::db();
$query = "SELECT gID, gName FROM Groups";
$result = $db->Execute($query);
?>
<select name="group">
   <option value=""></option>
<?php
while($row=$result->fetchRow()) {
   $gID = $row['gID'];
   $gName = $row['gName'];
   ?><option value="<?php echo $gID?>"><?php echo $gName?></option><?php
}
?>
</select>


Then in /concrete5/controllers/members.php Repace this block
$keywords = $this->get('keywords');
if ($keywords != '') {
   $userList->filterByKeywords($keywords);
}

With
$keywords = $this->get('keywords');
$groupID = $this->get('group');
if ($keywords != '') {
   $userList->filterByKeywords($keywords);
}
if ($groupID != '') {
    $userList->filterByGroup($groupID);
}


Let me know if you have any more questions, or if you can not get it to work I will test for myself.
nige replied on at Permalink Reply
nige
Hey thanks a lot that's excellent help.

Nige
rosie607 replied on at Permalink Reply
rosie607
Hi there

I tried to do this as well but I get the following message if I select any option from the drop down.

Fatal error: Call to a member function getGroupID() on a non-object in /Users/Rosie/Sites/mysite.com/concrete5.6.1.2/concrete/core/models/user_list.php on line 46

D you have any ideas why this is coming up?
Thanks in advance
rubencouto replied on at Permalink Reply
rubencouto
Hello!

When I try to do this, I also get this message:

Fatal error: Call to a member function getGroupID() on a non-object in /home2/conceptu/public_html/iebpv/models/user_list.php on line 51


Any ideas?
rubencouto replied on at Permalink Reply
rubencouto
Hello!

Made a slight correction to the code for the members page and it's working fine:

<?php
$db = Loader::db();
$query = "SELECT gID, gName FROM Groups";
$result = $db->Execute($query);
?>
<select name="group">
   <option value=""></option>
<?php
while($row=$result->fetchRow()) {
   $gID = $row['gID'];
   $gName = $row['gName'];
   ?><option value="<?php echo $gName?>"><?php echo $gName?></option><?php
}
?>
</select>
madmichael replied on at Permalink Reply
madmichael
Slight error in the code it should be filter by the group name, not the group ID

$userList->filterByGroup('Group Name');