示例#1
0
 public function __construct(array $params)
 {
     parent::__construct();
     $this->forumService = FORUM_BOL_ForumService::getInstance();
     if (!isset($params['groupId']) || !($groupId = (int) $params['groupId'])) {
         $this->setVisible(false);
         return;
     }
     $groupInfo = $this->forumService->getGroupInfo($groupId);
     if (!$groupInfo) {
         $this->setVisible(false);
         return;
     }
     $forumSection = $this->forumService->findSectionById($groupInfo->sectionId);
     if (!$forumSection) {
         $this->setVisible(false);
         return;
     }
     $isHidden = $forumSection->isHidden;
     $userId = OW::getUser()->getId();
     if ($isHidden) {
         $isModerator = OW::getUser()->isAuthorized($forumSection->entity);
         $event = new OW_Event('forum.can_view', array('entity' => $forumSection->entity, 'entityId' => $groupInfo->entityId), true);
         OW::getEventManager()->trigger($event);
         $canView = $event->getData();
         $eventParams = array('entity' => $forumSection->entity, 'entityId' => $groupInfo->entityId, 'action' => 'add_topic');
         $event = new OW_Event('forum.check_permissions', $eventParams);
         OW::getEventManager()->trigger($event);
         $canEdit = $event->getData();
     } else {
         $isModerator = OW::getUser()->isAuthorized('forum');
         $canView = OW::getUser()->isAuthorized('forum', 'view');
         $canEdit = OW::getUser()->isAuthorized('forum', 'edit');
         $canEdit = $canEdit || $isModerator ? true : false;
     }
     if ($groupInfo->isPrivate) {
         if (!$userId) {
             $this->assign('authFailed', true);
             return;
         } else {
             if (!$isModerator) {
                 if (!$this->forumService->isPrivateGroupAvailable($userId, json_decode($groupInfo->roles))) {
                     $this->assign('authFailed', true);
                     return;
                 }
             }
         }
     }
     if (!$canView) {
         $this->assign('authFailed', true);
         return;
     }
     $page = !empty($_GET['page']) && (int) $_GET['page'] ? abs((int) $_GET['page']) : 1;
     if (!$groupInfo) {
         $forumUrl = OW::getRouter()->urlForRoute('forum-default');
         OW::getApplication()->redirect($forumUrl);
     }
     $topicList = $this->forumService->getGroupTopicList($groupId, $page);
     $topicCount = $this->forumService->getGroupTopicCount($groupId);
     $userIds = array();
     $topicIds = array();
     foreach ($topicList as $topic) {
         array_push($topicIds, $topic['id']);
         if (isset($topic['lastPost']) && !in_array($topic['lastPost']['userId'], $userIds)) {
             array_push($userIds, $topic['lastPost']['userId']);
         }
     }
     $attachments = FORUM_BOL_PostAttachmentService::getInstance()->getAttachmentsCountByTopicIdList($topicIds);
     $this->assign('attachments', $attachments);
     $usernames = BOL_UserService::getInstance()->getUserNamesForList($userIds);
     $this->assign('usernames', $usernames);
     $displayNames = BOL_UserService::getInstance()->getDisplayNamesForList($userIds);
     $this->assign('displayNames', $displayNames);
     $perPage = $this->forumService->getTopicPerPageConfig();
     $pageCount = $topicCount ? ceil($topicCount / $perPage) : 1;
     $paging = new BASE_CMP_Paging($page, $pageCount, $perPage);
     $this->assign('paging', $paging->render());
     $addTopicUrl = OW::getRouter()->urlForRoute('add-topic', array('groupId' => $groupId));
     $this->assign('addTopicUrl', $addTopicUrl);
     $this->assign('canEdit', $canEdit);
     $this->assign('groupId', $groupId);
     $this->assign('topicList', $topicList);
     $this->assign('isHidden', $isHidden);
     $showCaption = !empty($params['caption']) ? $params['caption'] : false;
     if ($showCaption) {
         $groupName = htmlspecialchars($groupInfo->name);
         OW::getDocument()->setHeading(OW::getLanguage()->text('forum', 'forum_page_heading', array('forum' => $groupName)));
         OW::getDocument()->setHeadingIconClass('ow_ic_forum');
         OW::getDocument()->setTitle($groupName);
         OW::getDocument()->setDescription(OW::getLanguage()->text('forum', 'group_meta_description', array('group' => $groupName)));
         if ($isHidden) {
             $event = new OW_Event('forum.find_forum_caption', array('entity' => $forumSection->entity, 'entityId' => $groupInfo->entityId));
             OW::getEventManager()->trigger($event);
             $eventData = $event->getData();
             $componentForumCaption = $eventData['component'];
             if (!empty($componentForumCaption)) {
                 $this->assign('componentForumCaption', $componentForumCaption->render());
             } else {
                 $componentForumCaption = false;
                 $this->assign('componentForumCaption', $componentForumCaption);
             }
             OW::getNavigation()->deactivateMenuItems(OW_Navigation::MAIN);
             OW::getNavigation()->activateMenuItem(OW_Navigation::MAIN, $forumSection->entity, $eventData['key']);
         } else {
             $bcItems = array(array('href' => OW::getRouter()->urlForRoute('forum-default'), 'label' => OW::getLanguage()->text('forum', 'forum_index')), array('href' => OW::getRouter()->urlForRoute('section-default', array('sectionId' => $groupInfo->sectionId)), 'label' => $forumSection->name), array('label' => $groupInfo->name));
             $breadCrumbCmp = new BASE_CMP_Breadcrumb($bcItems);
             $this->addComponent('breadcrumb', $breadCrumbCmp);
         }
     }
     $this->addComponent('search', new FORUM_CMP_ForumSearch(array('scope' => 'group', 'groupId' => $groupId)));
     $this->assign('showCaption', $showCaption);
 }