klox7 VIP
Total posts: 914
06 Фев 2015 15:47

Hello,

I'm trying to display something in my custom template to other users but only if record has author and this author is in specific user group. So if author is in group X show this.

I know $author is for record owner but how to get his usergroup.

Regards

Последние изменения: 09 Фев 2015

Метки Developer


pepperstreet VIP
Total posts: 3,837
08 Фев 2015 02:55

Hello klox7,

Do you have the author's ID?

I have found the following Joomla forum topic... maybe still valid and of any help for you.

The following example uses 42 as the author's ID.

jimport( 'joomla.access.access' );
$groups = JAccess::getGroupsByUser(42, false);
print_r($groups);

klox7 VIP
Total posts: 914
08 Фев 2015 19:24

Hi,

isn't this just for logged in users? But anyway I don't have specific user ID because I need "show something to users if the one is has record is record owner and in specific group".

Thanks


pepperstreet VIP
Total posts: 3,837
08 Фев 2015 19:35

klox7 if record has author and this author is in specific user group. So if author is in group X show this.

klox7 anyway I don't have specific user ID

Sorry, then I am lost in translation. ;) What do you mean by "author"? And who is the visiter/viewer in your scenario?


This is what I have read in your first post:

  • A visiter is viewing a record of another user (author).
  • You want to know, if record author is in a specific usergroup.
  • If author in group A show content part X.
  • If author not in group A, show content part Y.

klox7 VIP
Total posts: 914
08 Фев 2015 20:36

pepperstreet Sorry, then I am lost in translation. ;) What do you mean by "author"? And who is the visiter/viewer in your scenario?

Author is "record owner", visitor is any other user (public or logged in) who is reading authors record.

pepperstreet

  • A visiter is viewing a record of another user (author).
  • You want to know, if record author is in a specific usergroup.
  • If author in group A show content part X.
  • exactly, but I can not use this $groups = JAccess::getGroupsByUser(42, false); because I have many authors with many records.


    pepperstreet VIP
    Total posts: 3,837
    08 Фев 2015 21:52

    klox7 I have many authors with many records.

    ???


    klox7 VIP
    Total posts: 914
    09 Фев 2015 08:02

    pepperstreet

    klox7 I have many authors with many records.

    ???

    Author = record owner = posted by...

    So yes, I have many authors with many records because users, that are in specific user group can submit records.


    Sergey
    Total posts: 13,748
    09 Фев 2015 09:52
    jimport( 'joomla.access.access' );
    $allow_for_group = 5;
    $groups = JAccess::getGroupsByUser($item->user_id, false);
    if(!empty($item->user_id) && in_array($allow_for_group, $groups))
    {
       /// Show what you what here
    }
    
    Работает на Cobalt