How to have different attributes for each usergroup

Permalink 1 user found helpful
Here is how I implement user attributes so I can have different data collected based on what user group the user is in.

1. Create all your attributes under "Dashboard > Members > Attributes".

2. Click on "Dashboard > Members > Attributes > Manage Sets [button]".

3. Create a new set for each user group (The handle needs to be the exact same handle used for the User Group) and check the checkboxes for each attribute to be show for each user group.

NOTE 1: If you want the same attribute shown to every user, do not place it in a attribute set.

NOTE 2: If you need the same attribute shown to multiple user groups (but not all of them) you will need to create a different one attribute for each user group.

4. Copy "concrete/single_pages/account/edit_profile.php" to "application/single_pages/account/edit_profile.php" to make a custom page.

5. Look for this code:
<?php
   if(is_array($attribs) && count($attribs)) {
      $af = Loader::helper('form/attribute');
      $af->setAttributeObject($profile);
      foreach($attribs as $ak) {
         print '<div class="ccm-profile-attribute">';
         print $af->display($ak, $ak->isAttributeKeyRequiredOnProfile());
         print '</div>';
      }
   }
   ?>


6. Change it to something like this:
<legend><?php echo t('Member Options')?></legend>   
   <?php
   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')) " .


That should do it - hope I remembered everything!

rockface
View Replies:
cd13sr replied on at Permalink Reply
Is this method/code still viable for version 8.1.0?

If so, how would you implement something similar for the profile view page?

Thanks!