1
simonvl
Xoopsmembers search by group and rank (HACK)
  • 2004/4/16 0:17

  • simonvl

  • Just popping in

  • Posts: 44

  • Since: 2004/1/28


I am developing a hack to allow xoopsmembers to be searched by group and rank.

I am posting this unfinished hack here in case other people better at php want to help me to develop this.

Current problems to solve:
---------------------------
1) the array within the array: user groups within the userdata array- how can I access these for both matching in the search, and for displaying in the smarty template?
2) XoopsFormSelectGroup- how to use?
(see below for where I want to use these)

So far I have got the searchresults section of index.php to be able to access this information, as follows:
section to get groups
(added just after
$start = (!empty($HTTP_POST_VARS['start'])) ? intval($HTTP_POST_VARS['start']) : 0;
$member_handler =& xoops_gethandler('member');
$total = $member_handler->getUserCount($criteria);
//----------------------hack show groups by samuels- edited by simonvl------------------------
        
function GetGroupsNames ($uid)
        {
            
$member_handler =& xoops_gethandler('member');
            
$User= new XoopsUser($uid);
            
$user_groups=$User->getGroups();
            
$count count($user_groups);
    
//$groups =& $member_handler->getGroups();
            
for ($i=0;$i<$count;$i++)
            {
                
$thisgroup =& $member_handler->getGroup($user_groups[$i]);
                
$g[$i]=$thisgroup->getVar('name');
            }
            return (
$g);

        }

This gets the groups each user found by the search is subscribed to and pust them in the array $g, where $g['0'] is the first group the user was assigned, etc.

The next bit puts this info into the $userdata array which xoopsmembers uses to store info and put it into a smarty variable as an array.
Added after
$userdata['id'] = $foundusers[$j]->getVar("uid");
$userdata['groups'] = GetGroupsNames($userdata['id']);
            
$usergroupinfo $userdata['groups'];
            echo 
$usergroupinfo['0']; //just for testing
// this bit thanks to Mithrandir:
            
$rank $foundusers[$j]->rank();
            
$userdata['rank'] = $rank['title'];
            
$rankinfo $userdata['rank'];
            echo 
$rankinfo//just for testing

At the moment, this successfully echos the rank information of each user, but of course returns "array" for the group.

using this for the search form
I can add a standard text matching search field for user ranks, or a selection box, or a hidden field that only lets visitors see certain ranked users- this I might use for a custom implementation of ranks on my site as a classification system.

Now, I want to select groups and put their name into the search form, to find members in that group. Should I use
XoopsFormSelectGroup($caption, $name, $include_anon=false, $value=null, $size=1, $multiple=false) (and if so, how!)
or should I use a normal xoopsformselect element and name the groups (making the implementation less flexible)?

Also, how do you get it to try to match the entry to all of the values in the array $g?

Ultimately, I would like members to be able to search all members, but anonymous visitors to be only allowed to search (and view) special members, moderators and admins- these are the society committee members at chillout.org.uk

Anyone want to help out here?
Thanks in advance
Simon

2
samuels
Re: Xoopsmembers search by group and rank (HACK)
  • 2004/4/16 8:02

  • samuels

  • Quite a regular

  • Posts: 249

  • Since: 2003/10/30


I don't know if it's usefull for you but I've made this hack to add a new search option. You can select one or more groups, and you will see only the users of these groups.
I have not tested it yet, perhaps runs or perhaps not

At xoopsmembers.php, after line 27:

function SearchByGroups($grps,$uid)
{
    
$User= new XoopsUser($uid);
    
$groupid $User->getGroups();
    for (
$i=0$i<count($groupid); $i++) 
    {
        if (@
in_array($groupid[$i], $grps))
        {
            return 
true;
        }
    }
}


With this little function you know if certain user is in one or more groups

Now, before the submit button
$form->addElement($submit_button);


Add a formselectgroup
$form->addElement( new XoopsFormSelectGroup (_MD_GROUPACCESS'groupid',false,array(1,2),3,true));


Documentation of this is HERE

First value: Description Text.
Second value: Name (must be unique in the form)
Third value: Do you want to show anonymous group?
4º value: Preselected values.
5º value: Number of lines to show.
6º value: Do you want to select more than one value?


Now we need to capture the form values.
After
$limit = (!empty($HTTP_POST_VARS['limit'])) ? intval($HTTP_POST_VARS['limit']) : 20;
    if ( 
$limit == || $limit 50 ) {
        
$limit 50;
    }


Add this
$groupid = ($HTTP_POST_VARS["groupid"]);


And now it's the time to use the function. I don't know how to use CriteriaCompo objects. This is and easy way to do that.

Look for line:
foreach (array_keys($foundusers) as $j) {


And add after:
if (SearchByGroups($groupid,$foundusers[$j]->getVar("uid")))
        {


And before line:
$totalpages ceil($total $limit);


Add:
}


I hope this code can help you a little.

3
simonvl
Re: Xoopsmembers search by group and rank (HACK)
  • 2004/4/18 0:18

  • simonvl

  • Just popping in

  • Posts: 44

  • Since: 2004/1/28


That's absolutely fantastic!! It worked first time!
Thanks so much, its very kind of you to help me.

For anyone interested, I have implemented this "search for users by group" hack- you can view the result at http://www.chillout.org.uk/modules/xoopsmembers/exampleindex.php
(for a limited time only) and you can see the code used in my wfsnippets section.
Enjoy.
(more hacks to this module will hopefully follow in this thread)
Simon

4
simonvl
Re: Xoopsmembers search by group and rank (HACK)
  • 2004/4/18 2:28

  • simonvl

  • Just popping in

  • Posts: 44

  • Since: 2004/1/28


As I promised, here is a further extension of the hack.

I would like to be able view the members without having to go through the search form (by putting [$op = "submit";] at the top of the form). Additionally, I would like to be able to have all groups shown if the visitor is logged on ($xoopsUser), but only certain groups if it is an anonymous visitor.
I used this code around line 215 (of the hacked version available from my website):
//hack 3
    
if ( !empty($HTTP_POST_VARS['groupid']) && $xoopsUser ) {
        
$groupid = ($HTTP_POST_VARS["groupid"]);
    }
    elseif ( 
$xoopsUser ) {
        
$groupid = array(1,2,4,7);
    }
    else {
        
$groupid = array(1,7);
    } 
    
// end hack 3

5
cauchy
Re: Xoopsmembers search by group and rank (HACK)
  • 2004/4/18 5:23

  • cauchy

  • Just popping in

  • Posts: 4

  • Since: 2004/4/7 1


I have some problem with the navigation bar at the bottom of the page.
This hack doesn't work for me.

6
simonvl
Re: Xoopsmembers search by group and rank (HACK)
  • 2004/4/19 13:54

  • simonvl

  • Just popping in

  • Posts: 44

  • Since: 2004/1/28


It sounds like a slight error in the code. Check it through. If that fails, turn on PHP debug in admin/general and post the details of your debug info. Someone here may be able to help.
Simon

Login

Who's Online

370 user(s) are online (258 user(s) are browsing Support Forums)


Members: 0


Guests: 370


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits