You are here

function _privatemsg_format_participants in Privatemsg 6.2

Same name and namespace in other branches
  1. 6 privatemsg.module \_privatemsg_format_participants()
  2. 7.2 privatemsg.module \_privatemsg_format_participants()
  3. 7 privatemsg.module \_privatemsg_format_participants()

Format an array of user objects.

Parameters

$part_array: Array with user objects, for example the one returnd 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 formated user objects, like user1, user2.

3 calls to _privatemsg_format_participants()
phptemplate_privatemsg_list_field__participants in ./privatemsg.theme.inc
Theme the participants field.
privatemsg_form_reply in ./privatemsg.pages.inc
Form builder function; Write a reply to a thread.
template_preprocess_privatemsg_recipients in ./privatemsg.module

File

./privatemsg.module, line 92
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 {

      // Multipe participants..
      $participants = implode(', ', $to);
      return t('Between !participants and !last', array(
        '!participants' => $participants,
        '!last' => $last,
      ));
    }
  }
  return '';
}