Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Show only specific menu to a specific user

Show only specific menu to a specific user

Hi Stephen,

This is probably what Drogos was asking too. I have several menus that I need to assign to specific users. For example, User 1 will only see menu 1 and the main menu. User two will only see menu 2 and the main menu etc. All the other menus need to hide. I have this so far.

if ( MM_NOT_LOGGED_IN ) return 1;
if ( $user->username == "user2" ) return 1,31;
if ( $user->username == "user2" ) return 1,23;
if ( $user->username == "user3" ) return 1,25;
if ( $user->username == "user4" ) return 1,22;
if ( $user->username == "user5" ) return 1,26;

I have all menus enabled since I get an error if I try to call one that is disabled. Should they be set to registered or public? With them set to Public, they all show all the time. With them set to registered, they all show whenever any user is logged in. The rules are working. I get a second instance of the correct menu with the correct user logged in. I just can't get the normal display of the other menus to hide.

I am running the latest joomla and your software. This is the only non-distro module installed.

Thanks for the help.

Jon

jhosford
Beginner Modder
ranks
useravatar
Offline
1 Posts
Administrator has disabled public posting

Re: Show only specific menu to a specific user

Hi Jon,

the syntax is just about right! Just instead of: return 1,31; you need to do:   return "1,31";

Since you are toggling these by the name of the user, they are only for logged in users, therefore you might as well set each of the included modules to "registered" (apart from module "1" which looks like you want it to show for non-logged-in users).

You mention that they are showing up twice. That's because basic MetaMod can't turn off modules that are assigned in the normal Joomla way - it can only decide to include (or not include) modules inside itself. Therefore you have to make the modules NOT show up without MetaMod being involved.

So there are a couple of ways to do this. The simplest way is to go into each of those modules and set them to appear on Menu Assignment: None. That ensures they don't show up by themselves, but MetaMod is quite happy to override that and include them anyway!

The other way, just for completeness, is to set them to a module position that doesn't appear on your page. You can just type in a new module position, like "reserved-for-metamod". The position that they end up in is the position that the MetaMod is in.

This is all outlined in the Quick Start guide.

Hope this helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Show only specific menu to a specific user

Stephen,
I have attempted all that you mentioned above.  I have included the script, based upon the recipe for including users based on time.

if ($user->id > 0) {
  $days = (int)((time() - strtotime( user->registerDate )) / (24*60*60));
  if ($days >= 270) return "53";
  if ($days >= 180) return "52";
  if ($days >= 90) return "31";
  return "51";
}
Each number (31, 51, 52, 53) corresponds to a unique menu with unique content available based upon tenure of subscriber.
At this point, I can't get any of the menus to appear.  It is a paid subscription site, so menus must be registered (altho they don't appear when set to public, either).  I have tried disabling the menus (and then re-enabling them, once that didn't work), entering a unique module position (as you mention above), and set the menu assignments to none.  I am running latest Joomla version, plus your latest metamod version. 

Thank you for the help.

Kirk

capt1234
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: Show only specific menu to a specific user

Hi Kirk,

there was a PHP error in your code. "user" needed a $ in front of it as below. Try that and see if it helps.

if ($user->id > 0) {
  $days = (int)((time() - strtotime( $user->registerDate )) / (24*60*60));
  if ($days >= 270) return "53";
  if ($days >= 180) return "52";
  if ($days >= 90) return "31";
  return "51";
}

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Show only specific menu to a specific user

Stephen,

Thanks for the quick response!  I tried the code correction, but it is still not functioning.  I also tried disabling metamod.  The menus must be in a recognized position to appear on the site with metamod disabled.  Is there a way to test if the metamod module is functioning correctly?  Not sure what else to try.  My forehead is sore from smashing it on the keyboard big_smile

capt1234
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: Show only specific menu to a specific user

Temporarily, try the following code by itself in the PHP box. This will give you some figures to play with, which will show whether we're on the right track:

$days = (int)((time() - strtotime( $user->registerDate )) / (24*60*60));
echo "register days: $days<br>";
echo "user id: " . $user->id . "<br>";

Does that come up with a valid-sounding number of days, and a user id greater than 0?

Also, in general make sure:
- the MetaMod is in the module position that you want the menus to appear in
- the MetaMod is enabled
- the other modules are disabled (it doesn't matter what position they are in)

Hope that helps,
Stephen

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Re: Show only specific menu to a specific user

Yeah!  Got it to appear!  Thank you!  Going to save that code for use later smile.

Now, however, the menu formatting and title disappear.  I'm using the milkyway template with the standard boarders around the main, user menus.  I created the new modules to be menus and got the formatting correct prior to disabling them for metamod.  Is this related to the unique menu position you mentioned in the above post?

Thanks again,

Kirk

capt1234
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: Show only specific menu to a specific user

Nevermind.  Figured it out.  Under style for included modules (multiple divs for rounded courners).  Thank you very much for all your help!

Kirk

capt1234
Beginner Modder
ranks
useravatar
Offline
4 Posts
Administrator has disabled public posting

Re: Show only specific menu to a specific user

Phew, glad it worked at last!

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5913
Dormant:
User Info:
 
Total Users:
10796
Newest User:
mokao3
Members Online:
0
Guests Online:
211

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