Visible objects for different group of users

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
DonKihott
Joomla! Fledgling
Joomla! Fledgling
Posts: 1
Joined: Wed Feb 15, 2012 6:25 pm

Visible objects for different group of users

Post by DonKihott » Wed Feb 15, 2012 9:13 pm

I am going to make visible some objects (div,table) in my index.php file only for the one group of users, for example authors. I have inserted the following code:

Code: Select all

<?php
$user =& JFactory::getUser();
?>
<?php if($user->get('usertype') == 'Author') : ?>
<div id="user1">
        <jdoc:include type="modules" name="user1" style="xhtml" />
</div>
<?php endif ?>
But it doesn't work. May be it is possible to identify the group by ID, but i am not in touch with php.

User avatar
wwhite
Joomla! Explorer
Joomla! Explorer
Posts: 469
Joined: Wed Jul 30, 2008 4:40 am
Location: SC USA

Re: Visible objects for different group of users

Post by wwhite » Thu Feb 16, 2012 1:28 am

Author group = 3
check with phpmyadmin for the table user_groups
Joomla - K2
Funeral Director - Every Day Above Ground is a Good Day!
Saying - This old world keeps spinning round, it a wonder tall trees aint laying down https://www.[youtube].com/watch?v=c_W9aaQ1Apo

User avatar
mtrivino
Joomla! Apprentice
Joomla! Apprentice
Posts: 32
Joined: Wed Aug 19, 2009 9:47 pm
Location: Bogotá, Colombia
Contact:

Re: Visible objects for different group of users

Post by mtrivino » Tue Feb 21, 2012 12:31 am

Hello,

actually I think you're using a deprecated attribute and you should change it. In Joomla! 1.5 you had only three groups, and users were supposed to belong to a single group, but ever since 1.6 there's a different mapping with user groups and access levels.

The easiest way to do something like that is to check if a user belongs to some specific group, like this:

Code: Select all

if(in_array("8", $user->getAuthorisedGroups())){
// if user belongs to group with id=8, do this...
}
I guess it's not the best way (you should use ACL), but it'll work for you.

Regards.


Locked

Return to “Joomla! 2.5 Coding”