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.

Moderators: ooffick, dam-man

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

Visible objects for different group of users

Postby 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.

wwhite
Joomla! Explorer
Joomla! Explorer
Posts: 278
Joined: Wed Jul 30, 2008 4:40 am
Location: SC USA
Contact:

Re: Visible objects for different group of users

Postby wwhite » Thu Feb 16, 2012 1:28 am

Author group = 3
check with phpmyadmin for the table user_groups
Every Day Above Ground is a Good Day!

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

Postby 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.


Return to “Joomla! 2.5 Coding”

Who is online

Users browsing this forum: No registered users and 6 guests