Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Show userrole View modes: 
User avatar
Member
Member
wessel.peeters-ibl-software - 12/16/2013 2:39:23 AM
   
Show userrole
Hello,

I would like to put on a profile page, the userroles that the current user is on.
Could i use a macro for this ? I can't figure it out.


Thank you.

User avatar
Kentico Support
Kentico Support
kentico_filipl - 12/16/2013 3:49:00 AM
   
RE:Show userrole
Hello Wessel,

There is only a built-in macro which determines if the selected user is in a chosen role.

Example using K# syntax:
{%if (CurrentUser.IsInRole("Editors")) {return true;} else {return false;} %}

If you need to have a method which will return all roles, you will need to create a custom macro (Developer's Guide - Registering custom macro methods) and use the following method for getting all roles:
CMS.SiteProvider.UserInfo.GetRoleIdList(Boolean includeGlobal, Boolean includeMembership, String siteName) - Gets all roles for current user

includeGlobal (Boolean) - If true, global roles are included
includeMembership (Boolean) - If true, membership roles are included
siteName (String) - Current site name


Best regards,
Filip Ligac

User avatar
Member
Member
wessel.peeters-ibl-software - 12/17/2013 2:00:21 AM
   
RE:Show userrole
Thank you for your message, could you give me some more information how to create the custom classes for giving the roles back

User avatar
Kentico Support
Kentico Support
kentico_filipl - 12/17/2013 2:37:51 AM
   
RE:Show userrole
Hello Wessel,

What exactly are you looking for? I think that the guide I attached the link to in my previous post contains a detailed description how you can create a custom macro method.

Best regards,
Filip Ligac

User avatar
Member
Member
wessel.peeters-ibl-software - 12/17/2013 2:55:21 AM
   
RE:Show userrole
I'm just would like that a repeater shows the current roles (with name) that a user is currently on

User avatar
Member
Member
kentico_davidb2 - 12/22/2013 10:17:47 AM
   
RE:Show userrole
The solution my colleague provided is probably the best for most scenarios.

As you specified it more and you want to use a repeater, please try the following:

Repeater with Custom Query webpart:

Query:
SELECT CMS_Role.RoleDisplayName
FROM CMS_Role
INNER JOIN CMS_UserRole ON CMS_Role.RoleID = CMS_UserRole.RoleID
WHERE ##WHERE##

Transformation:
SELECT CMS_Role.RoleDisplayName
FROM CMS_Role
INNER JOIN CMS_UserRole ON CMS_Role.RoleID = CMS_UserRole.RoleID
WHERE ##WHERE##

WHERE condition:
CMS_UserRole.UserID = {%CurrentUser.UserID%}

Dave