Since: 2.0.0
Inheritance: extends Gdn_Model
Ejemplo n.º 1
0
 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);
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 public function SettingsController_DashboardData_Handler(&$Sender)
 {
     $ConversationModel = new ConversationModel();
     // Number of Conversations
     $CountConversations = $ConversationModel->GetCountWhere();
     $Sender->AddDefinition('CountConversations', $CountConversations);
     $Sender->BuzzData[T('Conversations')] = number_format($CountConversations);
     // Number of New Conversations in the last day
     $Sender->BuzzData[T('New conversations in the last day')] = number_format($ConversationModel->GetCountWhere(array('DateInserted >=' => Gdn_Format::ToDateTime(strtotime('-1 day')))));
     // Number of New Conversations in the last week
     $Sender->BuzzData[T('New conversations in the last week')] = number_format($ConversationModel->GetCountWhere(array('DateInserted >=' => Gdn_Format::ToDateTime(strtotime('-1 week')))));
     $ConversationMessageModel = new ConversationMessageModel();
     // Number of Messages
     $CountMessages = $ConversationMessageModel->GetCountWhere();
     $Sender->AddDefinition('CountConversationMessages', $CountMessages);
     $Sender->BuzzData[T('Conversation Messages')] = number_format($CountMessages);
     // Number of New Messages in the last day
     $Sender->BuzzData[T('New messages in the last day')] = number_format($ConversationMessageModel->GetCountWhere(array('DateInserted >=' => Gdn_Format::ToDateTime(strtotime('-1 day')))));
     // Number of New Messages in the last week
     $Sender->BuzzData[T('New messages in the last week')] = number_format($ConversationMessageModel->GetCountWhere(array('DateInserted >=' => Gdn_Format::ToDateTime(strtotime('-1 week')))));
 }
