/**
  * @see	\wcf\data\IMessageQuickReplyAction::getMessageList()
  */
 public function getMessageList(DatabaseObject $conversation, $lastMessageTime)
 {
     $messageList = new ViewableConversationMessageList();
     $messageList->setConversation($conversation);
     $messageList->getConditionBuilder()->add("conversation_message.conversationID = ?", array($conversation->conversationID));
     $messageList->getConditionBuilder()->add("conversation_message.time > ?", array($lastMessageTime));
     $messageList->sqlOrderBy = "conversation_message.time " . CONVERSATION_LIST_DEFAULT_SORT_ORDER;
     $messageList->readObjects();
     return $messageList;
 }
Beispiel #2
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);
 }
 /**
  * get conversation message position
  *
  * @param  Object  $oConversationMessage
  *
  * @return  Integer
  */
 protected function getPcMsgPosition($oConversationMessage)
 {
     //refer MbqRdEtPcMsg::getObjsMbqEtPcMsg, $mbqOpt['case'] == 'byPc'
     $oViewableConversationMessageList = new ViewableConversationMessageList();
     $oViewableConversationMessageList->sqlOffset = 0;
     $oViewableConversationMessageList->sqlLimit = 1000000;
     //get all the conversation message to use
     $oViewableConversationMessageList->getConditionBuilder()->add('conversation_message.conversationID = ?', array($oConversationMessage->conversationID));
     $oViewableConversationMessageList->readObjects();
     $objsViewableConversationMessage = $oViewableConversationMessageList->getObjects();
     $ret = 1;
     foreach ($objsViewableConversationMessage as $oViewableConversationMessage) {
         if ($oViewableConversationMessage->getDecoratedObject()->messageID == $oConversationMessage->messageID) {
             return $ret;
         }
         $ret++;
     }
     //not found
     return 1;
 }