Specific attributes set for certain groups

Permalink 1 user found helpful
Wrapping my head around the csm still, getting there.

Is it possible to add specific attributes only to certain user groups? Looking at previous posts on the topic there seems to be a worrying lack of solutions :s

For example, if a user signs up under group "coach" they have certain fields to fill out.
If I then create an account for an administrator or copywriter, they obviously wouldn't need the same fields to fill out.

Attached a picture to try and be clearer.

Appreciate the help
Tim

1 Attachment

mckinstry
View Replies:
A3020 replied on at Permalink Reply
A3020
I had the same problem for the /profile/edit page and came with this solution. Maybe it is of help?

if($u->inGroup(Group::getByName('GROUP NAME 1'))){
   $set = AttributeSet::getByHandle('SET HANDLE 1');
} elseif($u->inGroup(Group::getByName('GROUP NAME 2'))){
   $set = AttributeSet::getByHandle('SET HANDLE 1');
}
if(is_object($set)){
   $attribs = $set->getAttributeKeys();
}
nickharris replied on at Permalink Reply
Love this solution.
1 question:
How can you get attributes which AREN'T in an attribute set?
A3020 replied on at Permalink Reply
A3020
AttributeKey::getList('Collection');
AttributeKey::getList('User');
AttributeKey::getList('File');
rockface replied on at Permalink Reply
rockface
I know this is an older thread, but the solution provides did not cover all the scenarios and would not work for me.

So, this method uses Attribute Sets. If you create an attribute set and name it the same as a user group name, this query will return all the akIDs for a given UserID
if(is_array($attribs) && count($attribs)) {
      $af = Loader::helper('form/attribute');
      $af->setAttributeObject($profile);
      //Load valid akID's for this user (based on user group)
      $sql="SELECT AttributeKeys.akID  " . 
         "FROM AttributeKeyCategories  " . 
         "INNER JOIN ((Groups LEFT JOIN UserGroups ON Groups.gID = UserGroups.gID) " . 
         "RIGHT JOIN (AttributeSets RIGHT JOIN (AttributeKeys " . 
         "LEFT JOIN AttributeSetKeys ON AttributeKeys.akID = AttributeSetKeys.akID) " . 
         "ON AttributeSets.asID = AttributeSetKeys.asID) " . 
         "ON Groups.gName = AttributeSets.asName) " . 
         "ON AttributeKeyCategories.akCategoryID = AttributeKeys.akCategoryID " .
         "WHERE ((AttributeSets.asName='Member Info') AND (AttributeKeyCategories.akCategoryHandle='user')) " . 
         "OR ((AttributeSets.asName Is Null) AND (AttributeKeyCategories.akCategoryHandle='user')) " . 
         "OR ((UserGroups.uID=?) AND (AttributeKeyCategories.akCategoryHandle='user'))";

Placing this code in a custom version of the edit_profile.php single page and the system will display all user attributes in
1. All attributes in the "Member Info" attribute set
2. All user attributes not in an attribute set
3. All attributes in the attribute set named the same as any user group assigned to the user

Once the array of valid akIDs is created, the code which normally writes out all user fields is given a condition resticting it to only show attributes which are in the array of valid akIDs:

-> if (in_array($ak->getAttributeKeyID(), $akIDs)) {

I know this could be done with real Concrete5 class calls, but i needed something that works and the 5.7 documentation does not cover these features yet.