Ejemplo n.º 4
0
 /**
  * Allows users to bookmark conversations.
  *
  * @param int $ConversationID Unique ID of conversation to view.
  * @param string $TransientKey Single-use hash to prove intent.
  */
 public function bookmark($ConversationID = '', $TransientKey = '')
 {
     $Session = Gdn::session();
     $Bookmark = null;
     // Validate & do bookmarking.
     if (is_numeric($ConversationID) && $ConversationID > 0 && $Session->UserID > 0 && $Session->validateTransientKey($TransientKey)) {
         $Bookmark = $this->ConversationModel->bookmark($ConversationID, $Session->UserID);
     }
     // Report success or error
     if ($Bookmark === false) {
         $this->Form->addError('ErrorBool');
     } else {
         $this->setJson('Bookmark', $Bookmark);
     }
     // Redirect back where the user came from if necessary
     if ($this->_DeliveryType == DELIVERY_TYPE_ALL) {
         redirect($_SERVER['HTTP_REFERER']);
     } else {
         $this->render();
     }
 }
 /**
  * Save message from form submission.
  * 
  * @since 2.0.0
  * @access public
  *
  * @param array $FormPostValues Values submitted via form.
  * @return int Unique ID of message created or updated.
  */
 public function Save($FormPostValues, $Conversation = NULL)
 {
     $Session = Gdn::Session();
     // Define the primary key in this model's table.
     $this->DefineSchema();
     // Add & apply any extra validation rules:
     $this->Validation->ApplyRule('Body', 'Required');
     $this->AddInsertFields($FormPostValues);
     // Validate the form posted values
     $MessageID = FALSE;
     if ($this->Validate($FormPostValues)) {
         $Fields = $this->Validation->SchemaValidationFields();
         // All fields on the form that relate to the schema
         TouchValue('Format', $Fields, C('Garden.InputFormatter', 'Html'));
         $MessageID = $this->SQL->Insert($this->Name, $Fields);
         $this->LastMessageID = $MessageID;
         $ConversationID = ArrayValue('ConversationID', $Fields, 0);
         if (!$Conversation) {
             $Conversation = $this->SQL->GetWhere('Conversation', array('ConversationID' => $ConversationID))->FirstRow(DATASET_TYPE_ARRAY);
         }
         // Get the new message count for the conversation.
         $SQLR = $this->SQL->Select('MessageID', 'count', 'CountMessages')->Select('MessageID', 'max', 'LastMessageID')->From('ConversationMessage')->Where('ConversationID', $ConversationID)->Get()->FirstRow(DATASET_TYPE_ARRAY);
         if (sizeof($SQLR)) {
             list($CountMessages, $LastMessageID) = array_values($SQLR);
         } else {
             return;
         }
         // Update the conversation's DateUpdated field.
         $DateUpdated = Gdn_Format::ToDateTime();
         $this->SQL->Update('Conversation c')->Set('CountMessages', $CountMessages)->Set('LastMessageID', $LastMessageID)->Set('UpdateUserID', Gdn::Session()->UserID)->Set('DateUpdated', $DateUpdated)->Where('ConversationID', $ConversationID)->Put();
         // Update the last message of the users that were previously up-to-date on their read messages.
         $this->SQL->Update('UserConversation uc')->Set('uc.LastMessageID', $MessageID)->Set('uc.DateConversationUpdated', $DateUpdated)->Where('uc.ConversationID', $ConversationID)->Where('uc.Deleted', '0')->Where('uc.CountReadMessages', $CountMessages - 1)->Where('uc.UserID <>', $Session->UserID)->Put();
         // Update the date updated of the users that were not up-to-date.
         $this->SQL->Update('UserConversation uc')->Set('uc.DateConversationUpdated', $DateUpdated)->Where('uc.ConversationID', $ConversationID)->Where('uc.Deleted', '0')->Where('uc.CountReadMessages <>', $CountMessages - 1)->Where('uc.UserID <>', $Session->UserID)->Put();
         // Update the sending user.
         $this->SQL->Update('UserConversation uc')->Set('uc.CountReadMessages', $CountMessages)->Set('Deleted', 0)->Set('uc.DateConversationUpdated', $DateUpdated)->Where('ConversationID', $ConversationID)->Where('UserID', $Session->UserID)->Put();
         // Find users involved in this conversation
         $UserData = $this->SQL->Select('UserID')->Select('LastMessageID')->Select('Deleted')->From('UserConversation')->Where('ConversationID', $ConversationID)->Get()->Result(DATASET_TYPE_ARRAY);
         $UpdateCountUserIDs = array();
         $NotifyUserIDs = array();
         // Collapse for call to UpdateUserCache and ActivityModel.
         $InsertUserFound = FALSE;
         foreach ($UserData as $UpdateUser) {
             $LastMessageID = GetValue('LastMessageID', $UpdateUser);
             $UserID = GetValue('UserID', $UpdateUser);
             $Deleted = GetValue('Deleted', $UpdateUser);
             if ($UserID == GetValue('InsertUserID', $Fields)) {
                 $InsertUserFound = TRUE;
                 if ($Deleted) {
                     $this->SQL->Put('UserConversation', array('Deleted' => 0, 'DateConversationUpdated' => $DateUpdated), array('ConversationID' => $ConversationID, 'UserID' => $UserID));
                 }
             }
             // Update unread for users that were up to date
             if ($LastMessageID == $MessageID) {
                 $UpdateCountUserIDs[] = $UserID;
             }
             // Send activities to users that have not deleted the conversation
             if (!$Deleted) {
                 $NotifyUserIDs[] = $UserID;
             }
         }
         if (!$InsertUserFound) {
             $UserConversation = array('UserID' => GetValue('InsertUserID', $Fields), 'ConversationID' => $ConversationID, 'LastMessageID' => $LastMessageID, 'CountReadMessages' => $CountMessages, 'DateConversationUpdated' => $DateUpdated);
             $this->SQL->Insert('UserConversation', $UserConversation);
         }
         if (sizeof($UpdateCountUserIDs)) {
             $ConversationModel = new ConversationModel();
             $ConversationModel->UpdateUserUnreadCount($UpdateCountUserIDs, TRUE);
         }
         $ActivityModel = new ActivityModel();
         foreach ($NotifyUserIDs as $NotifyUserID) {
             if ($Session->UserID == $NotifyUserID) {
                 continue;
             }
             // don't notify self.
             // Notify the users of the new message.
             $ActivityID = $ActivityModel->Add($Session->UserID, 'ConversationMessage', '', $NotifyUserID, '', "/messages/{$ConversationID}#{$MessageID}", FALSE);
             $Story = GetValue('Body', $Fields, '');
             if (C('Conversations.Subjects.Visible')) {
                 $Story = ConcatSep("\n\n", GetValue('Subject', $Conversation, ''), $Story);
             }
             $ActivityModel->SendNotification($ActivityID, $Story);
         }
     }
     return $MessageID;
 }
