SIMPLE Random Member Selector
Need a SIMPLE generator which will randomly generate the name of a user who is in a specified usergroup.

A VERY SIMPLE menu or page in the Admin Control Panel where there could be a "generate" button, resulting in a random user from the specified group being selected/displayed. IF POSSIBLE, also create a log entry every time a name is generated listing which username was generated.

I did some investigation already and found this (here on mybb but the original poster didn't elaborate how to use this), which apparently works. I would LOVE this to be put into a very simple plugin for use.

The plugin would require settings where you can change the usergroups to include and the minPosts #.

//pick a random user from the group
$usergroupIn = '8';
$minPosts = '0';
$query = $db->query("SELECT * FROM ".TABLE_PREFIX."users WHERE usergroup = '$usergroupIn' AND postnum >=$minPosts  ORDER BY rand() LIMIT 1");
$user = $db->fetch_array($query);
$username = build_profile_link($user['username'], $user['uid']); 

-- on my forum we need to randomly select members who are included in our 'active' or 'leaders' group, so they can participate in random events on the site. It's just easier to have a generator on board than using an off-site generator and hoping that the number/name generated is an active user, etc.
Ask and you shall receive Smile

Ok so how this works.

1 - Unzip and upload randomuser.php to /inc/plugins
2 - Install and activate (it doesn't perform any actions on this, and if you want to remove it you should uninstall then delete)
3 - Go to Admin >> Users & Groups >> Random User (menu item on left)
4 - Choose the Group you want to search in
5 - Hit Generate

This will generate a username and a link to their profile (Frontend)

Nothing Spectacular but does what you asked, also there are no simple plugins, they all take a bit of work. That took me about 1.5 hours to do complete but I was distracted whilst doing it Smile

I snuck in a donation link at the bottom, because I a both cheeky and optimistic haha.

Let me know if you need it altered to do anything else, like link to the admin profile instead, I can possible make it select from several groups at once, but probably not required.

**Note random generation in mysql is not really truly random, I have added a further element that makes it much more random by changing the random operator to RAND(UNIX_TIMESTAMP()).

RAND slows queries a little and if you find that you are not getting really random results we can alter the code to do the random selection in PHP instead. Either way if you have large groups or lots of groups this could potentially be a little slow but it should be fine.

The only truly dodgy part is in the query

Select uid, username from ".TABLE_PREFIX."users where usergroup=".$search_usergroup." OR ".$search_usergroup." IN (additionalgroups) ORDER BY RAND(UNIX_TIMESTAMP()) LIMIT 1"

Now this is simply grabbing any member from one of those groups and the additional groups could probably be better done within PHP because there are limitations on IN queries, if you have 1000 additional groups for a user this could fail.

It does not check post counts or anything like that, but I can add that.

It also does not yet add a log entry but I could add that later to the admin logs or something if you like.

Ok I just updated it so that it now adds an Admin Log entry under ACP >> Tools & Maintenance >> Administrator Logs

This will tell you whenever it has been run, the date and time it was run, who ran it and the user that was randomly selected

Attached Files
.zip (Size: 3.12 KB / Downloads: 125)
Quote:I can possible make it select from several groups at once

Actually, this would be wonderful. Currently we have members who are separated into separate groups based on what priviledges they get on the board, but I don't want to exclude any of them from events. (We have Members, Leaders, and Premium) ... I could just set my premium/leaders to have the additional usergroup of member that way searching for member would automatically include all of them.

This looks great! Thank you so incredibly much. I'm asking a few members for some donations so we can send some your way. Smile Thanks again!

I know plugins aren't easy, so I do appreciate the time and effort you spent. I think when I said simple I meant "nothing fancy" more than "easy". I tried editing a plugin I already had to do the same function without creating an area in the admin panel (and it wouldn't create any logs) but failed after fiddling around for 2 hours+ (but I'm a coding noob...).

It will currently search both additional and primary group so if all users have the additional group of say "lucky prize group" then you search based on that then you are good to go and it will log a note in the admin logs also.

I will make an alternate version later which allows you to select multiple groups with a multi-select box and upload it so you can choose that may be a bit more complex though query wise

Forum Jump:

Users browsing this thread: 1 Guest(s)