/**
  * @see \wcf\system\jcoins\shop\item\type\IShopItem::buy()
  */
 public function buy(array $paramters)
 {
     parent::buy($paramters);
     $paramters = $this->prepare($paramters);
     $data = array('userID' => WCF::getSession()->userID, 'username' => WCF::getSession()->getUser()->username, 'time' => TIME_NOW, 'isDraft' => 0, 'participantCanInvite' => 0, 'subject' => $paramters['subject']);
     $messageData = array('message' => $paramters['text'], 'enableBBCodes' => 1, 'enableHtml' => 0, 'enableSmilies' => 1, 'showSignature' => 1);
     $conversationData = array('data' => $data, 'messageData' => $messageData, 'participants' => array($paramters['userid']));
     $action = new ConversationAction(array(), 'create', $conversationData);
     $conversation = $action->executeAction();
     if ($paramters['close'] == 1) {
         $action = new ConversationAction(array($conversation['returnValues']), 'close', array());
         $action->executeAction();
     }
 }
 /**
  * Rebuilds the conversation data of the relevant conversations.
  */
 public function rebuild()
 {
     if (empty($this->objects)) {
         $this->readObjects();
     }
     // collect number of messages for each conversation
     $conditionBuilder = new PreparedStatementConditionBuilder();
     $conditionBuilder->add('conversation_message.conversationID IN (?)', array($this->objectIDs));
     $sql = "SELECT\t\tconversationID, COUNT(messageID) AS messages, SUM(attachments) AS attachments\n\t\t\tFROM\t\twcf" . WCF_N . "_conversation_message conversation_message\n\t\t\t" . $conditionBuilder . "\n\t\t\tGROUP BY\tconversationID";
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditionBuilder->getParameters());
     $objectIDs = array();
     while ($row = $statement->fetchArray()) {
         if (!$row['messages']) {
             continue;
         }
         $objectIDs[] = $row['conversationID'];
         $conversationEditor = new ConversationEditor(new Conversation(null, array('conversationID' => $row['conversationID'])));
         $conversationEditor->update(array('attachments' => $row['attachments'], 'replies' => $row['messages'] - 1));
         $conversationEditor->updateFirstMessage();
         $conversationEditor->updateLastMessage();
     }
     // delete conversations without messages
     $deleteConversationIDs = array_diff($this->objectIDs, $objectIDs);
     if (!empty($deleteConversationIDs)) {
         $conversationAction = new ConversationAction($deleteConversationIDs, 'delete');
         $conversationAction->executeAction();
     }
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     $this->objectList->getConditionBuilder()->add('conversation.conversationID BETWEEN ? AND ?', array($this->limit * $this->loopCount + 1, $this->limit * $this->loopCount + $this->limit));
     parent::execute();
     // prepare statements
     $sql = "SELECT\t\tmessageID, time, userID, username\n\t\t\tFROM\t\twcf" . WCF_N . "_conversation_message\n\t\t\tWHERE\t\tconversationID = ?\n\t\t\tORDER BY\ttime";
     $firstMessageStatement = WCF::getDB()->prepareStatement($sql, 1);
     $sql = "SELECT\t\ttime, userID, username\n\t\t\tFROM\t\twcf" . WCF_N . "_conversation_message\n\t\t\tWHERE\t\tconversationID = ?\n\t\t\tORDER BY\ttime DESC";
     $lastMessageStatement = WCF::getDB()->prepareStatement($sql, 1);
     $sql = "SELECT\tCOUNT(*) AS messages,\n\t\t\t\tSUM(attachments) AS attachments\n\t\t\tFROM\twcf" . WCF_N . "_conversation_message\n\t\t\tWHERE\tconversationID = ?";
     $statsStatement = WCF::getDB()->prepareStatement($sql);
     $sql = "SELECT\tCOUNT(*) AS participants\n\t\t\tFROM\twcf" . WCF_N . "_conversation_to_user conversation_to_user\n\t\t\tWHERE\tconversation_to_user.conversationID = ?\n\t\t\t\tAND conversation_to_user.hideConversation <> ?\n\t\t\t\tAND conversation_to_user.participantID <> ?\n\t\t\t\tAND conversation_to_user.isInvisible = ?";
     $participantCounterStatement = WCF::getDB()->prepareStatement($sql);
     $sql = "SELECT\t\tconversation_to_user.participantID AS userID, conversation_to_user.hideConversation, user_table.username\n\t\t\tFROM\t\twcf" . WCF_N . "_conversation_to_user conversation_to_user\n\t\t\tLEFT JOIN\twcf" . WCF_N . "_user user_table\n\t\t\tON\t\t(user_table.userID = conversation_to_user.participantID)\n\t\t\tWHERE\t\tconversation_to_user.conversationID = ?\n\t\t\t\t\tAND conversation_to_user.participantID <> ?\n\t\t\t\t\tAND conversation_to_user.isInvisible = ?\n\t\t\tORDER BY\tuser_table.username";
     $participantStatement = WCF::getDB()->prepareStatement($sql, 5);
     $sql = "SELECT\tCOUNT(*) AS participants\n\t\t\tFROM\twcf" . WCF_N . "_conversation_to_user\n\t\t\tWHERE\tconversationID = ?\n\t\t\t\tAND participantID IS NOT NULL";
     $existingParticipantStatement = WCF::getDB()->prepareStatement($sql, 5);
     $obsoleteConversations = array();
     foreach ($this->objectList as $conversation) {
         $editor = new ConversationEditor($conversation);
         // check for obsolete conversations
         $obsolete = false;
         if ($conversation->isDraft) {
             if (!$conversation->userID) {
                 $obsolete = true;
             }
         } else {
             $existingParticipantStatement->execute(array($conversation->conversationID));
             $row = $existingParticipantStatement->fetchSingleRow();
             if (!$row['participants']) {
                 $obsolete = true;
             }
         }
         if ($obsolete) {
             $obsoleteConversations[] = $editor;
             continue;
         }
         // update data
         $data = array();
         // get first post
         $firstMessageStatement->execute(array($conversation->conversationID));
         if (($row = $firstMessageStatement->fetchSingleRow()) !== false) {
             $data['firstMessageID'] = $row['messageID'];
             $data['lastPostTime'] = $data['time'] = $row['time'];
             $data['userID'] = $row['userID'];
             $data['username'] = $row['username'];
         }
         // get last post
         $lastMessageStatement->execute(array($conversation->conversationID));
         if (($row = $lastMessageStatement->fetchSingleRow()) !== false) {
             $data['lastPostTime'] = $row['time'];
             $data['lastPosterID'] = $row['userID'];
             $data['lastPoster'] = $row['username'];
         }
         // get stats
         $statsStatement->execute(array($conversation->conversationID));
         $row = $statsStatement->fetchSingleRow();
         $data['replies'] = $row['messages'] ? $row['messages'] - 1 : 0;
         $data['attachments'] = $row['attachments'] ?: 0;
         // get number of participants
         $participantCounterStatement->execute(array($conversation->conversationID, Conversation::STATE_LEFT, $conversation->userID, 0));
         $row = $participantCounterStatement->fetchSingleRow();
         $data['participants'] = $row['participants'];
         // get participant summary
         $participantStatement->execute(array($conversation->conversationID, $conversation->userID, 0));
         $users = array();
         while ($row = $participantStatement->fetchArray()) {
             $users[] = $row;
         }
         $data['participantSummary'] = serialize($users);
         $editor->update($data);
     }
     // delete obsolete conversations
     if (!empty($obsoleteConversations)) {
         $action = new ConversationAction($obsoleteConversations, 'delete');
         $action->executeAction();
     }
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     MessageForm::save();
     // save message
     $data = array_merge($this->additionalFields, array('message' => $this->text, 'enableBBCodes' => $this->enableBBCodes, 'enableHtml' => $this->enableHtml, 'enableSmilies' => $this->enableSmilies, 'showSignature' => $this->showSignature));
     if ($this->conversation->isDraft && !$this->draft) {
         $data['time'] = TIME_NOW;
     }
     if (!$this->draft) {
         $data['lastEditTime'] = TIME_NOW;
         $data['editCount'] = $this->message->editCount + 1;
     }
     $messageData = array('data' => $data, 'attachmentHandler' => $this->attachmentHandler);
     $this->objectAction = new ConversationMessageAction(array($this->message), 'update', $messageData);
     $this->objectAction->executeAction();
     // update conversation
     if ($this->isFirstMessage) {
         $data = array('subject' => $this->subject, 'isDraft' => $this->draft ? 1 : 0, 'participantCanInvite' => $this->participantCanInvite);
         if ($this->draft) {
             $data['draftData'] = serialize(array('participants' => $this->participantIDs, 'invisibleParticipants' => $this->invisibleParticipantIDs));
         }
         $conversationData = array('data' => $data);
         if ($this->conversation->isDraft && !$this->draft) {
             $conversationData['participants'] = $this->participantIDs;
             $conversationData['invisibleParticipants'] = $this->invisibleParticipantIDs;
             $conversationData['data']['time'] = $conversationData['data']['lastPostTime'] = TIME_NOW;
         }
         $conversationAction = new ConversationAction(array($this->conversation), 'update', $conversationData);
         $conversationAction->executeAction();
     }
     $this->saved();
     // forward
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('Conversation', array('object' => $this->conversation, 'messageID' => $this->messageID)) . '#message' . $this->messageID);
     exit;
 }