Ejemplo n.º 6
0
if (CheckPermission('Conversations.Conversations.Add')) {
    echo Anchor(T('New Message'), 'messages/add');
}
echo Wrap(T('Inbox'), 'strong');
?>
   </li>
<?php 
if (count($this->Data('Conversations'))) {
    ?>
   <?php 
    foreach ($this->Data('Conversations') as $Row) {
        $Subject = '';
        if ($Row['Subject']) {
            $Subject = Gdn_Format::Text($Row['Subject']);
        } else {
            $Subject = ConversationModel::ParticipantTitle($Row, FALSE);
        }
        $PhotoUser = UserBuilder($Row, 'LastInsert');
        ?>
   <li class="Item" rel="<?php 
        echo Url("/messages/{$Row['ConversationID']}#latest");
        ?>
">
      <div class="Author Photo"><?php 
        echo UserPhoto($PhotoUser);
        ?>
</div>
      <div class="ItemContent">
         <b class="Subject"><?php 
        echo Anchor($Subject, "/messages/{$Row['ConversationID']}#latest");
        ?>
Ejemplo n.º 7
0
 /**
  * Are we allowed to add more recipients?
  *
  * If we pass $CountRecipients then $ConversationID isn't needed (set to zero).
  *
  * @param int $ConversationID Unique ID of the conversation.
  * @param int $CountRecipients Optionally skip needing to query the count by passing it.
  * @return bool Whether user may add more recipients to conversation.
  */
 public function AddUserAllowed($ConversationID = 0, $CountRecipients = 0)
 {
     // Determine whether recipients can be added
     $CanAddRecipients = TRUE;
     $MaxCount = C('Conversations.MaxRecipients');
     // Avoid a query if we already know we can add. MaxRecipients being unset means unlimited.
     if ($MaxCount && !CheckPermission('Garden.Moderation.Manage')) {
         if (!$CountRecipients) {
             // Count current recipients
             $ConversationModel = new ConversationModel();
             $CountRecipients = $ConversationModel->GetRecipients($ConversationID);
         }
         // Add 1 because sender counts as a recipient.
         $CanAddRecipients = count($CountRecipients) < $MaxCount + 1;
     }
     return $CanAddRecipients;
 }
 /**
  * Save message from form submission.
  *
  * @since 2.0.0
  * @access public
  *
  * @param array $FormPostValues Values submitted via form.
  * @return int Unique ID of message created or updated.
  */
 public function save($FormPostValues, $Conversation = null, $Options = array())
 {
     $Session = Gdn::session();
     // Define the primary key in this model's table.
     $this->defineSchema();
     // Add & apply any extra validation rules:
     $this->Validation->applyRule('Body', 'Required');
     $this->addInsertFields($FormPostValues);
     $this->EventArguments['FormPostValues'] = $FormPostValues;
     $this->fireEvent('BeforeSaveValidation');
     // Determine if spam check should be skipped.
     $SkipSpamCheck = !empty($Options['NewConversation']);
     // Validate the form posted values
     $MessageID = false;
     if ($this->validate($FormPostValues) && !$this->checkForSpam('ConversationMessage', $SkipSpamCheck)) {
         $Fields = $this->Validation->schemaValidationFields();
         // All fields on the form that relate to the schema
         touchValue('Format', $Fields, c('Garden.InputFormatter', 'Html'));
         $this->EventArguments['Fields'] = $Fields;
         $this->fireEvent('BeforeSave');
         $MessageID = $this->SQL->insert($this->Name, $Fields);
         $this->LastMessageID = $MessageID;
         $ConversationID = val('ConversationID', $Fields, 0);
         if (!$Conversation) {
             $Conversation = $this->SQL->getWhere('Conversation', array('ConversationID' => $ConversationID))->firstRow(DATASET_TYPE_ARRAY);
         }
         $Message = $this->getID($MessageID);
         $this->EventArguments['Conversation'] = $Conversation;
         $this->EventArguments['Message'] = $Message;
         $this->fireEvent('AfterSave');
         // Get the new message count for the conversation.
         $SQLR = $this->SQL->select('MessageID', 'count', 'CountMessages')->select('MessageID', 'max', 'LastMessageID')->from('ConversationMessage')->where('ConversationID', $ConversationID)->get()->firstRow(DATASET_TYPE_ARRAY);
         if (sizeof($SQLR)) {
             list($CountMessages, $LastMessageID) = array_values($SQLR);
         } else {
             return;
         }
         // Update the conversation's DateUpdated field.
         $DateUpdated = Gdn_Format::toDateTime();
         $this->SQL->update('Conversation c')->set('CountMessages', $CountMessages)->set('LastMessageID', $LastMessageID)->set('UpdateUserID', Gdn::session()->UserID)->set('DateUpdated', $DateUpdated)->where('ConversationID', $ConversationID)->put();
         // Update the last message of the users that were previously up-to-date on their read messages.
         $this->SQL->update('UserConversation uc')->set('uc.LastMessageID', $MessageID)->set('uc.DateConversationUpdated', $DateUpdated)->where('uc.ConversationID', $ConversationID)->where('uc.Deleted', '0')->where('uc.CountReadMessages', $CountMessages - 1)->where('uc.UserID <>', $Session->UserID)->put();
         // Update the date updated of the users that were not up-to-date.
         $this->SQL->update('UserConversation uc')->set('uc.DateConversationUpdated', $DateUpdated)->where('uc.ConversationID', $ConversationID)->where('uc.Deleted', '0')->where('uc.CountReadMessages <>', $CountMessages - 1)->where('uc.UserID <>', $Session->UserID)->put();
         // Update the sending user.
         $this->SQL->update('UserConversation uc')->set('uc.CountReadMessages', $CountMessages)->set('Deleted', 0)->set('uc.DateConversationUpdated', $DateUpdated)->where('ConversationID', $ConversationID)->where('UserID', $Session->UserID)->put();
         // Find users involved in this conversation
         $UserData = $this->SQL->select('UserID')->select('LastMessageID')->select('Deleted')->from('UserConversation')->where('ConversationID', $ConversationID)->get()->result(DATASET_TYPE_ARRAY);
         $UpdateCountUserIDs = array();
         $NotifyUserIDs = array();
         // Collapse for call to UpdateUserCache and ActivityModel.
         $InsertUserFound = false;
         foreach ($UserData as $UpdateUser) {
             $LastMessageID = val('LastMessageID', $UpdateUser);
             $UserID = val('UserID', $UpdateUser);
             $Deleted = val('Deleted', $UpdateUser);
             if ($UserID == val('InsertUserID', $Fields)) {
                 $InsertUserFound = true;
                 if ($Deleted) {
                     $this->SQL->put('UserConversation', array('Deleted' => 0, 'DateConversationUpdated' => $DateUpdated), array('ConversationID' => $ConversationID, 'UserID' => $UserID));
                 }
             }
             // Update unread for users that were up to date
             if ($LastMessageID == $MessageID) {
                 $UpdateCountUserIDs[] = $UserID;
             }
             // Send activities to users that have not deleted the conversation
             if (!$Deleted) {
                 $NotifyUserIDs[] = $UserID;
             }
         }
         if (!$InsertUserFound) {
             $UserConversation = array('UserID' => val('InsertUserID', $Fields), 'ConversationID' => $ConversationID, 'LastMessageID' => $LastMessageID, 'CountReadMessages' => $CountMessages, 'DateConversationUpdated' => $DateUpdated);
             $this->SQL->insert('UserConversation', $UserConversation);
         }
         if (sizeof($UpdateCountUserIDs)) {
             $ConversationModel = new ConversationModel();
             $ConversationModel->updateUserUnreadCount($UpdateCountUserIDs, true);
         }
         $this->fireEvent('AfterAdd');
         $activityModel = new ActivityModel();
         foreach ($NotifyUserIDs as $notifyUserID) {
             if ($Session->UserID == $notifyUserID) {
                 continue;
                 // don't notify self.
             }
             // Notify the users of the new message.
             $activity = array('ActivityType' => 'ConversationMessage', 'ActivityUserID' => val('InsertUserID', $Fields), 'NotifyUserID' => $notifyUserID, 'HeadlineFormat' => t('HeadlineFormat.ConversationMessage', '{ActivityUserID,user} sent you a <a href="{Url,html}">message</a>'), 'RecordType' => 'Conversation', 'RecordID' => $ConversationID, 'Story' => val('Body', $Fields, ''), 'Format' => val('Format', $Fields, c('Garden.InputFormatter')), 'Route' => "/messages/{$ConversationID}#{$MessageID}");
             if (c('Conversations.Subjects.Visible') && val('Subject', $Conversation, '')) {
                 $activity['HeadlineFormat'] = val('Subject', $Conversation, '');
             }
             $activityModel->queue($activity, 'ConversationMessage');
         }
         $activityModel->saveQueue();
     }
     return $MessageID;
 }
Ejemplo n.º 9
0
 protected function AddIgnore($ForUserID, $IgnoreUserID)
 {
     $this->SetUserMeta($ForUserID, "Blocked.User.{$IgnoreUserID}", date('Y-m-d H:i:s'));
     // Since the Conversation application can be turned off, check first if the ConversationModel is present.
     if (class_exists('ConversationModel')) {
         // Remove from conversations
         $Conversations = $this->IgnoreConversations($IgnoreUserID, $ForUserID);
         Gdn::SQL()->Delete('UserConversation', array('UserID' => $ForUserID, 'ConversationID' => $Conversations));
         $conversationModel = new ConversationModel();
         $conversationModel->countUnread($ForUserID, true);
     }
 }
   public function Commit() {
      
      if (is_null($this->Type))
         throw new Exception(T("Adding a Regarding event requires a type."));

      if (is_null($this->ForeignType))
         throw new Exception(T("Adding a Regarding event requires a foreign association type."));

      if (is_null($this->ForeignID))
         throw new Exception(T("Adding a Regarding event requires a foreign association id."));

      if (is_null($this->Comment))
         throw new Exception(T("Adding a Regarding event requires a comment."));

      if (is_null($this->UserID))
         $this->UserID = Gdn::Session()->UserID;

      $RegardingModel = new RegardingModel();
      
      $CollapseMode = C('Garden.Regarding.AutoCollapse', TRUE);
      $Collapse = FALSE;
      if ($CollapseMode) {
         // Check for an existing report of this type
         $ExistingRegardingEntity = $RegardingModel->GetRelated($this->Type, $this->ForeignType, $this->ForeignID);
         if ($ExistingRegardingEntity !== FALSE)
            $Collapse = TRUE;
      }
      
      if (!$Collapse) {
         // Create a new Regarding entry
         $RegardingID = $RegardingModel->Save(array(
            'Type'            => $this->Type,
            'ForeignType'     => $this->ForeignType,
            'ForeignID'       => $this->ForeignID,
            'InsertUserID'    => $this->UserID,
            'DateInserted'    => date('Y-m-d H:i:s'),

            'ParentType'      => $this->ParentType,
            'ParentID'        => $this->ParentID,
            'ForeignURL'      => $this->ForeignURL,
            'Comment'         => $this->Comment,
            'OriginalContent' => $this->OriginalContent
         ));
      }
      
      // Handle collaborations
      
      // Don't error on foreach
      if (!is_array($this->CollaborativeActions))
         $this->CollaborativeActions = array();
      
      foreach ($this->CollaborativeActions as $Action) {
         $ActionType = GetValue('Type', $Action);
         switch ($ActionType) {
            case 'discussion':
               $DiscussionModel = new DiscussionModel();
               
               if (!$Collapse) {
                  $CategoryID = GetValue('Parameters', $Action);
               
                  // Make a new discussion
                  $DiscussionID = $DiscussionModel->Save(array(
                     'Name'         => $this->CollaborativeTitle,
                     'CategoryID'   => $CategoryID,
                     'Body'         => $this->OriginalContent,
                     'InsertUserID' => GetValue('InsertUserID', $this->SourceElement),
                     'Announce'     => 0,
                     'Close'        => 0,
                     'RegardingID'  => $RegardingID
                  ));
               } else {
                  // Add a comment to the existing discussion
                  
                  // First, find out which discussion it was, based on RegardingID
                  $Discussion = $DiscussionModel->GetWhere(array('RegardingID' => GetValue('RegardingID', $ExistingRegardingEntity, FALSE)))->FirstRow(DATASET_TYPE_ARRAY);
                  if ($Discussion !== FALSE) {
                     $CommentModel = new CommentModel();
                     $CommentID = $CommentModel->Save(array(
                        'DiscussionID' => GetValue('DiscussionID', $Discussion),
                        'Body'         => $this->Comment,
                        'InsertUserID' => $this->UserID
                     ));
                  }
               }
               
               break;

            case 'conversation':
                  
               $ConversationModel = new ConversationModel();
               $ConversationMessageModel = new ConversationMessageModel();
               
               $Users = GetValue('Parameters', $Action);
               $UserList = explode(',', $Users);
               if (!sizeof($UserList))
                  throw new Exception(sprintf(T("The userlist provided for collaboration on '%s:%s' is invalid.", $this->Type, $this->ForeignType)));
               
               $ConversationID = $ConversationModel->Save(array(
                  'To'              => 'Admins',
                  'Body'            => $this->CollaborativeTitle,
                  'RecipientUserID' => $UserList,
                  'RegardingID'     => $RegardingID
               ), $ConversationMessageModel);
               
               break;
         }
      }

      return TRUE;
   }
Ejemplo n.º 11
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(' ');
        }
Ejemplo n.º 12
0
 /**
  *
  *
  * @return bool
  * @throws Exception
  * @throws Gdn_UserException
  */
 public function commit()
 {
     if (is_null($this->Type)) {
         throw new Exception(T("Adding a Regarding event requires a type."));
     }
     if (is_null($this->ForeignType)) {
         throw new Exception(T("Adding a Regarding event requires a foreign association type."));
     }
     if (is_null($this->ForeignID)) {
         throw new Exception(T("Adding a Regarding event requires a foreign association id."));
     }
     if (is_null($this->Comment)) {
         throw new Exception(T("Adding a Regarding event requires a comment."));
     }
     if (is_null($this->UserID)) {
         $this->UserID = Gdn::session()->UserID;
     }
     $RegardingModel = new RegardingModel();
     $CollapseMode = c('Garden.Regarding.AutoCollapse', true);
     $Collapse = false;
     if ($CollapseMode) {
         // Check for an existing report of this type
         $ExistingRegardingEntity = $RegardingModel->getRelated($this->Type, $this->ForeignType, $this->ForeignID);
         if ($ExistingRegardingEntity) {
             $Collapse = true;
             $RegardingID = val('RegardingID', $ExistingRegardingEntity);
         }
     }
     if (!$Collapse) {
         // Create a new Regarding entry
         $RegardingPreSend = array('Type' => $this->Type, 'ForeignType' => $this->ForeignType, 'ForeignID' => $this->ForeignID, 'InsertUserID' => $this->UserID, 'DateInserted' => date('Y-m-d H:i:s'), 'ParentType' => $this->ParentType, 'ParentID' => $this->ParentID, 'ForeignURL' => $this->ForeignURL, 'Comment' => $this->Comment, 'OriginalContent' => $this->OriginalContent, 'Reports' => 1);
         $RegardingID = $RegardingModel->save($RegardingPreSend);
         if (!$RegardingID) {
             return false;
         }
     }
     // Handle collaborations
     // Don't error on foreach
     if (!is_array($this->CollaborativeActions)) {
         $this->CollaborativeActions = array();
     }
     foreach ($this->CollaborativeActions as $Action) {
         $ActionType = val('Type', $Action);
         switch ($ActionType) {
             case 'discussion':
                 $DiscussionModel = new DiscussionModel();
                 if ($Collapse) {
                     $Discussion = Gdn::SQL()->select('*')->from('Discussion')->where(array('RegardingID' => $RegardingID))->get()->firstRow(DATASET_TYPE_ARRAY);
                 }
                 if (!$Collapse || !$Discussion) {
                     $CategoryID = val('Parameters', $Action);
                     // Make a new discussion
                     $DiscussionID = $DiscussionModel->save(array('Name' => $this->CollaborativeTitle, 'CategoryID' => $CategoryID, 'Body' => $this->OriginalContent, 'InsertUserID' => val('InsertUserID', $this->SourceElement), 'Announce' => 0, 'Close' => 0, 'RegardingID' => $RegardingID));
                     if (!$DiscussionID) {
                         throw new Gdn_UserException($DiscussionModel->Validation->resultsText());
                     }
                     $DiscussionModel->updateDiscussionCount($CategoryID);
                 } else {
                     // Add a comment to the existing discussion.
                     $CommentModel = new CommentModel();
                     $CommentID = $CommentModel->save(array('DiscussionID' => val('DiscussionID', $Discussion), 'Body' => $this->Comment, 'InsertUserID' => $this->UserID));
                     $CommentModel->save2($CommentID, true);
                 }
                 break;
             case 'conversation':
                 $ConversationModel = new ConversationModel();
                 $ConversationMessageModel = new ConversationMessageModel();
                 $Users = val('Parameters', $Action);
                 $UserList = explode(',', $Users);
                 if (!sizeof($UserList)) {
                     throw new Exception(sprintf(T("The userlist provided for collaboration on '%s:%s' is invalid.", $this->Type, $this->ForeignType)));
                 }
                 $ConversationID = $ConversationModel->save(array('To' => 'Admins', 'Body' => $this->CollaborativeTitle, 'RecipientUserID' => $UserList, 'RegardingID' => $RegardingID), $ConversationMessageModel);
                 break;
         }
     }
     return true;
 }
Ejemplo n.º 13
0
if (checkPermission('Conversations.Conversations.Add')) {
    echo anchor(t('New Message'), 'messages/add');
}
echo wrap(t('Inbox'), 'strong');
?>
    </li>
    <?php 
if (count($this->data('Conversations'))) {
    ?>
        <?php 
    foreach ($this->data('Conversations') as $Row) {
        $Subject = '';
        if ($Row['Subject']) {
            $Subject = Gdn_Format::text($Row['Subject']);
        } else {
            $Subject = ConversationModel::participantTitle($Row, false);
        }
        $PhotoUser = userBuilder($Row, 'LastInsert');
        ?>
            <li class="Item" rel="<?php 
        echo url("/messages/{$Row['ConversationID']}#Message_{$Row['LastMessageID']}");
        ?>
">
                <div class="Author Photo"><?php 
        echo userPhoto($PhotoUser);
        ?>
</div>
                <div class="ItemContent">
                    <b class="Subject"><?php 
        echo anchor($Subject, "/messages/{$Row['ConversationID']}#Message_{$Row['LastMessageID']}");
        ?>
Ejemplo n.º 14
0
 /**
  * Add a new message to a conversation.
  *
  * @param MessageController $Sender
  */
 public function MessagesController_BeforeAddMessage_Handler($Sender)
 {
     $ConversationID = $Sender->EventArguments['ConversationID'];
     $ConversationModel = new ConversationModel();
     $Recipients = $ConversationModel->GetRecipients($ConversationID);
     if (!$Recipients->NumRows()) {
         return;
     }
     $Recipients = $Recipients->ResultArray();
     $Recipients = ConsolidateArrayValuesByKey($Recipients, 'UserID');
     $UserID = Gdn::Session()->UserID;
     foreach ($Recipients as $RecipientID => $Recipient) {
         if ($this->Ignored($UserID, $RecipientID)) {
             $Sender->Form->AddError(sprintf(T('Unable to send message, %s is ignoring you.'), $User['Name']));
         }
     }
 }
Ejemplo n.º 15
0
    if ($Conversation->LastFormat == 'Text') {
        $Message = SliceString(Gdn_Format::To($Conversation->LastBody, $Conversation->LastFormat), 100);
    } else {
        $Message = SliceString(Gdn_Format::Text(Gdn_Format::To($Conversation->LastBody, $Conversation->LastFormat), FALSE), 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 = GetValue('Subject', $Conversation)) {
        if ($Names) {
            echo Bullet(' ');
        }