function _privatemsg_format_participants

1 privatemsg.module _privatemsg_format_participants($part_array, $limit = NULL, $no_text = FALSE)
7-1 privatemsg.module _privatemsg_format_participants($part_array, $limit = NULL, $no_text = FALSE)
7-2 privatemsg.module _privatemsg_format_participants($part_array, $limit = NULL, $no_text = FALSE)
6-2 privatemsg.module _privatemsg_format_participants($part_array, $limit = NULL, $no_text = FALSE)

Format an array of user objects.

Parameters

$part_array: Array with user objects, for example the one returned by _privatemsg_generate_user_array.

$limit: Limit the number of user objects which should be displayed.

$no_text: When TRUE, don't display the Participants/From text.

Return value

String with formatted user objects, like user1, user2.

2 calls to _privatemsg_format_participants()

File

./privatemsg.module, line 126
Allows users to send private messages to other users.

Code

function _privatemsg_format_participants($part_array, $limit = NULL, $no_text = FALSE) {
  global $user;
  if (count($part_array) > 0) {
    $to = array();
    $limited = FALSE;
    foreach ($part_array as $account) {

      // Directly address the current user.
      if (isset($account->type) && in_array($account->type, array('hidden', 'user')) && $account->recipient == $user->uid) {
        array_unshift($to, $no_text ? t('You') : t('you'));
        continue;
      }

      // Don't display recipients with type hidden.
      if (isset($account->type) && $account->type == 'hidden') {
        continue;
      }
      if (is_int($limit) && count($to) >= $limit) {
        $limited = TRUE;
        break;
      }
      $to[] = privatemsg_recipient_format($account);
    }

    $limit_string = '';
    if ($limited) {
      $limit_string = t(' and others');
    }


    if ($no_text) {
      return implode(', ', $to) . $limit_string;
    }

    $last = array_pop($to);
    if (count($to) == 0) { // Only one participant
      return t("From !last", array('!last' => $last));
    }
    else { // Multiple participants..
      $participants = implode(', ', $to);
      return t('Between !participants and !last', array('!participants' => $participants, '!last' => $last));
    }
  }
  return '';
}