/**
  * action implement
  */
 public function actionImplement($in)
 {
     global $db;
     $result = false;
     switch ($in->data['type']) {
         case 'newtopic':
         case 'sub':
         case 'quote':
         case 'tag':
             $oViewableThreadList = new ViewableThreadList();
             $oViewableThreadList->setObjectIDs(array($in->data['id']));
             $oViewableThreadList->readObjects();
             $result = $oViewableThreadList->getObjects();
             if (sizeof($result) == 1 && isset($result[$in->data['id']])) {
                 $thread = $result[$in->data['id']]->getDecoratedObject();
                 if ($thread->userID == (int) $in->data['authorid']) {
                     $result = true;
                 }
             }
             break;
         case 'conv':
             $oViewableConversationMessageList = new ViewableConversationMessageList();
             $oViewableConversationMessageList->setObjectIDs(array($in->data['id']));
             $oViewableConversationMessageList->readObjects();
             $result = $oViewableConversationMessageList->getObjects();
             if (sizeof($result) == 1 && isset($result[$in->data['id']])) {
                 $pm = $result[$in->data['id']]->getDecoratedObject();
                 if ($pm->userID == (int) $in->data['authorid']) {
                     $result = true;
                 }
             }
             break;
     }
     $this->data = array('result' => $result, 'result_text' => 'fail');
 }
