function user_alter_student_profile_items

7.x user.module user_alter_student_profile_items($bool_mini, &$extra_profile_items, $bool_balance = TRUE, $alt_section = "")
6.x user.module user_alter_student_profile_items($bool_mini, &$extra_profile_items, $bool_balance = TRUE, $alt_section = "")

Implements hook_alter_student_profile_items

We want to see if any modules have registered attributes which are visible or editible in the student profile box.

File

modules/user/user.module, line 559

Code

function user_alter_student_profile_items($bool_mini, &$extra_profile_items, $bool_balance = TRUE, $alt_section = "") {
  global $current_student_id;

  $user_id = db_get_user_id_from_cwid($current_student_id, 'student');

  $attributes = user_get_registered_attributes();
  if (count($attributes) === 0) {
    return; // nothing to do.
  }

  foreach ($attributes as $attr => $definition) {

    if ($alt_section != "" && @$definition ['settings']['alt_section'] != $alt_section) {
      continue;
    }


    if (!isset($definition ['display'])) {
      // No display set, so create a "default" one that just uses the title of the attribute
      $definition ['display']['value'] = array(
        'label' => $definition ['title'],
      );
    }


    foreach ($definition ['display'] as $attr_key => $details) {
      $value = user_get_attribute($user_id, $attr . "__" . $attr_key, '');
      $display_value = filter_markup($value, 'plain');

      // Is there any special way this value is meant to be displayed?
      // Ex: if its a date field, should we change how that gets displayed?
      invoke_hook("alter_user_attribute_display", array($attr . '__' . $attr_key, &$display_value));


      // If this attribute had "options", like radios or select, then use THAT value.  Doesn't work with select lists that
      // make use of optgroups.      
      if (isset($definition ['fields'][$attr_key]['options'][$value])) {
        $display_value = $definition ['fields'][$attr_key]['options'][$value];
      }

      $item = array();
      $item ['label'] = $details ['label'];


      $item ['content'] = (isset($details ['value']) == TRUE) ? $details ['value'] : '';

      $item ['content'] = str_replace("@value", $display_value, $item ['content']);
      $item ['content'] = str_replace("@key", $value, $item ['content']);
      if (trim($item ['content']) == "") {
        $item ['content'] = $display_value;
      }



      $bool_add_it = FALSE;
      $bool_added_edit = FALSE;

      $edit_link = "";
      $url = fp_url("user/$user_id/edit-attribute/$attr", "window_mode=popup");
      $title = t("Edit ") . $definition ['title'];
      $title = htmlentities($title, ENT_QUOTES);
      if (user_has_permission("edit_attribute_$attr")) {
        $edit_link = "<a class='user-edit-attribute-link' href='javascript:fpOpenSmallIframeDialog(\"$url\", \"$title\");'><i class='fa fa-pencil'></i></a>";
      }

      if (!$bool_mini) {
        if ($definition ['settings']['large_profile']) {
          // We are on the large profile, and this element shoudl show on the large profile.
          $bool_add_it = TRUE;
        } // large_profile
        if ($definition ['settings']['large_profile_editable']) {
          $bool_add_it = TRUE;
          // Display link to edit this attribute.
          $item ['content'] .= $edit_link;
          $bool_added_edit = TRUE;
        }
      } // if NOT mini
      else if ($bool_mini) {
        // This IS mini        
        if ($definition ['settings']['mini_profile']) {
          // We are on the large profile, and this element should show on the mini profile.
          $bool_add_it = TRUE;
        }
        if ($definition ['settings']['mini_profile_editable']) {
          // We are on the large profile, and this element should show on the mini profile.
          $bool_add_it = TRUE;
          $item ['content'] .= $edit_link;
          $bool_added_edit = TRUE;
        }
      } // else is mini      



      if ($alt_section != "" && isset($definition ['settings']['alt_section'])) {

        // Are we adding to some alt_section?  Is it editable?
        if ($definition ['settings']['alt_section'] == $alt_section) {

          // We are defined some alt section
          $bool_add_it = TRUE;
        }
        if (@$definition ['settings']['alt_editable'] && $bool_added_edit == FALSE) {
          // We are on the large profile, and this element should show on the mini profile.
          $bool_add_it = TRUE;
          $item ['content'] .= $edit_link;
          $bool_added_edit = TRUE;
        }
      }



    } // foreach


    if ($bool_add_it && $bool_balance) {
      // permission check as to whether it can be viewed at all
      if (user_has_permission("view_attribute_$attr")) {
        fp_push_and_balance_profile_items($extra_profile_items, array($attr . "__" . $attr_key => $item));
      }
    }
    else if ($bool_add_it) {
      $extra_profile_items [$attr . '__' . $attr_key] = $item;
    }

  } // foreach attributes


}