Exemple #5
0
 /**
  * get private conversation message objs
  *
  * @param  Mixed  $var
  * @param  Array  $mbqOpt
  * $mbqOpt['case'] = 'byPc' means get data by private conversation obj.$var is the private conversation obj.
  * $mbqOpt['case'] = 'byMsgIds' means get data by conversation message ids.$var is the ids.
  * $mbqOpt['case'] = 'byObjsViewableConversationMessage' means get data by objsViewableConversationMessage.$var is the objsViewableConversationMessage.
  * @return  Mixed
  */
 public function getObjsMbqEtPcMsg($var, $mbqOpt)
 {
     if ($mbqOpt['case'] == 'byPc') {
         $oMbqEtPc = $var;
         if ($mbqOpt['oMbqDataPage']) {
             $oMbqDataPage = $mbqOpt['oMbqDataPage'];
             $oViewableConversation = $var->mbqBind['oViewableConversation'];
             $oConversation = $var->mbqBind['oViewableConversation']->getDecoratedObject();
             $oViewableConversationMessageList = new ViewableConversationMessageList();
             $oViewableConversationMessageList->sqlOffset = $oMbqDataPage->startNum;
             $oViewableConversationMessageList->sqlLimit = $oMbqDataPage->numPerPage;
             //ref wcf\page\ConversationPage::initObjectList()
             $oViewableConversationMessageList->getConditionBuilder()->add('conversation_message.conversationID = ?', array($var->convId->oriValue));
             $oViewableConversationMessageList->readObjects();
             $oMbqDataPage->totalNum = $oViewableConversationMessageList->countObjects();
             //mark read,ref wcf\page\ConversationPage::readData()
             // update last visit time count
             if ($oViewableConversation->isNew() && $oViewableConversationMessageList->getMaxPostTime() > $oViewableConversation->lastVisitTime) {
                 $visitTime = $oViewableConversationMessageList->getMaxPostTime();
                 if ($visitTime == $oViewableConversation->lastPostTime) {
                     $visitTime = TIME_NOW;
                 }
                 $conversationAction = new ConversationAction(array($oViewableConversation->getDecoratedObject()), 'markAsRead', array('visitTime' => $visitTime));
                 $conversationAction->executeAction();
             }
             /* common begin */
             $mbqOpt['case'] = 'byObjsViewableConversationMessage';
             $mbqOpt['oMbqDataPage'] = $oMbqDataPage;
             return $this->getObjsMbqEtPcMsg($oViewableConversationMessageList->getObjects(), $mbqOpt);
             /* common end */
         }
     } elseif ($mbqOpt['case'] == 'byMsgIds') {
         $oViewableConversationMessageList = new ViewableConversationMessageList();
         $oViewableConversationMessageList->setObjectIDs($var);
         $oViewableConversationMessageList->readObjects();
         /* common begin */
         $mbqOpt['case'] = 'byObjsViewableConversationMessage';
         return $this->getObjsMbqEtPcMsg($oViewableConversationMessageList->getObjects(), $mbqOpt);
         /* common end */
     } elseif ($mbqOpt['case'] == 'byObjsViewableConversationMessage') {
         $objsViewableConversationMessage = $var;
         /* common begin */
         $objsMbqEtPcMsg = array();
         $authorUserIds = array();
         foreach ($objsViewableConversationMessage as $oViewableConversationMessage) {
             $authorUserIds[] = $oViewableConversationMessage->getDecoratedObject()->userID;
             $objsMbqEtPcMsg[] = $this->initOMbqEtPcMsg($oViewableConversationMessage, array('case' => 'oViewableConversationMessage'));
         }
         /* load oAuthorMbqEtUser property */
         $oMbqRdEtUser = MbqMain::$oClk->newObj('MbqRdEtUser');
         $objsAuthorMbqEtUser = $oMbqRdEtUser->getObjsMbqEtUser($authorUserIds, array('case' => 'byUserIds'));
         foreach ($objsMbqEtPcMsg as &$oMbqEtPcMsg) {
             foreach ($objsAuthorMbqEtUser as $oAuthorMbqEtUser) {
                 if ($oMbqEtPcMsg->msgAuthorId->oriValue == $oAuthorMbqEtUser->userId->oriValue) {
                     $oMbqEtPcMsg->oAuthorMbqEtUser = $oAuthorMbqEtUser;
                     break;
                 }
             }
         }
         /* load attachment */
         $oMbqRdEtAtt = MbqMain::$oClk->newObj('MbqRdEtAtt');
         foreach ($objsMbqEtPcMsg as &$oMbqEtPcMsg) {
             if ($attachmentList = $oMbqEtPcMsg->mbqBind['oViewableConversationMessage']->getDecoratedObject()->getAttachments()) {
                 foreach ($attachmentList->getObjects() as $oAttachment) {
                     $oMbqEtPcMsg->objsMbqEtAtt[] = $oMbqRdEtAtt->initOMbqEtAtt($oAttachment, array('case' => 'oAttachment'));
                 }
             }
         }
         /* load objsNotInContentMbqEtAtt */
         foreach ($objsMbqEtPcMsg as &$oMbqEtPcMsg) {
             $filedataids = MbqMain::$oMbqCm->getAttIdsFromContent($oMbqEtPcMsg->msgContent->oriValue);
             foreach ($oMbqEtPcMsg->objsMbqEtAtt as $oMbqEtAtt) {
                 if (!in_array($oMbqEtAtt->attId->oriValue, $filedataids)) {
                     $oMbqEtPcMsg->objsNotInContentMbqEtAtt[] = $oMbqEtAtt;
                 }
             }
         }
         /* common end */
         if ($mbqOpt['oMbqDataPage']) {
             $oMbqDataPage = $mbqOpt['oMbqDataPage'];
             $oMbqDataPage->datas = $objsMbqEtPcMsg;
             return $oMbqDataPage;
         } else {
             return $objsMbqEtPcMsg;
         }
     }
     MbqError::alert('', __METHOD__ . ',line:' . __LINE__ . '.' . MBQ_ERR_INFO_UNKNOWN_CASE);
 }
 /**
  * @see	\wcf\data\AbstractDatabaseObjectAction::delete()
  */
 public function delete()
 {
     $count = parent::delete();
     $attachmentMessageIDs = $conversationIDs = array();
     foreach ($this->objects as $message) {
         if (!in_array($message->conversationID, $conversationIDs)) {
             $conversationIDs[] = $message->conversationID;
         }
         if ($message->attachments) {
             $attachmentMessageIDs[] = $message->messageID;
         }
     }
     // rebuild conversations
     if (!empty($conversationIDs)) {
         $conversationAction = new ConversationAction($conversationIDs, 'rebuild');
         $conversationAction->executeAction();
     }
     if (!empty($this->objectIDs)) {
         // delete notifications
         UserNotificationHandler::getInstance()->deleteNotifications('conversationMessage', 'com.woltlab.wcf.conversation.message.notification', array(), $this->objectIDs);
         // update search index
         SearchIndexManager::getInstance()->delete('com.woltlab.wcf.conversation.message', $this->objectIDs);
         // update embedded objects
         MessageEmbeddedObjectManager::getInstance()->removeObjects('com.woltlab.wcf.conversation.message', $this->objectIDs);
         // remove moderation queues
         ModerationQueueManager::getInstance()->removeQueues('com.woltlab.wcf.conversation.message', $this->objectIDs);
     }
     // remove attachments
     if (!empty($attachmentMessageIDs)) {
         AttachmentHandler::removeAttachments('com.woltlab.wcf.conversation.message', $attachmentMessageIDs);
     }
     return $count;
 }
