Help please :-) with fetch user --> group

Author Message

danny36 danny36

Wednesday 27 October 2004 2:46:17 am

I need to display the name of the group the user belongs to.
I try to use:

{let utente=fetch( 'user', 'current_user' )}
{$utente.groups[0]}
{/let}

but i obtain only the object_ID of the group.

<b>Is there a way to obtain the name of the group??</b>

Thank you very much

danny36 danny36

Wednesday 17 November 2004 6:50:34 am

anyone can help me?

Łukasz Serwatka

Wednesday 17 November 2004 6:53:25 am

Hi

Try use

{$utente|attribute}

to view all attributes

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

danny36 danny36

Wednesday 17 November 2004 7:16:58 am

yes but this show all attributes of user included the subarray group, but how can i access to the attribute of this sub array?

Łukasz Serwatka

Wednesday 17 November 2004 7:20:47 am

Use this

{let utente=fetch( 'user', 'current_user' )}
{$utente.contentobject.id}

{let group=fetch( 'user', 'member_of',
       hash( 'id', $utente.contentobject.id ) )}

{$group[0].name}

{/let}

{/let}

{$group} is a array so you can use {section} to view all groups for curren user

it works but i think that is a simple way to fetch user group

P.S
Please edit your last post, it`s too long ;-)

Personal website -> http://serwatka.net
Blog (about eZ Publish) -> http://serwatka.net/blog

danny36 danny36

Wednesday 17 November 2004 7:49:36 am

I found this code snippet in the documentation:

{let user=fetch( 'user', 'current_user' )}
   User:     {$user.contentobject.name}<br />
   Email:    {$user.email}<br />
   Login:    {$user.login}<br />
   Group(s): {$user.groups|implode(', ')}<br />
{/let}

the code show me this result:

User: Anonymous User
Email: [email protected]
Login: anonymous
Groups: 42

but is still show the Object ID of "anonymous" group, how can i access of attribute "name" and "description" of class "group" that can i found in the "classes" link in admin site?

Bruce Morrison

Thursday 18 November 2004 2:09:05 pm

Once you have the object id(s) of the group(s) you can fetch them just like any other object using

{let utente=fetch( 'user', 'current_user' )
     group=fetch( 'content', 'object', hash( 'object_id', $utente.groups[0] ) )}

Group name: {$group.name}
{/let}

See
http://ez.no/ez_publish/documentation/reference/data_fetching/content/object

Cheers
Bruce

My Blog: http://www.stuffandcontent.com/
Follow me on twitter: http://twitter.com/brucemorrison
Consolidated eZ Publish Feed : http://friendfeed.com/rooms/ez-publish

Norman Leutner

Thursday 29 December 2005 10:23:01 pm

For fetching and displaying the groups of the current user you can use:

{def $user=fetch( 'user', 'current_user' )}

{foreach $user.groups as $key => $group}
{def $group=fetch( 'content', 'object', hash( 'object_id', $user.groups[$key] ) )}
  User is Member of: {$group.name} <br/>
{/foreach}

Mit freundlichen Grüßen
Best regards

Norman Leutner

____________________________________________________________
eZ Publish Platinum Partner - http://www.all2e.com
http://ez.no/partners/worldwide_partners/all2e_gmbh

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.