public function GetData() { // Fetch from model. $Model = new ConversationModel(); $Result = $Model->Get($this->UserID, 0, $this->Limit, array()); // Join in the participants. $Model->JoinParticipants($Result); $this->SetData('Conversations', $Result); }
public function GetWhispers($DiscussionID, $Comments, $Limit, $Offset) { $FirstDate = NULL; $LastDate = NULL; if (count($Comments) > 0) { if ($Offset > 0) { $FirstComment = array_shift($Comments); $FirstDate = GetValue('DateInserted', $FirstComment); array_unshift($Comments, $FirstComment); } if (count($Comments) < $Limit) { $LastComment = array_pop($Comments); array_push($Comments, $LastComment); $LastCommentID = GetValue('CommentID', $LastComment); // We need to grab the comment that is one after the last comment. $LastComment = Gdn::SQL()->Limit(1)->GetWhere('Comment', array('DiscussionID' => $DiscussionID, 'CommentID >' => $LastCommentID))->FirstRow(); if ($LastComment) { $LastDate = GetValue('DateInserted', $LastComment); } } } // Grab the conversations that are associated with this discussion. $Sql = Gdn::SQL()->Select('c.ConversationID, c.DateUpdated')->From('Conversation c')->Where('c.DiscussionID', $DiscussionID); if (!Gdn::Session()->CheckPermission('Conversations.Moderation.Manage')) { $Sql->Join('UserConversation uc', 'c.ConversationID = uc.ConversationID')->Where('uc.UserID', Gdn::Session()->UserID); } $Conversations = $Sql->Get()->ResultArray(); $Conversations = Gdn_DataSet::Index($Conversations, 'ConversationID'); // Join the participants into the conversations. $ConversationModel = new ConversationModel(); $ConversationModel->JoinParticipants($Conversations); $this->Conversations = $Conversations; $ConversationIDs = array_keys($Conversations); // Grab all messages that are between the first and last dates. $Sql = Gdn::SQL()->Select('cm.*')->From('ConversationMessage cm')->WhereIn('cm.ConversationID', $ConversationIDs)->OrderBy('cm.DateInserted'); if ($FirstDate) { $Sql->Where('cm.DateInserted >=', $FirstDate); } if ($LastDate) { $Sql->Where('cm.DateInserted <', $LastDate); } $Whispers = $Sql->Get(); Gdn::UserModel()->JoinUsers($Whispers->Result(), array('InsertUserID')); // Add dummy comment fields to the whispers. $WhispersResult =& $Whispers->Result(); foreach ($WhispersResult as &$Whisper) { SetValue('DiscussionID', $Whisper, $DiscussionID); SetValue('CommentID', $Whisper, 'w' . GetValue('MessageID', $Whisper)); SetValue('Type', $Whisper, 'Whisper'); SetValue('Url', $Whisper, ''); $Participants = GetValueR(GetValue('ConversationID', $Whisper) . '.Participants', $Conversations); SetValue('Participants', $Whisper, $Participants); } return $Whispers; }