Ejemplo n.º 1
0
 /**
  * get forum post objs
  *
  * @param  Mixed  $var
  * @param  Array  $mbqOpt
  * $mbqOpt['case'] = 'byTopic' means get data by forum topic obj.$var is the forum topic obj.
  * $mbqOpt['case'] = 'byPostIds' means get data by post ids.$var is the ids.
  * $mbqOpt['case'] = 'byObjsViewablePost' means get data by objsViewablePost.$var is the objsViewablePost.
  * $mbqOpt['case'] = 'byReplyUser' means get data by reply user.$var is the MbqEtUser obj.
  * $mbqOpt['notGetAttachment'] = true means do not get attachment of forum post.
  * @return  Mixed
  */
 public function getObjsMbqEtForumPost($var = null, $mbqOpt = array())
 {
     if ($mbqOpt['case'] == 'byTopic') {
         $oMbqEtForumTopic = $var;
         if ($mbqOpt['oMbqDataPage']) {
             $oMbqDataPage = $mbqOpt['oMbqDataPage'];
             //ref wbb\page\ThreadPage::initObjectList()
             $oThreadPostList = new ThreadPostList($var->mbqBind['oViewableThread']->getDecoratedObject());
             $oThreadPostList->sqlOffset = $oMbqDataPage->startNum;
             $oThreadPostList->sqlLimit = $oMbqDataPage->numPerPage;
             $oThreadPostList->readObjects();
             $oMbqDataPage->totalNum = $oThreadPostList->countObjects();
             /* common begin */
             $mbqOpt['case'] = 'byObjsViewablePost';
             $mbqOpt['oMbqDataPage'] = $oMbqDataPage;
             return $this->getObjsMbqEtForumPost($oThreadPostList->getObjects(), $mbqOpt);
             /* common end */
         }
     } elseif ($mbqOpt['case'] == 'byPostIds') {
         $objsViewablePost = array();
         $oViewablePostList = new ViewablePostList();
         $oViewablePostList->setObjectIDs($var);
         $oViewablePostList->readObjects();
         /* common begin */
         $mbqOpt['case'] = 'byObjsViewablePost';
         return $this->getObjsMbqEtForumPost($oViewablePostList->getObjects(), $mbqOpt);
         /* common end */
     } elseif ($mbqOpt['case'] == 'byReplyUser') {
         if ($mbqOpt['oMbqDataPage']) {
             $oMbqDataPage = $mbqOpt['oMbqDataPage'];
             $oViewablePostList = new ViewablePostList();
             $oViewablePostList->sqlJoins .= 'INNER JOIN wbb' . WCF_N . '_thread thread ON (post.threadID = thread.threadID AND thread.isAnnouncement = 0 AND post.postID != thread.firstPostID)';
             //!!!
             $oViewablePostList->getConditionBuilder()->add('post.userID = ?', array($var->userId->oriValue));
             $oViewablePostList->readObjects();
             $oMbqDataPage->totalNum = $oViewablePostList->countObjects();
             /* common begin */
             $mbqOpt['case'] = 'byObjsViewablePost';
             $mbqOpt['oMbqDataPage'] = $oMbqDataPage;
             return $this->getObjsMbqEtForumPost($oViewablePostList->getObjects(), $mbqOpt);
             /* common end */
         }
     } elseif ($mbqOpt['case'] == 'byObjsViewablePost') {
         $objsViewablePost = $var;
         /* common begin */
         $objsMbqEtForumPost = array();
         $authorUserIds = array();
         $topicIds = array();
         foreach ($objsViewablePost as $oViewablePost) {
             $objsMbqEtForumPost[] = $this->initOMbqEtForumPost($oViewablePost, array('case' => 'oViewablePost'));
         }
         foreach ($objsMbqEtForumPost as $oMbqEtForumPost) {
             $authorUserIds[$oMbqEtForumPost->postAuthorId->oriValue] = $oMbqEtForumPost->postAuthorId->oriValue;
             //$topicIds[$oMbqEtForumPost->topicId->oriValue] = $oMbqEtForumPost->topicId->oriValue;
             //must use empty array key,otherwise can cause wbb systemException error when doing the following call:$oMbqRdEtForumTopic->getObjsMbqEtForumTopic($topicIds, array('case' => 'byTopicIds'));
             $topicIds[] = $oMbqEtForumPost->topicId->oriValue;
         }
         /* load oMbqEtForumTopic property and oMbqEtForum property */
         $oMbqRdEtForumTopic = MbqMain::$oClk->newObj('MbqRdEtForumTopic');
         $objsMbqEtFroumTopic = $oMbqRdEtForumTopic->getObjsMbqEtForumTopic($topicIds, array('case' => 'byTopicIds'));
         foreach ($objsMbqEtFroumTopic as $oNewMbqEtFroumTopic) {
             foreach ($objsMbqEtForumPost as &$oMbqEtForumPost) {
                 if ($oNewMbqEtFroumTopic->topicId->oriValue == $oMbqEtForumPost->topicId->oriValue) {
                     $oMbqEtForumPost->oMbqEtForumTopic = $oNewMbqEtFroumTopic;
                     if ($oMbqEtForumPost->oMbqEtForumTopic->oMbqEtForum) {
                         $oMbqEtForumPost->oMbqEtForum = $oMbqEtForumPost->oMbqEtForumTopic->oMbqEtForum;
                     }
                 }
             }
         }
         /* load post author */
         $oMbqRdEtUser = MbqMain::$oClk->newObj('MbqRdEtUser');
         $objsAuthorMbqEtUser = $oMbqRdEtUser->getObjsMbqEtUser($authorUserIds, array('case' => 'byUserIds'));
         $postIds = array();
         foreach ($objsMbqEtForumPost as &$oMbqEtForumPost) {
             $postIds[] = $oMbqEtForumPost->postId->oriValue;
             foreach ($objsAuthorMbqEtUser as $oAuthorMbqEtUser) {
                 if ($oMbqEtForumPost->postAuthorId->oriValue == $oAuthorMbqEtUser->userId->oriValue) {
                     $oMbqEtForumPost->oAuthorMbqEtUser = $oAuthorMbqEtUser;
                     if ($oMbqEtForumPost->oAuthorMbqEtUser->isOnline->hasSetOriValue()) {
                         $oMbqEtForumPost->isOnline->setOriValue($oMbqEtForumPost->oAuthorMbqEtUser->isOnline->oriValue ? MbqBaseFdt::getFdt('MbqFdtForum.MbqEtForumPost.isOnline.range.yes') : MbqBaseFdt::getFdt('MbqFdtForum.MbqEtForumPost.isOnline.range.no'));
                     }
                     if ($oMbqEtForumPost->oAuthorMbqEtUser->iconUrl->hasSetOriValue()) {
                         $oMbqEtForumPost->authorIconUrl->setOriValue($oMbqEtForumPost->oAuthorMbqEtUser->iconUrl->oriValue);
                     }
                     break;
                 }
             }
         }
         /* load attachment */
         $oMbqRdEtAtt = MbqMain::$oClk->newObj('MbqRdEtAtt');
         if (!isset($mbqOpt['notGetAttachment'])) {
             $objsMbqEtAtt = $oMbqRdEtAtt->getObjsMbqEtAtt($postIds, array('case' => 'byForumPostIds'));
             foreach ($objsMbqEtAtt as $oMbqEtAtt) {
                 foreach ($objsMbqEtForumPost as &$oMbqEtForumPost) {
                     if ($oMbqEtForumPost->postId->oriValue == $oMbqEtAtt->postId->oriValue) {
                         $oMbqEtForumPost->objsMbqEtAtt[] = $oMbqEtAtt;
                     }
                 }
             }
         }
         /* load objsNotInContentMbqEtAtt */
         if (!isset($mbqOpt['notGetAttachment'])) {
             foreach ($objsMbqEtForumPost as &$oMbqEtForumPost) {
                 $filedataids = MbqMain::$oMbqCm->getAttIdsFromContent($oMbqEtForumPost->postContent->oriValue);
                 foreach ($oMbqEtForumPost->objsMbqEtAtt as $oMbqEtAtt) {
                     if (!in_array($oMbqEtAtt->attId->oriValue, $filedataids)) {
                         $oMbqEtForumPost->objsNotInContentMbqEtAtt[] = $oMbqEtAtt;
                     }
                 }
             }
         }
         /* load objsMbqEtThank property and make related properties/flags */
         //
         /* make other properties */
         $oMbqAclEtForumPost = MbqMain::$oClk->newObj('MbqAclEtForumPost');
         foreach ($objsMbqEtForumPost as &$oMbqEtForumPost) {
             if ($oMbqAclEtForumPost->canAclSaveRawPost($oMbqEtForumPost)) {
                 $oMbqEtForumPost->canEdit->setOriValue(MbqBaseFdt::getFdt('MbqFdtForum.MbqEtForumPost.canEdit.range.yes'));
             } else {
                 $oMbqEtForumPost->canEdit->setOriValue(MbqBaseFdt::getFdt('MbqFdtForum.MbqEtForumPost.canEdit.range.no'));
             }
         }
         /* common end */
         if (isset($mbqOpt['oMbqDataPage'])) {
             $oMbqDataPage = $mbqOpt['oMbqDataPage'];
             $oMbqDataPage->datas = $objsMbqEtForumPost;
             return $oMbqDataPage;
         } else {
             return $objsMbqEtForumPost;
         }
     }
     MbqError::alert('', __METHOD__ . ',line:' . __LINE__ . '.' . MBQ_ERR_INFO_UNKNOWN_CASE);
 }
Ejemplo n.º 2
0
 /**
  * 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);
 }