ConversationModel::getID PHP Метод

getID() публичный Метод

Get meta data of a single conversation.
public getID ( integer $ConversationID, string $datasetType = false, array $options = [] ) : array | stdClass
$ConversationID integer Unique ID of conversation.
$datasetType string The format of the resulting conversation.
$options array Options to modify the get. Currently supports `viewingUserID`.
Результат array | stdClass Returns a conversation.
    public function getID($ConversationID, $datasetType = false, $options = [])
    {
        if (is_numeric($datasetType)) {
            deprecated('ConversationModel->getID(int, int)', 'ConversationModel->getID(int, string, array)');
            $viewingUserID = $datasetType;
            $datasetType = false;
        } else {
            $viewingUserID = val('viewingUserID', $options);
        }
        $datasetType = $datasetType ?: DATASET_TYPE_OBJECT;
        // Get the conversation.
        $Conversation = $this->getWhere(array('ConversationID' => $ConversationID))->firstRow(DATASET_TYPE_ARRAY);
        if ($viewingUserID) {
            $Data = $this->SQL->getWhere('UserConversation', array('ConversationID' => $ConversationID, 'UserID' => $viewingUserID))->firstRow(DATASET_TYPE_ARRAY);
            // Convert the array.
            $UserConversation = arrayTranslate($Data, array('LastMessageID', 'CountReadMessages', 'DateLastViewed', 'Bookmarked'));
            $UserConversation['CountNewMessages'] = $Conversation['CountMessages'] - $Data['CountReadMessages'];
        } else {
            $UserConversation = array('CountNewMessages' => 0, 'CountReadMessages' => $Conversation['CountMessages'], 'DateLastViewed' => $Conversation['DateUpdated']);
        }
        $Conversation = array_merge($Conversation, $UserConversation);
        if ($datasetType === DATASET_TYPE_OBJECT) {
            $Conversation = (object) $Conversation;
        }
        return $Conversation;
    }

Usage Example

Пример #1
0
 /**
  *
  *
  * @param $ConversationID
  * @param null $LastMessageID
  * @throws Exception
  */
 public function getNew($ConversationID, $LastMessageID = null)
 {
     $this->RecipientData = $this->ConversationModel->getRecipients($ConversationID);
     $this->setData('Recipients', $this->RecipientData);
     // Check permissions on the recipients.
     $InConversation = false;
     foreach ($this->RecipientData->result() as $Recipient) {
         if ($Recipient->UserID == Gdn::session()->UserID) {
             $InConversation = true;
             break;
         }
     }
     if (!$InConversation) {
         // Conversation moderation must be enabled and they must have permission
         if (!c('Conversations.Moderation.Allow', false)) {
             throw permissionException();
         }
         $this->permission('Conversations.Moderation.Manage');
     }
     $this->Conversation = $this->ConversationModel->getID($ConversationID);
     $this->setData('Conversation', $this->Conversation);
     // Bad conversation? Redirect
     if ($this->Conversation === false) {
         throw notFoundException('Conversation');
     }
     $Where = array();
     if ($LastMessageID) {
         if (strpos($LastMessageID, '_') !== false) {
             $LastMessageID = array_pop(explode('_', $LastMessageID));
         }
         $Where['MessageID >='] = $LastMessageID;
     }
     // Fetch message data
     $this->setData('MessageData', $this->ConversationMessageModel->get($ConversationID, Gdn::session()->UserID, 0, 50, $Where), true);
     $this->render('Messages');
 }