1
solo71
Groups code issue...
  • 2005/6/18 1:38

  • solo71

  • Module Developer

  • Posts: 941

  • Since: 2003/1/29


Hello,

I am facing the following problem.

1) In the xoops_version.php I have added the follwing code to get all the existing group in my module preferences :

global $xoopsDB$xoopsUser$xoopsModule$xoopsModuleConfig;

    
$member_handler =& xoops_gethandler('member');
    
$xoopsgroups = &$member_handler->getGroupList();  
    foreach (
$xoopsgroups as $key=>$group) {  
    
$groups[$group] = $key;  
    }

$modversion['config'][4]['name'] = 'groups';
$modversion['config'][4]['title'] = '_MI_MYHOME_GROUPS';
$modversion['config'][4]['description'] = '_MI_MYHOME_GROUPS_DSC';
$modversion['config'][4]['formtype'] = 'select_multi';
$modversion['config'][4]['valuetype'] = 'array';
$modversion['config'][4]['options'] = $groups;
$modversion['config'][4]['default'] = $groups;


2) Then I try to get those value in my main index.php page as following:
$group is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);

    
$groups explode(" "$xoopsModuleConfig["groups"]);
    if (
count(array_intersect($group,$groups)) > 0)
    {
         
My code;
        }


Unfortunatly, all I get as a result is a poor :
Notice [PHP]: Array to string conversion in file modules/myhome/index.php line 21

How can I convert the xoops_version.php to be used by the index.php code?


2
solo71
Re: Groups code issue...
  • 2005/6/18 7:35

  • solo71

  • Module Developer

  • Posts: 941

  • Since: 2003/1/29


*bump*

3
Mithrandir
Re: Groups code issue...

Please use a group_multi in xoops_version.php instead of adding queries to every page load where the main menu is visible with your module listed (since xoops_version.php is read there)

The value of a select_multi (and a group_multi) is already an array, so you don't need to explode() anything.

4
solo71
Re: Groups code issue...
  • 2005/6/18 10:00

  • solo71

  • Module Developer

  • Posts: 941

  • Since: 2003/1/29


Thanks for you help Mithy.

I fully understant the concern regarding the "queries to every page load" but...

For some reaason, when I use the 'group_multi' it only display 2 of the 3 groups : Webmaster and Registered used, but never ever the anonymous group (which in my case is exactly what I'm looking for).

That's why I'm using the 'select_multi' code, which used to select each and every existing groups.

Unfortunately, while the 'group_multi' works nicely for my module, the 'select_multi' doesn't. I can be wrong, but I think one them display its array as text, while the other is displaying it as groupid (number).

Unless, I'm not using the right code for the right operation, I'm a little bit stuck here.

If you want to have a look @ myHome test.



PS : remember I'm not a coder.

5
Mithrandir
Re: Groups code issue...

ok, I'll add "group_multi_anon" in XOOPS 2.2

Select_multi and group_multi works exactly the same - just with different options. And the error you get is because you are trying to explode an array when you can only explode strings.

Quote:
I'm not a coder

Yes you are. You code, therefore you are a coder. Whether you like it or not.

6
solo71
Re: Groups code issue...
  • 2005/6/18 11:34

  • solo71

  • Module Developer

  • Posts: 941

  • Since: 2003/1/29


Quote:

Mithrandir wrote:
ok, I'll add "group_multi_anon" in XOOPS 2.2


Is'nt better to add this directly to the "group_multi" function, along with the 2 other standard groups?



Quote:

Mithrandir wrote:
And the error you get is because you are trying to explode an array when you can only explode strings.


Exactly, you were right again. Re-checking the code I noticed a line I didn't quote correctly, which caused the error. Cheers and thanks.

Quote:

Mithrandir wrote:
Yes you are. You code, therefore you are a coder. Whether you like it or not.


He he, let say I'm an amator...

Oh, and my profile displays "Just can't stay away" anyway.


7
Mithrandir
Re: Groups code issue...

Quote:
Is'nt better to add this directly to the "group_multi" function, along with the 2 other standard groups?

When I give you flexibility, you want simplicity - when I make things simple, you want them to be more flexible (not you personally... you as in..."the world")

The eternal dilemma

I'll take a look at how and where this group_multi is used and whether it makes sense to have anonymous there. Sometimes it doesn't (select groups that have access when site is closed... no need for anonymous... but does it matter or harm? That's what I will figure out)

Quote:
let's say I'm an amatoeur

(sorry for spell-check, couldn't help myself )

We all started out like that. What separates the gold from the glitter is whether you want to change that and become capable of figuring these things out yourself - or whether you are happy with relying on other people

We all can use a nudge now and then, and a coder can always learn new stuff by being told or experimenting, so you may not be a perfect coder, but at least you can improve continously - but playing the "I'm not a coder"-card is giving up.

(trying to cheer up and motivate - not bringing you down. I hope this is also the way it is perceived)

8
solo71
Re: Groups code issue...
  • 2005/6/18 12:14

  • solo71

  • Module Developer

  • Posts: 941

  • Since: 2003/1/29


Quote:

Mithrandir wrote:

I'll take a look at how and where this group_multi is used and whether it makes sense to have anonymous there. Sometimes it doesn't (select groups that have access when site is closed... no need for anonymous... but does it matter or harm? That's what I will figure out)

To be honest, this is not the first time I'm facing this code problem, nore does Marcan, as he told me... Maybe you could ask him what he thinks about it.



Quote:

Mithrandir wrote:

(trying to cheer up and motivate - not bringing you down. I hope this is also the way it is perceived)


That's the way I understood it. Well, you perfectly knew it was false modesty, as everyone here knows I'm the best module dev all around here.

Beware Mithy, next yeat will be mine! (Just need to get ride of Marcan, Hervé, Catz and some similars...)



PS: thanks for your help.

9
Catzwolf
Re: Groups code issue...
  • 2005/6/18 12:49

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


Hey Solo,

First, your erm...first part you are trying to be a little bit to techincal there and no need for the foreach there. Try this:

$member_handler = &xoops_gethandler'member' );
$group_list = &$member_handler -> getGroupList();
$group_list array_flip$group_list );


This will do exactly the same as you are trying above.

For the second part, again you are trying to over state the issue where something like this would be good enough.

$groups $xoopsUser->getGroups();
if ( 
array_intersect$xoopsModuleConfig['groups'], $groups ) )
{
        
$has_access true;
}


Hope that helps in some way =)

ATB

John

10
solo71
Re: Groups code issue...
  • 2005/6/19 21:53

  • solo71

  • Module Developer

  • Posts: 941

  • Since: 2003/1/29


Thanks a lot John!

So here are the results of your very pertinent suggestions...

1)
$member_handler = &xoops_gethandler'member' );
$group_list = &$member_handler -> getGroupList();
$group_list array_flip$group_list );


Perfect! That work very well...


2)
$groups $xoopsUser->getGroups();
if ( 
array_intersect$xoopsModuleConfig['groups'], $groups ) )
{
        
$has_access true;
}


Almost! This code doesn't take in account the anonymous group, and leads to an error as it is...

Thus, I converted it like:

$groups is_object($xoopsUser) ? $xoopsUser->getGroups() : array(XOOPS_GROUP_ANONYMOUS);
    if ( 
array_intersect$xoopsModuleConfig['groups'], $groups ) )
    {

        
$has_access true;
}


So far, it seems to work...


Login

Who's Online

131 user(s) are online (70 user(s) are browsing Support Forums)


Members: 0


Guests: 131


more...

Donat-O-Meter

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

Latest GitHub Commits