Exemple #7
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();
         }
     }
 }
 /**
  * @see	\wcf\page\IPage::readData()
  */
 public function readData()
 {
     parent::readData();
     // add breadcrumbs
     WCF::getBreadcrumbs()->add(new Breadcrumb(WCF::getLanguage()->get('wcf.conversation.conversations'), LinkHandler::getInstance()->getLink('ConversationList')));
     if ($this->conversation->isDraft) {
         WCF::getBreadcrumbs()->add(new Breadcrumb(WCF::getLanguage()->get('wcf.conversation.folder.draft'), LinkHandler::getInstance()->getLink('ConversationList', array('filter' => 'draft'))));
     }
     // update last visit time count
     if ($this->conversation->isNew() && $this->objectList->getMaxPostTime() > $this->conversation->lastVisitTime) {
         $visitTime = $this->objectList->getMaxPostTime();
         if ($visitTime == $this->conversation->lastPostTime) {
             $visitTime = TIME_NOW;
         }
         $conversationAction = new ConversationAction(array($this->conversation->getDecoratedObject()), 'markAsRead', array('visitTime' => $visitTime));
         $conversationAction->executeAction();
     }
     // get participants
     $this->participantList = new ConversationParticipantList($this->conversationID, WCF::getUser()->userID, $this->conversation->userID == WCF::getUser()->userID);
     $this->participantList->readObjects();
     // init quote objects
     $messageIDs = array();
     foreach ($this->objectList as $message) {
         $messageIDs[] = $message->messageID;
     }
     MessageQuoteManager::getInstance()->initObjects('com.woltlab.wcf.conversation.message', $messageIDs);
     // set attachment permissions
     if ($this->objectList->getAttachmentList() !== null) {
         $this->objectList->getAttachmentList()->setPermissions(array('canDownload' => true, 'canViewPreview' => true));
     }
     // get timeframe for modifications
     $this->objectList->rewind();
     $startTime = $this->objectList->current()->time;
     $count = count($this->objectList);
     if ($count == 1) {
         $endTime = $startTime;
     } else {
         $this->objectList->seek($count - 1);
         $endTime = $this->objectList->current()->time;
     }
     $this->objectList->rewind();
     // load modification log entries
     $this->modificationLogList = new ConversationLogModificationLogList();
     $this->modificationLogList->setConversation($this->conversation->getDecoratedObject());
     $this->modificationLogList->getConditionBuilder()->add("modification_log.time BETWEEN ? AND ?", array($startTime, $endTime));
     $this->modificationLogList->readObjects();
 }