Page 1 of 1

Using DOCman's User Groups info to hide menu items

Posted: Wed Sep 22, 2010 7:36 pm
by Nightslyr
I'm new to both Joomla and DOCman, so please bear with me. I am pretty competent with PHP, however.

I have a couple of DOCman user groups created - community members and partners. In my main site navigation, I have a group of links which lead to files only partners should be able to access. What I'd like to do is hide this dropdown section of the menu from everyone EXCEPT administrators and DOCman partners.

The 'simplest' thing I can think of is to grab a hold of the DOCman User object for the current user, and then test whether or not the user is in the partner group. I'm just not sure if:

A. This is even possible. I'm not sure how walled off extensions are from Joomla itself.
B. How to do it if it is possible.

Any ideas?

Re: Using DOCman's User Groups info to hide menu items

Posted: Thu Sep 23, 2010 4:53 pm
by ooffick
You would probably need to create two menus, one with the menu included and one without the menu. And then use two different modules, one for the normal user and one for the administrators and DOCman partners.

However, that would still allow the normal user to get in, if they would find out the URL.

Olaf

Re: Using DOCman's User Groups info to hide menu items

Posted: Thu Sep 23, 2010 7:20 pm
by Nightslyr
ooffick wrote:You would probably need to create two menus, one with the menu included and one without the menu. And then use two different modules, one for the normal user and one for the administrators and DOCman partners.
Well, the problem is that the menu(s) can't see the DOCman user groups. They also don't adhere to the custom group I made according to the wiki article I posted in another thread. The menu can see the custom group I made, it just can't properly limit access.

Re: Using DOCman's User Groups info to hide menu items

Posted: Fri Sep 24, 2010 10:35 am
by ooffick
if you just want to change the links in the menu, you can use two menus with two different module positions and this code in your template:

You will need to change the name of your group

Code: Select all

<?php 
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$db->setQuery('select groups_members from #__docman_groups where groups_name ="[YOUR DOCMAN GROUP]"');
$temp = $db->loadResult();
$array = explode(',',$temp);
if(in_array("{$user->id}",$array)): ?>
<jdoc:include type="modules" name="menu_withpremission" />
<?php else: ?>
<jdoc:include type="modules" name="menu_withoutpremission" />
<?php endif; ?>
Olaf

Re: Using DOCman's User Groups info to hide menu items

Posted: Fri Sep 24, 2010 6:40 pm
by Nightslyr
ooffick wrote:if you just want to change the links in the menu, you can use two menus with two different module positions and this code in your template:

You will need to change the name of your group

Code: Select all

<?php 
$user =& JFactory::getUser();
$db =& JFactory::getDBO();
$db->setQuery('select groups_members from #__docman_groups where groups_name ="[YOUR DOCMAN GROUP]"');
$temp = $db->loadResult();
$array = explode(',',$temp);
if(in_array("{$user->id}",$array)): ?>
<jdoc:include type="modules" name="menu_withpremission" />
<?php else: ?>
<jdoc:include type="modules" name="menu_withoutpremission" />
<?php endif; ?>
Olaf
Tried it, but it looks like the normal menu functionality is still trumping my small hack. I can see that the query is working by echoing out whether or not the user id is in the DOCman group, but it still doesn't toggle my menus properly.

EDIT: In particular, it's ignoring my attempts to directly render the menus and is simply doing what the enable/disable and positioning options tell it to do.

Re: Using DOCman's User Groups info to hide menu items

Posted: Fri Sep 24, 2010 7:03 pm
by ooffick
  1. Create a new menu: called menua (Unique Name: menua; Title: menua; Description: menua; Module Title: menua)
  2. Create a new menu: called menub (Unique Name: menub; Title: menub; Description: menub; Module Title: menub)
  3. Add Menu item to the menu "menua": (e.g. Type: External Link > Title: Menu A; Link: http://www.joomla.org)
  4. Add Menu item to the menu "menub": (e.g. Type: External Link > Title: Menu B; Link: http://www.joomla.org)
  5. Go to Extensions Module Manager
  6. Find the module menua
  7. change the module position to menu_withpremission (Tip: you can write into the selection box)
  8. click on save
  9. Find the module menub
  10. change the module position to menu_withoutpremission (Tip: you can write into the selection box)
  11. click on save
  12. use the PHP code and enter it in templates/[YOUR-TEMPLATE]/index.php
  13. save the file
Olaf

Re: Using DOCman's User Groups info to hide menu items

Posted: Fri Sep 24, 2010 7:14 pm
by Nightslyr
ooffick wrote:
  1. Create a new menu: called menua (Unique Name: menua; Title: menua; Description: menua; Module Title: menua)
  2. Create a new menu: called menub (Unique Name: menub; Title: menub; Description: menub; Module Title: menub)
  3. Add Menu item to the menu "menua": (e.g. Type: External Link > Title: Menu A; Link: http://www.joomla.org)
  4. Add Menu item to the menu "menub": (e.g. Type: External Link > Title: Menu B; Link: http://www.joomla.org)
  5. Go to Extensions Module Manager
  6. Find the module menua
  7. change the module position to menu_withpremission (Tip: you can write into the selection box)
  8. click on save
  9. Find the module menub
  10. change the module position to menu_withoutpremission (Tip: you can write into the selection box)
  11. click on save
  12. use the PHP code and enter it in templates/[YOUR-TEMPLATE]/index.php
  13. save the file
Olaf
Awesome! You are the man! :D