/**
  * Hides or restores conversations.
  * 
  * @return	array
  */
 public function hideConversation()
 {
     $sql = "UPDATE\twcf" . WCF_N . "_conversation_to_user\n\t\t\tSET\thideConversation = ?\n\t\t\tWHERE\tconversationID = ?\n\t\t\t\tAND participantID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     WCF::getDB()->beginTransaction();
     foreach ($this->objectIDs as $conversationID) {
         $statement->execute(array($this->parameters['hideConversation'], $conversationID, WCF::getUser()->userID));
     }
     WCF::getDB()->commitTransaction();
     // reset user's conversation counters if user leaves conversation
     // permanently
     if ($this->parameters['hideConversation'] == Conversation::STATE_LEFT) {
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'conversationCount');
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'unreadConversationCount');
     }
     // add modification log entry
     if ($this->parameters['hideConversation'] == Conversation::STATE_LEFT) {
         if (empty($this->objects)) {
             $this->readObjects();
         }
         foreach ($this->objects as $conversation) {
             ConversationModificationLogHandler::getInstance()->leave($conversation->getDecoratedObject());
         }
     }
     // unmark items
     $this->unmarkItems();
     if ($this->parameters['hideConversation'] == Conversation::STATE_LEFT) {
         // update participants count and participant summary
         ConversationEditor::updateParticipantCounts($this->objectIDs);
         ConversationEditor::updateParticipantSummaries($this->objectIDs);
         // delete conversation if all users have left it
         $conditionBuilder = new PreparedStatementConditionBuilder();
         $conditionBuilder->add('conversation.conversationID IN (?)', array($this->objectIDs));
         $conditionBuilder->add('conversation_to_user.conversationID IS NULL');
         $conversationIDs = array();
         $sql = "SELECT\t\tDISTINCT conversation.conversationID\n\t\t\t\tFROM\t\twcf" . WCF_N . "_conversation conversation\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_conversation_to_user conversation_to_user\n\t\t\t\tON\t\t(\tconversation_to_user.conversationID = conversation.conversationID\n\t\t\t\t\t\tAND\tconversation_to_user.hideConversation <> " . Conversation::STATE_LEFT . "\n\t\t\t\t\t\tAND\tconversation_to_user.participantID IS NOT NULL)\n\t\t\t\t" . $conditionBuilder;
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute($conditionBuilder->getParameters());
         while ($row = $statement->fetchArray()) {
             $conversationIDs[] = $row['conversationID'];
         }
         if (!empty($conversationIDs)) {
             $action = new ConversationAction($conversationIDs, 'delete');
             $action->executeAction();
         }
     }
     return array('actionName' => 'hideConversation', 'redirectURL' => LinkHandler::getInstance()->getLink('ConversationList'));
 }
示例#2
0
 /**
  * delete conversation
  *
  * @param  Object  $oMbqEtPc
  * @param  Integer  $mode
  */
 public function deleteConversation($oMbqEtPc = null, $mode = null)
 {
     $oConversation = $oMbqEtPc->mbqBind['oViewableConversation']->getDecoratedObject();
     $conversationEditor = new ConversationEditor($oConversation);
     if ($mode == 1) {
         $hideConversation = Conversation::STATE_HIDDEN;
     } elseif ($mode == 2) {
         $hideConversation = Conversation::STATE_LEFT;
     } else {
         MbqError::alert('', 'Need valid mode.', '', MBQ_ERR_APP);
     }
     $objectIDs = array($oMbqEtPc->convId->oriValue);
     //ref wcf\data\conversation\ConversationAction::hideConversation()
     $sql = "UPDATE\twcf" . WCF_N . "_conversation_to_user\r\n\t\t\tSET\thideConversation = ?\r\n\t\t\tWHERE\tconversationID = ?\r\n\t\t\t\tAND participantID = ?";
     $statement = WCF::getDB()->prepareStatement($sql);
     WCF::getDB()->beginTransaction();
     foreach ($objectIDs as $conversationID) {
         $statement->execute(array($hideConversation, $conversationID, WCF::getUser()->userID));
     }
     WCF::getDB()->commitTransaction();
     // reset user's conversation counters if user leaves conversation
     // permanently
     if ($hideConversation == Conversation::STATE_LEFT) {
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'conversationCount');
         UserStorageHandler::getInstance()->reset(array(WCF::getUser()->userID), 'unreadConversationCount');
     }
     // add modification log entry
     if ($hideConversation == Conversation::STATE_LEFT) {
         ConversationModificationLogHandler::getInstance()->leave($conversationEditor->getDecoratedObject());
     }
     // unmark items
     ClipboardHandler::getInstance()->unmark($objectIDs, ClipboardHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.conversation.conversation'));
     if ($hideConversation == Conversation::STATE_LEFT) {
         // update participant summary
         ConversationEditor::updateParticipantSummaries($objectIDs);
         // delete conversation if all users have left it
         $conditionBuilder = new PreparedStatementConditionBuilder();
         $conditionBuilder->add('conversation.conversationID IN (?)', array($objectIDs));
         $conditionBuilder->add('conversation_to_user.conversationID IS NULL');
         $conversationIDs = array();
         $sql = "SELECT\t\tDISTINCT conversation.conversationID\r\n\t\t\t\tFROM\t\twcf" . WCF_N . "_conversation conversation\r\n\t\t\t\tLEFT JOIN\twcf" . WCF_N . "_conversation_to_user conversation_to_user\r\n\t\t\t\tON\t\t(conversation_to_user.conversationID = conversation.conversationID AND conversation_to_user.hideConversation <> " . Conversation::STATE_LEFT . ")\r\n\t\t\t\t" . $conditionBuilder;
         $statement = WCF::getDB()->prepareStatement($sql);
         $statement->execute($conditionBuilder->getParameters());
         while ($row = $statement->fetchArray()) {
             $conversationIDs[] = $row['conversationID'];
         }
         if (!empty($conversationIDs)) {
             $action = new ConversationAction($conversationIDs, 'delete');
             $action->executeAction();
         }
     }
 }