ConversationModel::participantTitle PHP Метод

participantTitle() публичный статический Метод

Gets a nice title to represent the participants in a conversation.
public static participantTitle ( array | object $Conversation, boolean $Html = true, integer $Max = 3 ) : string
$Conversation array | object The conversation to get the participants for.
$Html boolean Whether or not to return HTML.
$Max integer The maximum number of participants to show in the list.
Результат string Returns a title for the conversation.
    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;
    }

Usage Example

Пример #1
0
    $CssClass .= $Conversation->CountNewMessages > 0 ? ' New' : '';
    $CssClass .= $LastPhoto != '' ? ' HasPhoto' : '';
    $CssClass .= ' ' . ($Conversation->CountNewMessages <= 0 ? 'Read' : 'Unread');
    $JumpToItem = $Conversation->CountMessages - $Conversation->CountNewMessages;
    $Message = sliceString(Gdn_Format::plainText($Conversation->LastBody, $Conversation->LastFormat), 100);
    if (stringIsNullOrEmpty(trim($Message))) {
        $Message = t('Blank Message');
    }
    $this->EventArguments['Conversation'] = $Conversation;
    ?>
    <li class="<?php 
    echo $CssClass;
    ?>
">
        <?php 
    $Names = ConversationModel::participantTitle($Conversation, false);
    ?>
        <div class="ItemContent Conversation">
            <?php 
    $Url = '/messages/' . $Conversation->ConversationID . '/#Item_' . $JumpToItem;
    echo '<h3 class="Users">';
    if ($Names) {
        if ($LastPhoto) {
            echo '<div class="Author Photo">' . $LastPhoto . '</div>';
        }
        echo anchor(htmlspecialchars($Names), $Url);
    }
    if ($Subject = val('Subject', $Conversation)) {
        if ($Names) {
            echo Bullet(' ');
        }
All Usage Examples Of ConversationModel::participantTitle