Example #2
0
 /**
  * get topic by topic id
  *
  * @param  Integer  $topicId
  * @return Mixed
  */
 protected function getTopicByTopicId($topicId)
 {
     $oViewableThreadList = new ViewableThreadList();
     $oViewableThreadList->setObjectIDs(array($topicId));
     $oViewableThreadList->readObjects();
     $objsViewableThread = $oViewableThreadList->getObjects();
     if ($objsViewableThread && ($oViewableThread = array_shift($objsViewableThread)) && ($oThread = $oViewableThread->getDecoratedObject()) && $oThread->threadID) {
         return $oThread;
     } else {
         return false;
     }
 }
 /**
  * get forum topic objs
  *
  * @param  Mixed  $var
  * @param  Array  $mbqOpt
  * $mbqOpt['case'] = 'byForum' means get data by forum obj.$var is the forum obj.
  * $mbqOpt['case'] = 'byObjsViewableThread' means get data by objsViewableThread.$var is the objsViewableThread.
  * $mbqOpt['case'] = 'byTopicIds' means get data by topic ids.$var is the ids.
  * $mbqOpt['case'] = 'byAuthor' means get data by author.$var is the MbqEtUser obj.
  * $mbqOpt['case'] = 'subscribed' means get subscribed data.$var is the user id.
  * $mbqOpt['top'] = true means get sticky data.
  * $mbqOpt['notIncludeTop'] = true means get not sticky data.
  * @return  Mixed
  */
 public function getObjsMbqEtForumTopic($var = null, $mbqOpt = array())
 {
     if ($mbqOpt['case'] == 'byForum') {
         $oMbqEtForum = $var;
         if ($mbqOpt['oMbqDataPage']) {
             $oMbqDataPage = $mbqOpt['oMbqDataPage'];
             //ref wbb\page\BoardPage::initObjectList()
             $oBoardThreadList = new BoardThreadList($oMbqEtForum->mbqBind['oDetailedBoardNode']->getBoard(), 1000);
             //!!!
             if (isset($mbqOpt['ann']) && $mbqOpt['ann'] == true) {
                 $oBoardThreadList->sqlOffset = $oMbqDataPage->startNum;
                 $oBoardThreadList->sqlLimit = $oMbqDataPage->numPerPage;
                 $oBoardThreadList->readObjects();
                 $oMbqDataPage->totalNum = $oBoardThreadList->countAnnouncements();
                 $objsViewableThread = array();
                 foreach ($oBoardThreadList->getObjects() as $oViewableThread) {
                     if ($oViewableThread->getDecoratedObject()->isAnnouncement) {
                         //filter the announcement ViewableThread
                         $objsViewableThread[] = $oViewableThread;
                     }
                 }
             } elseif (isset($mbqOpt['top']) && $mbqOpt['top'] == true) {
                 $oBoardThreadList->getConditionBuilder()->add('thread.isSticky = 1');
                 $oBoardThreadList->sqlOffset = $oMbqDataPage->startNum;
                 $oBoardThreadList->sqlLimit = $oMbqDataPage->numPerPage;
                 $oBoardThreadList->readObjects();
                 $oMbqDataPage->totalNum = $oBoardThreadList->countObjects();
                 $objsViewableThread = array();
                 foreach ($oBoardThreadList->getObjects() as $oViewableThread) {
                     if (!$oViewableThread->getDecoratedObject()->isAnnouncement) {
                         //filter the announcement ViewableThread
                         $objsViewableThread[] = $oViewableThread;
                     }
                 }
             } else {
                 $oBoardThreadList->getConditionBuilder()->add('thread.isSticky = 0');
                 $oBoardThreadList->sqlOffset = $oMbqDataPage->startNum;
                 $oBoardThreadList->sqlLimit = $oMbqDataPage->numPerPage;
                 $oBoardThreadList->readObjects();
                 $oMbqDataPage->totalNum = $oBoardThreadList->countObjects();
                 $objsViewableThread = array();
                 foreach ($oBoardThreadList->getObjects() as $oViewableThread) {
                     if (!$oViewableThread->getDecoratedObject()->isAnnouncement) {
                         //filter the announcement ViewableThread
                         $objsViewableThread[] = $oViewableThread;
                     }
                 }
             }
             /* common begin */
             $mbqOpt['case'] = 'byObjsViewableThread';
             $mbqOpt['oMbqDataPage'] = $oMbqDataPage;
             $mbqOpt['originCase'] = 'byForum';
             return $this->getObjsMbqEtForumTopic($objsViewableThread, $mbqOpt);
             /* common end */
         }
     } elseif ($mbqOpt['case'] == 'subscribed') {
         if ($mbqOpt['oMbqDataPage']) {
             $oMbqDataPage = $mbqOpt['oMbqDataPage'];
             $oWatchedThreadList = new WatchedThreadList();
             $oWatchedThreadList->sqlOffset = $oMbqDataPage->startNum;
             $oWatchedThreadList->sqlLimit = $oMbqDataPage->numPerPage;
             $oWatchedThreadList->getConditionBuilder()->add('thread.isAnnouncement = 0');
             //!!!
             $oWatchedThreadList->readObjectIDs();
             $oMbqDataPage->totalNum = $oWatchedThreadList->countObjects();
             /* common begin */
             $mbqOpt['case'] = 'byTopicIds';
             $mbqOpt['oMbqDataPage'] = $oMbqDataPage;
             return $this->getObjsMbqEtForumTopic($oWatchedThreadList->objectIDs, $mbqOpt);
             /* common end */
         }
     } elseif ($mbqOpt['case'] == 'byAuthor') {
         if ($mbqOpt['oMbqDataPage']) {
             $oMbqDataPage = $mbqOpt['oMbqDataPage'];
             $oViewableThreadList = new ViewableThreadList();
             $oViewableThreadList->sqlOffset = $oMbqDataPage->startNum;
             $oViewableThreadList->sqlLimit = $oMbqDataPage->numPerPage;
             $oViewableThreadList->getConditionBuilder()->add('thread.boardID IN (?)', array(MbqMain::$oMbqAppEnv->accessibleBoardIds));
             $oViewableThreadList->getConditionBuilder()->add('thread.userID = ?', array($var->userId->oriValue));
             //!!!
             $oViewableThreadList->getConditionBuilder()->add('thread.isAnnouncement = 0');
             //!!!
             $oViewableThreadList->readObjects();
             $oMbqDataPage->totalNum = $oViewableThreadList->countObjects();
             /* common begin */
             $mbqOpt['case'] = 'byObjsViewableThread';
             $mbqOpt['oMbqDataPage'] = $oMbqDataPage;
             return $this->getObjsMbqEtForumTopic($oViewableThreadList->getObjects(), $mbqOpt);
             /* common end */
         }
     } elseif ($mbqOpt['case'] == 'byTopicIds') {
         //ref wbb\data\thread\ViewableThread::getThread()
         $oViewableThreadList = new ViewableThreadList();
         $oViewableThreadList->setObjectIDs($var);
         $oViewableThreadList->readObjects();
         /* common begin */
         $mbqOpt['case'] = 'byObjsViewableThread';
         return $this->getObjsMbqEtForumTopic($oViewableThreadList->getObjects(), $mbqOpt);
         /* common end */
     } elseif ($mbqOpt['case'] == 'byObjsViewableThread') {
         $objsViewableThread = $var;
         /* common begin */
         $objsMbqEtForumTopic = array();
         $authorUserIds = array();
         $lastReplyUserIds = array();
         $forumIds = array();
         $topicIds = array();
         foreach ($objsViewableThread as $oViewableThread) {
             if ($oViewableThread->getDecoratedObject()->isDisabled && (!WCF::getSession()->getPermission('mod.board.isSuperMod') || !WCF::getSession()->getPermission('mod.board.canEnableThread'))) {
                 continue;
             }
             $objsMbqEtForumTopic[] = $this->initOMbqEtForumTopic($oViewableThread, array('case' => 'oViewableThread'));
         }
         foreach ($objsMbqEtForumTopic as $oMbqEtForumTopic) {
             $authorUserIds[$oMbqEtForumTopic->topicAuthorId->oriValue] = $oMbqEtForumTopic->topicAuthorId->oriValue;
             $lastReplyUserIds[$oMbqEtForumTopic->lastReplyAuthorId->oriValue] = $oMbqEtForumTopic->lastReplyAuthorId->oriValue;
             $forumIds[$oMbqEtForumTopic->forumId->oriValue] = $oMbqEtForumTopic->forumId->oriValue;
             $topicIds[$oMbqEtForumTopic->topicId->oriValue] = $oMbqEtForumTopic->topicId->oriValue;
         }
         //make topicContent and shortContent properties from first post,ref wbb\page\ThreadPage::initObjectList()
         $oMbqRdEtForumPost = MbqMain::$oClk->newObj('MbqRdEtForumPost');
         foreach ($objsMbqEtForumTopic as &$oMbqEtForumTopic) {
             $oThreadPostList = new ThreadPostList($oMbqEtForumTopic->mbqBind['oViewableThread']->getDecoratedObject());
             $oThreadPostList->setObjectIDs(array($oMbqEtForumTopic->mbqBind['oViewableThread']->getDecoratedObject()->firstPostID));
             $oThreadPostList->readObjects();
             foreach ($oThreadPostList->getObjects() as $oViewablePost) {
                 $oMbqEtForumTopic->topicContent->setOriValue($oViewablePost->getDecoratedObject()->getMessage());
                 $oMbqEtForumTopic->oFirstMbqEtForumPost = $oViewablePost;
                 $shortContent = MbqMain::$oMbqCm->getShortContent($oMbqRdEtForumPost->processContentForDisplay($oViewablePost, true));
                 break;
                 //only get the first post
             }
             $oThreadPostList->setObjectIDs(array($oMbqEtForumTopic->mbqBind['oViewableThread']->getDecoratedObject()->lastPostID));
             $oThreadPostList->readObjects();
             foreach ($oThreadPostList->getObjects() as $oViewablePost) {
                 $oMbqEtForumTopic->oLastMbqEtForumPost = $oViewablePost;
                 $oMbqEtForumTopic->shortContent->setOriValue(MbqMain::$oMbqCm->getShortContent($oMbqRdEtForumPost->processContentForDisplay($oViewablePost, true)));
                 break;
                 //only get the lase post
             }
             if (isset($mbqOpt['originCase']) && $mbqOpt['originCase'] == "byForum" && isset($shortContent)) {
                 $oMbqEtForumTopic->shortContent->setOriValue($shortContent);
             }
         }
         /* load oMbqEtForum property */
         $oMbqRdEtForum = MbqMain::$oClk->newObj('MbqRdEtForum');
         $objsMbqEtForum = $oMbqRdEtForum->getObjsMbqEtForum($forumIds, array('case' => 'byForumIds'));
         foreach ($objsMbqEtForum as $oNewMbqEtForum) {
             foreach ($objsMbqEtForumTopic as &$oMbqEtForumTopic) {
                 if ($oNewMbqEtForum->forumId->oriValue == $oMbqEtForumTopic->forumId->oriValue) {
                     $oMbqEtForumTopic->oMbqEtForum = $oNewMbqEtForum;
                 }
             }
         }
         /* load topic author */
         $oMbqRdEtUser = MbqMain::$oClk->newObj('MbqRdEtUser');
         $objsAuthorMbqEtUser = $oMbqRdEtUser->getObjsMbqEtUser($authorUserIds, array('case' => 'byUserIds'));
         foreach ($objsMbqEtForumTopic as &$oMbqEtForumTopic) {
             foreach ($objsAuthorMbqEtUser as $oAuthorMbqEtUser) {
                 if ($oMbqEtForumTopic->topicAuthorId->oriValue == $oAuthorMbqEtUser->userId->oriValue) {
                     $oMbqEtForumTopic->oAuthorMbqEtUser = $oAuthorMbqEtUser;
                     if ($oMbqEtForumTopic->oAuthorMbqEtUser->iconUrl->hasSetOriValue()) {
                         $oMbqEtForumTopic->authorIconUrl->setOriValue($oMbqEtForumTopic->oAuthorMbqEtUser->iconUrl->oriValue);
                     }
                     break;
                 }
             }
         }
         /* load oLastReplyMbqEtUser */
         $objsLastReplyMbqEtUser = $oMbqRdEtUser->getObjsMbqEtUser($lastReplyUserIds, array('case' => 'byUserIds'));
         foreach ($objsMbqEtForumTopic as &$oMbqEtForumTopic) {
             foreach ($objsLastReplyMbqEtUser as $oLastReplyMbqEtUser) {
                 if ($oMbqEtForumTopic->lastReplyAuthorId->oriValue == $oLastReplyMbqEtUser->userId->oriValue) {
                     $oMbqEtForumTopic->oLastReplyMbqEtUser = $oLastReplyMbqEtUser;
                     break;
                 }
             }
         }
         /* make other properties */
         $oMbqAclEtForumPost = MbqMain::$oClk->newObj('MbqAclEtForumPost');
         foreach ($objsMbqEtForumTopic as &$oMbqEtForumTopic) {
             if ($oMbqAclEtForumPost->canAclReplyPost($oMbqEtForumTopic)) {
                 $oMbqEtForumTopic->canReply->setOriValue(MbqBaseFdt::getFdt('MbqFdtForum.MbqEtForumTopic.canReply.range.yes'));
             } else {
                 $oMbqEtForumTopic->canReply->setOriValue(MbqBaseFdt::getFdt('MbqFdtForum.MbqEtForumTopic.canReply.range.no'));
             }
         }
         if (isset($mbqOpt['oMbqDataPage'])) {
             $oMbqDataPage = $mbqOpt['oMbqDataPage'];
             $oMbqDataPage->datas = $objsMbqEtForumTopic;
             return $oMbqDataPage;
         } else {
             return $objsMbqEtForumTopic;
         }
         /* common end */
     }
     MbqError::alert('', __METHOD__ . ',line:' . __LINE__ . '.' . MBQ_ERR_INFO_UNKNOWN_CASE);
 }