Page 1 of 1

Visible objects for different group of users

Posted: Wed Feb 15, 2012 9:13 pm
by DonKihott
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.

Re: Visible objects for different group of users

Posted: Thu Feb 16, 2012 1:28 am
by wwhite
Author group = 3
check with phpmyadmin for the table user_groups

Re: Visible objects for different group of users

Posted: Tue Feb 21, 2012 12:31 am
by mtrivino
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.