Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Showing a module once to a specific...
Showing a module once to a specific user level/type
Showing a module once to a specific user level/type
Hi,
I'm using the below code I found here on the forum to display a "One-Time Offer" for new members to my site. My interest is to be able to control who sees the offer based on their access level/type. Our membership is set up where you're a "Junior, Senior, Executive or Senior Executive" and I don't want an Executive to see the same offer as a Junior.
That being said, how can I modify the below code to control this? Thanks!!
Also, if I want to show offer 1 to Junior and offer 2 to Senior, do I have to run 2 metamod modules or do I just add the code to the same metamod module?
$c = JRequest::getInt('SeenIt', 0, 'cookie');
if ($c) return; /* if cookie was set, don't show anything, else... */
setcookie( 'SeenIt', 1, time()+60*60*24*365*10, '/' );
return 77; /* return module 101, but only the first time */
Re: Showing a module once to a specific user level/type
Hi ocloren,
(1) if you want to show different numbers of modules to different groups, but in the same module position, you can do it all in one MetaMod.
(2) Which ACL system are you using for the membership levels? It must be a 3rd-party component, since by default Joomla doesn't allow customisation/addition of user levels.
(3) I think that most of the ACL systems add the new user groups to Joomla's master list. This means that the $user object in Joomla contains the new group(s) by name. e.g. in your rule you can refer to $user->usertype to find the group name for the currently logged-in user.
Assuming that #3 is true in your case, you can base the rule around this:
$c = JRequest::getInt('SeenIt', 0, 'cookie');
if ($c) return; /* if cookie was set, don't show anything, else... */
setcookie( 'SeenIt', 1, time()+60*60*24*365*10, '/' );
// now we get to the part where we display a module, because
// it's the first time that this logged-in user has ever seen a page
// with this module on it.
if ($user->usertype == 'Junior') return 77;
if ($user->usertype == 'Senior') return "77,78";
if ($user->usertype == 'Executive') return 79;
if ($user->usertype == 'Senior Executive') return 80;
// if they are in any other group, they see nothing.
Please note: this will only work if your ACL component puts the custom group name into $user->usertype. You can test out what info is available in $user by creating a new MetaMod, and using the following PHP:
echo "<pre>";
print_r($user);
echo "</pre>";
Then, log in as one of the users in one of the groups, and see if the group name shows up in the output of the MetaMod. If you see that usertype is set to that group name, then you can use the recipe above. If there's a different variable name then you should be able to adjust the recipe. If the group name is not there at all, write back with some more info about what system you're using, and I'll try to find another way of getting the group info.
Best regards,
Stephen
- Index
- » MetaMod
- » MetaMod General Support
- » Showing a module once to a specific...
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5944
- Total Posts Today:
- 1
- User Info:
- Total Users:
- 7645
- Newest User:
- foocd90
- Members Online:
- 0
- Guests Online:
- 165
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked