Beispiel #1
0
 /**
  * Shows all uncleared messages within a conversation for the viewing user
  *
  * @todo ENFORCE PERMISSIONS SO THAT PEOPLE CAN'T READ OTHER PEOPLE'S MESSAGES
  */
 public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '')
 {
     if ($this->Head) {
         $this->Head->Title(Translate('Conversations'));
     }
     $this->Offset = $Offset;
     $Session = Gdn::Session();
     if (!is_numeric($ConversationID) || $ConversationID < 0) {
         $ConversationID = 0;
     }
     $this->Form->SetModel($this->ConversationMessageModel);
     $this->Form->AddHidden('ConversationID', $ConversationID);
     $this->RecipientData = $this->ConversationModel->GetRecipients($ConversationID);
     $this->Conversation = $this->ConversationModel->GetID($ConversationID, $Session->UserID);
     if ($this->Conversation === FALSE) {
         Redirect('garden/home/filenotfound');
     }
     if ($Limit == '' || !is_numeric($Limit) || $Limit < 0) {
         $Limit = Gdn::Config('Conversations.Messages.PerPage', 50);
     }
     if (!is_numeric($this->Offset) || $this->Offset < 0) {
         // Round down to the appropriate offset based on the user's read messages & messages per page
         $CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages;
         if ($CountReadMessages < 0) {
             $CountReadMessages = 0;
         }
         if ($CountReadMessages > $this->Conversation->CountMessages) {
             $CountReadMessages = $this->Conversation->CountMessages;
         }
         // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
         $this->Offset = floor($CountReadMessages / $Limit) * $Limit;
     }
     $this->MessageData = $this->ConversationMessageModel->Get($ConversationID, $Session->UserID, $this->Offset, $Limit);
     // $CountMessages = $this->ConversationMessageModel->GetCount($ConversationID, $Session->UserID);
     // Build a pager
     $PagerFactory = new PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'Newer Messages';
     $this->Pager->LessCode = 'Older Messages';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($this->Offset, $Limit, $this->Conversation->CountMessages, 'messages/' . $ConversationID . '/%1$s/%2$s/');
     // Mark the conversation as ready by this user.
     $this->ConversationModel->MarkRead($ConversationID, $Session->UserID);
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'messages';
     }
     $this->AddModule('NewConversationModule');
     $ClearHistoryModule = new ClearHistoryModule($this);
     $ClearHistoryModule->ConversationID($ConversationID);
     $this->AddModule($ClearHistoryModule);
     $InThisConversationModule = new InThisConversationModule($this);
     $InThisConversationModule->SetData($this->RecipientData);
     $this->AddModule($InThisConversationModule);
     $this->AddModule('AddPeopleModule');
     $this->Render();
 }
 /**
  * Shows all uncleared messages within a conversation for the viewing user
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $ConversationID Unique ID of conversation to view.
  * @param int $Offset Number to skip.
  * @param int $Limit Number to show.
  */
 public function index($ConversationID = false, $Offset = -1, $Limit = '')
 {
     $this->Offset = $Offset;
     $Session = Gdn::session();
     Gdn_Theme::section('Conversation');
     // Figure out Conversation ID
     if (!is_numeric($ConversationID) || $ConversationID < 0) {
         $ConversationID = 0;
     }
     // Form setup for adding comments
     $this->Form->setModel($this->ConversationMessageModel);
     $this->Form->addHidden('ConversationID', $ConversationID);
     // Check permissions on the recipients.
     $InConversation = $this->ConversationModel->inConversation($ConversationID, Gdn::session()->UserID);
     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->Conversation->Participants = $this->ConversationModel->getRecipients($ConversationID);
     $this->setData('Conversation', $this->Conversation);
     // Bad conversation? Redirect
     if ($this->Conversation === false) {
         throw notFoundException('Conversation');
     }
     // Get limit
     if ($Limit == '' || !is_numeric($Limit) || $Limit < 0) {
         $Limit = Gdn::config('Conversations.Messages.PerPage', 50);
     }
     // Calculate counts
     if (!is_numeric($this->Offset) || $this->Offset < 0) {
         // Round down to the appropriate offset based on the user's read messages & messages per page
         $CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages;
         if ($CountReadMessages < 0) {
             $CountReadMessages = 0;
         }
         if ($CountReadMessages > $this->Conversation->CountMessages) {
             $CountReadMessages = $this->Conversation->CountMessages;
         }
         // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
         $this->Offset = floor($CountReadMessages / $Limit) * $Limit;
         // Send the hash link in.
         if ($CountReadMessages > 1) {
             $this->addDefinition('LocationHash', '#Item_' . $CountReadMessages);
         }
     }
     // Fetch message data
     $this->MessageData = $this->ConversationMessageModel->get($ConversationID, $Session->UserID, $this->Offset, $Limit);
     $this->EventArguments['MessageData'] = $this->MessageData;
     $this->fireEvent('beforeMessages');
     $this->setData('Messages', $this->MessageData);
     // Figure out who's participating.
     $ParticipantTitle = ConversationModel::participantTitle($this->Conversation, true);
     $this->Participants = $ParticipantTitle;
     $this->title(strip_tags($this->Participants));
     // $CountMessages = $this->ConversationMessageModel->getCount($ConversationID, $Session->UserID);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->getPager('MorePager', $this);
     $this->Pager->MoreCode = 'Newer Messages';
     $this->Pager->LessCode = 'Older Messages';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->configure($this->Offset, $Limit, $this->Conversation->CountMessages, 'messages/' . $ConversationID . '/%1$s/%2$s/');
     // Mark the conversation as ready by this user.
     $this->ConversationModel->markRead($ConversationID, $Session->UserID);
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->setJson('LessRow', $this->Pager->toString('less'));
         $this->setJson('MoreRow', $this->Pager->toString('more'));
         $this->View = 'messages';
     }
     // Add modules.
     $ClearHistoryModule = new ClearHistoryModule($this);
     $ClearHistoryModule->conversationID($ConversationID);
     $this->addModule($ClearHistoryModule);
     $InThisConversationModule = new InThisConversationModule($this);
     $InThisConversationModule->setData($this->Conversation->Participants);
     $this->addModule($InThisConversationModule);
     // Doesn't make sense for people who can't even start conversations to be adding people
     if (checkPermission('Conversations.Conversations.Add')) {
         $this->addModule('AddPeopleModule');
     }
     $Subject = $this->data('Conversation.Subject');
     if (!$Subject) {
         $Subject = t('Message');
     }
     $this->Data['Breadcrumbs'][] = array('Name' => $Subject, 'Url' => url('', '//'));
     // Render view
     $this->render();
 }
 /**
  * Shows all uncleared messages within a conversation for the viewing user
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $ConversationID Unique ID of conversation to view.
  * @param int $Offset Number to skip.
  * @param int $Limit Number to show.
  */
 public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '')
 {
     $this->Offset = $Offset;
     $Session = Gdn::Session();
     Gdn_Theme::Section('Conversation');
     // Figure out Conversation ID
     if (!is_numeric($ConversationID) || $ConversationID < 0) {
         $ConversationID = 0;
     }
     // Form setup for adding comments
     $this->Form->SetModel($this->ConversationMessageModel);
     $this->Form->AddHidden('ConversationID', $ConversationID);
     // Get conversation data
     $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');
     }
     // Get limit
     if ($Limit == '' || !is_numeric($Limit) || $Limit < 0) {
         $Limit = Gdn::Config('Conversations.Messages.PerPage', 50);
     }
     // Calculate counts
     if (!is_numeric($this->Offset) || $this->Offset < 0) {
         // Round down to the appropriate offset based on the user's read messages & messages per page
         $CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages;
         if ($CountReadMessages < 0) {
             $CountReadMessages = 0;
         }
         if ($CountReadMessages > $this->Conversation->CountMessages) {
             $CountReadMessages = $this->Conversation->CountMessages;
         }
         // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
         $this->Offset = floor($CountReadMessages / $Limit) * $Limit;
         // Send the hash link in.
         if ($CountReadMessages > 1) {
             $this->AddDefinition('LocationHash', '#Item_' . $CountReadMessages);
         }
     }
     // Fetch message data
     $this->MessageData = $this->ConversationMessageModel->Get($ConversationID, $Session->UserID, $this->Offset, $Limit);
     // Figure out who's participating.
     $this->Participants = '';
     $Count = 0;
     $Users = array();
     $InConversation = FALSE;
     foreach ($this->RecipientData->Result() as $User) {
         $Count++;
         if ($User->UserID == $Session->UserID) {
             $InConversation = TRUE;
             continue;
         }
         if ($User->Deleted) {
             $Users[] = Wrap(UserAnchor($User), 'del', array('title' => sprintf(T('%s has left this conversation.'), htmlspecialchars($User->Name))));
             $this->SetData('_HasDeletedUsers', TRUE);
         } else {
             $Users[] = UserAnchor($User);
         }
     }
     if ($InConversation) {
         if (count($Users) == 0) {
             $this->Participants = T('Just you!');
         } else {
             $this->Participants = sprintf(T('%s and you'), implode(', ', $Users));
         }
     } else {
         $this->Participants = implode(', ', $Users);
     }
     $this->Title(strip_tags($this->Participants));
     // $CountMessages = $this->ConversationMessageModel->GetCount($ConversationID, $Session->UserID);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'Newer Messages';
     $this->Pager->LessCode = 'Older Messages';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($this->Offset, $Limit, $this->Conversation->CountMessages, 'messages/' . $ConversationID . '/%1$s/%2$s/');
     // Mark the conversation as ready by this user.
     $this->ConversationModel->MarkRead($ConversationID, $Session->UserID);
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'messages';
     }
     // Add modules.
     $ClearHistoryModule = new ClearHistoryModule($this);
     $ClearHistoryModule->ConversationID($ConversationID);
     $this->AddModule($ClearHistoryModule);
     $InThisConversationModule = new InThisConversationModule($this);
     $InThisConversationModule->SetData($this->RecipientData);
     $this->AddModule($InThisConversationModule);
     $this->AddModule('AddPeopleModule');
     // Render view
     $this->Render();
 }
 /**
  * Shows all uncleared messages within a conversation for the viewing user
  */
 public function Index($ConversationID = FALSE, $Offset = -1, $Limit = '')
 {
     $this->Offset = $Offset;
     $Session = Gdn::Session();
     if (!is_numeric($ConversationID) || $ConversationID < 0) {
         $ConversationID = 0;
     }
     $this->Form->SetModel($this->ConversationMessageModel);
     $this->Form->AddHidden('ConversationID', $ConversationID);
     $this->RecipientData = $this->ConversationModel->GetRecipients($ConversationID);
     $this->Conversation = $this->ConversationModel->GetID($ConversationID, $Session->UserID);
     if ($this->Conversation === FALSE) {
         Redirect('dashboard/home/filenotfound');
     }
     if ($Limit == '' || !is_numeric($Limit) || $Limit < 0) {
         $Limit = Gdn::Config('Conversations.Messages.PerPage', 50);
     }
     if (!is_numeric($this->Offset) || $this->Offset < 0) {
         // Round down to the appropriate offset based on the user's read messages & messages per page
         $CountReadMessages = $this->Conversation->CountMessages - $this->Conversation->CountNewMessages;
         if ($CountReadMessages < 0) {
             $CountReadMessages = 0;
         }
         if ($CountReadMessages > $this->Conversation->CountMessages) {
             $CountReadMessages = $this->Conversation->CountMessages;
         }
         // (((67 comments / 10 perpage) = 6.7) rounded down = 6) * 10 perpage = offset 60;
         $this->Offset = floor($CountReadMessages / $Limit) * $Limit;
     }
     $this->MessageData = $this->ConversationMessageModel->Get($ConversationID, $Session->UserID, $this->Offset, $Limit);
     $this->Participants = '';
     $Count = 0;
     $Users = array();
     foreach ($this->RecipientData->Result() as $User) {
         if ($User->Deleted) {
             continue;
         }
         $Count++;
         if ($User->UserID == $Session->UserID) {
             continue;
         }
         $Users[] = UserAnchor($User);
     }
     if (count($Users) == 0) {
         $this->Participants = T('Just you!');
     } else {
         $this->Participants = sprintf(T('%s and you'), implode(', ', $Users));
     }
     $this->Title(strip_tags($this->Participants));
     // $CountMessages = $this->ConversationMessageModel->GetCount($ConversationID, $Session->UserID);
     // Build a pager
     $PagerFactory = new Gdn_PagerFactory();
     $this->Pager = $PagerFactory->GetPager('MorePager', $this);
     $this->Pager->MoreCode = 'Newer Messages';
     $this->Pager->LessCode = 'Older Messages';
     $this->Pager->ClientID = 'Pager';
     $this->Pager->Configure($this->Offset, $Limit, $this->Conversation->CountMessages, 'messages/' . $ConversationID . '/%1$s/%2$s/');
     // Mark the conversation as ready by this user.
     $this->ConversationModel->MarkRead($ConversationID, $Session->UserID);
     // Deliver json data if necessary
     if ($this->_DeliveryType != DELIVERY_TYPE_ALL) {
         $this->SetJson('LessRow', $this->Pager->ToString('less'));
         $this->SetJson('MoreRow', $this->Pager->ToString('more'));
         $this->View = 'messages';
     }
     $this->AddModule('SignedInModule');
     $this->AddModule('NewConversationModule');
     $ClearHistoryModule = new ClearHistoryModule($this);
     $ClearHistoryModule->ConversationID($ConversationID);
     $this->AddModule($ClearHistoryModule);
     $InThisConversationModule = new InThisConversationModule($this);
     $InThisConversationModule->SetData($this->RecipientData);
     $this->AddModule($InThisConversationModule);
     $this->AddModule('AddPeopleModule');
     $this->Render();
 }