Jump to content

Group form setting request


TheJackal84

Recommended Posts

Posted

I noticed with the group form settings there are ways to not show the admin and guests groups from being selected, So say I do a form setting with guests disabled from being picked and they can only pick user groups, the statement would have to be

{{ if \IPS\Settings::i()->My_Setting == 'all' AND \IPS\Member::loggedIn()->member_id OR \IPS\Member::loggedIn()->inGroup( explode(',', \IPS\Settings::i()->My_Setting AND \IPS\Member::loggedIn()->member_id ) ) }}

is there not a way for the setting to know that guests are already excluded from viewing / using and we can just use the statement as the setting already knows groups are excluded as they can't be picked

{{ if \IPS\Settings::i()->My_Setting == 'all' OR \IPS\Member::loggedIn()->inGroup( explode(',', \IPS\Settings::i()->My_Setting ) ) }}

Because it seems silly to exclude the guest group from being picked then have to put another statement in disabling them from using it anyway

Posted

I don't understand the question.

Firstly, your first if statement wouldn't work correctly (you are exploding on a boolean technically because you have an AND'd statement there, and you are mixing AND and OR in the if statement without parenthesis), but setting that aside, if you do not permit the guest group to be used then an inGroup() check would be fine. Unless you are excluding the guest group from being included and "all" is represented as a *...in which case you would indeed need to check if the member_id is set.

Posted
4 minutes ago, bfarber said:

I don't understand the question.

Firstly, your first if statement wouldn't work correctly (you are exploding on a boolean technically because you have an AND'd statement there, and you are mixing AND and OR in the if statement without parenthesis), but setting that aside, if you do not permit the guest group to be used then an inGroup() check would be fine. Unless you are excluding the guest group from being included and "all" is represented as a *...in which case you would indeed need to check if the member_id is set.

The first would work, I have used it in lots of tests

Basically the setting would be

$form->add( new \IPS\Helpers\Form\Select( 'my_Setting', ( \IPS\Settings::i()->my_Setting == 'all' ) ? 'all' : explode( ',', \IPS\Settings::i()->my_Setting ), TRUE, array( 'options' => \IPS\Member\Group::groups(TRUE, FALSE), 'parse' => 'normal', 'multiple' => true, 'unlimited' => 'all', 'unlimitedLang' => 'all_groups' ), NULL, NULL, NULL, 'my_Setting' ) );

the

'options' => \IPS\Member\Group::groups(TRUE, FALSE)

is hiding guests from being selected

so if the user selected all it will now pass through if you used the code

if ( \IPS\Settings::i()->my_Setting == 'all' OR \IPS\Member::loggedIn()->inGroup( explode(',', \IPS\Settings::i()->my_Setting ) ) )

and also allow guests to use it as its set to all, should the setting not know that the guests are already excluded?, the only way is to add a

if ( \IPS\Member::loggedIn()->member_id )

in there so it will not work for guests, or like my first one

if ( \IPS\Settings::i()->my_Setting == 'all' AND \IPS\Member::loggedIn()->member_id OR \IPS\Member::loggedIn()->inGroup( explode(',', \IPS\Settings::i()->my_Setting AND \IPS\Member::loggedIn()->member_id ) ) )

 

Posted
Just now, TheJackal84 said:

The first would work, I have used it in lots of tests

Was it just pseudo-code? Because I can't see how this could ever work as expected:

explode(',', \IPS\Settings::i()->My_Setting AND \IPS\Member::loggedIn()->member_id )
Just now, TheJackal84 said:

Basically the setting would be


$form->add( new \IPS\Helpers\Form\Select( 'my_Setting', ( \IPS\Settings::i()->my_Setting == 'all' ) ? 'all' : explode( ',', \IPS\Settings::i()->my_Setting ), TRUE, array( 'options' => \IPS\Member\Group::groups(TRUE, FALSE), 'parse' => 'normal', 'multiple' => true, 'unlimited' => 'all', 'unlimitedLang' => 'all_groups' ), NULL, NULL, NULL, 'my_Setting' ) );

the


'options' => \IPS\Member\Group::groups(TRUE, FALSE)

is hiding guests from being selected

so if the user selected all it will now pass through if you used the code


if ( \IPS\Settings::i()->my_Setting == 'all' OR \IPS\Member::loggedIn()->inGroup( explode(',', \IPS\Settings::i()->my_Setting ) ) )

and also allow guests to use it as its set to all, should the setting not know that the guests are already excluded?, the only way is to add a


if ( \IPS\Member::loggedIn()->member_id )

in there so it will not work for guests, or like my first one


if ( \IPS\Settings::i()->my_Setting == 'all' AND \IPS\Member::loggedIn()->member_id OR \IPS\Member::loggedIn()->inGroup( explode(',', \IPS\Settings::i()->my_Setting AND \IPS\Member::loggedIn()->member_id ) ) )

 

There is no way for the software to know that "*" means all (*except guests). You would need to explicitly block guests if you don't want them to have access, and are blocking them in your settings form from being selectable. We do this in places as well.

Posted
8 minutes ago, bfarber said:

Was it just pseudo-code? Because I can't see how this could ever work as expected:


explode(',', \IPS\Settings::i()->My_Setting AND \IPS\Member::loggedIn()->member_id )

Sorry that was a typo

it was meant to be

if ( \IPS\Settings::i()->My_Setting == 'all' AND \IPS\Member::loggedIn()->member_id or \IPS\Member::loggedIn()->inGroup( explode(',', \IPS\Settings::i()->My_Setting )) AND \IPS\Member::loggedIn()->member_id )
8 minutes ago, bfarber said:

There is no way for the software to know that "*" means all (*except guests). You would need to explicitly block guests if you don't want them to have access, and are blocking them in your settings form from being selectable. We do this in places as well.

OK thanks, It's probably just me but I always forget to add the \IPS\Member::loggedIn()->member_id bit as the guests can't be selected, Will just need to wake up more lol :)

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...