Hi,

I have enabled the user profile module, and have defined a "Company" field, with internal name "profile_company". I want to make this field visible in the group user listing. How is this possible?

Best regards,

Olivier

Comments

ShutterFreak’s picture

I guess I should edit og_list_users_sql(), og_list_users_page($gid) and og_list_users_faces_page($gid) for the magic to take effect.

Or do I need to edit a view too?

ShutterFreak’s picture

I got it working for me.

Basically I created the following function:

function get_company_for_user($uid) {
  $fid = 1; // Field identifier for the "Company" field (verify in the profile_fields table).
  $sql = "SELECT value FROM {profile_values} WHERE uid = %d AND fid = %d";
  $result = db_query($sql, $uid, $fid);
  while ($row = db_fetch_array($result)) {
    return $row['value'];
  }
  return '';
}

I then copied the theme_username() code from theme.inc to my theme's template.php:

function MYTHEME_username($object) {

  if ($object->uid && $object->name) {
    $company = og_get_company_for_user($object->uid);
    // Shorten the name when it is too long or it will break many tables.
    //if (drupal_strlen($object->name) > 20) {
    //  $name = drupal_substr($object->name, 0, 15) .'...';
    //}
    //else {
      $name = $object->name;
    //}

    if (user_access('access user profiles')) {
      $output = l($name, 'user/'. $object->uid, array('title' => t('View user profile.')));
    }
    else {
      $output = check_plain($name);
    }
    if (drupal_strlen($company) > 0) {
	    $output .= ' <span class="username-company">[' . $company . ']</span>';
    }
  }
  else if ($object->name) {
    // Sometimes modules display content composed by people who are
    // not registered members of the site (e.g. mailing list or news
    // aggregator modules). This clause enables modules to display
    // the true author of the content.
    if ($object->homepage) {
      $output = l($object->name, $object->homepage);
    }
    else {
      $output = check_plain($object->name);
    }

    $output .= ' ('. t('not verified') .')';
  }
  else {
    $output = variable_get('anonymous', t('Anonymous'));
  }

  return $output;
}
Cross_and_Flame’s picture

...and solve a question for me! Thanks!

ShutterFreak’s picture

As a result of applying my patch, every time a user name is displayed, the company is written too.

By defining the CSS for span.username-company you can influence the way the company information is displayed. When displaying users in an image grid (users with their avatar images), I define that span as a block with the following CSS: display: block;.