public static function participantTitle($Conversation, $Html = true, $Max = 3)
{
$Participants = val('Participants', $Conversation);
$Total = (int) val('CountParticipants', $Conversation);
$MyID = Gdn::session()->UserID;
$FoundMe = false;
// Try getting people that haven't left the conversation and aren't you.
$Users = array();
$i = 0;
foreach ($Participants as $Row) {
if (val('UserID', $Row) == $MyID) {
$FoundMe = true;
continue;
}
if (val('Deleted', $Row)) {
continue;
}
if ($Html) {
$Users[] = userAnchor($Row);
} else {
$Users[] = val('Name', $Row);
}
$i++;
if ($i > $Max || $Total > $Max && $i === $Max) {
break;
}
}
$Count = count($Users);
if ($Count === 0) {
if ($FoundMe) {
$Result = t('Just you');
} elseif ($Total) {
$Result = plural($Total, '%s person', '%s people');
} else {
$Result = t('Nobody');
}
} else {
$Px = implode(', ', $Users);
if ($Count + 1 === $Total && $FoundMe) {
$Result = $Px;
} elseif ($Total - $Count === 1) {
$Result = sprintf(t('%s and 1 other'), $Px);
} elseif ($Total > $Count) {
$Result = sprintf(t('%s and %s others'), $Px, $Total - $Count);
} else {
$Result = $Px;
}
}
return $Result;
}