I make plugins for my board that require selection of forum ids or usergroups to pull data from and currently I use a text box with a comma separated list of forums/usergroup ids, which is kind of clunky.
It would be really nice if I could have a dropdown list of all the forums/usergroups, like there is in the ACP settings, but I am unsure how to do this.
Any tips?
Well i think the most usefull and functional is to use:
groupselect
and
forumselect
instead text, textarea or watever you want.
Then add the sentence to search with
is_member($mybb->settings['settings_for_groupselect'])
this for usergroups and i use in_array to forumselect.
Well this way is how it works i found it and i use on all my paid plugins so, i think this not have more troubles like the way you add this options.
DarkNeo, thanks for the quick reply, but I don't really understand
Do you have a code snippet I can study?
Note that the build in select boxes also include radio buttons for none and all and always allow multiple selections.
@Lee: simply set "forumselect" or "groupselect" as your settingscode (optionscode column in settings table)
Example:
$setting = array(
'sid' => 'NULL',
'name' => 'usegroups_for_my_plugin',
'title' => 'Usergroups use this plugin ',
'description' => 'Select usergroups who can use my plugin',
'optionscode' => 'text',
'value' => '',
'disporder' => 1,
'gid' => intval( $gid )
);
That code was used as text and the change is on that part:
$setting = array(
'sid' => 'NULL',
'name' => 'usegroups_for_my_plugin',
'title' => 'Usergroups use this plugin ',
'description' => 'Select usergroups who can use my plugin',
'optionscode' => 'groupselect',
'value' => '',
'disporder' => 1,
'gid' => intval( $gid )
);
you can see the change and that's all xD.
When you call to this on your function like:
function my_usergroups{
global $mybb;
if(is_member($mybb->settings['usegroups_for_my_plugin'])){
// return data what you want to set like all data loaded or show contents or any
}
else{
// return another thing otherwise
}
}
And that's easy xD.
Wow, thanks guys, I shall go test it. This option is only available in 1.8.x I think?
Yep, both was added in 1.8.0. Note that is_member doesn't handle all/none correctly (at least not before 1.8.4)
I dont really know that function (
)
Usually, if I am adding a usergroup criteria I use this snip:
//Set the groups allowed to do this
$access = false;
// Get the viewers usergroup and any additional group they are in
$groups = explode(',',$mybb->settings['setting_value']);
// Additional Groups
$additionalgroups = explode(",",$mybb->user['additionalgroups']);
if(in_array($mybb->user['usergroup'], $groups))
{
$access=true;
}
foreach($additionalgroups as $additionalgroup)
{
if(in_array($additionalgroup, $groups))
{
$access=true;
}
}
Its a neat function - I use it a lot. I would like to keep using it, unless is_member does the same thing?
if(is_member($mybb->settings['foo']) || $mybb->settings['foo'] == -1)
{
// user belongs to this group
}
if(my_strpos(','.$mybb->settings['foo'].',', ','.(int)$fid.',') !== false || $mybb->settings['foo'] == -1)
{
// forum belongs to this forum list
}
And yes, is_member does the same. It can even be used for forums but I prefer not to (I already did in some of my plugins though).
is_member will return true for -1 in future version but right now you need the extra check.