Exemplo n.º 1
0
 public function onBeforeRender()
 {
     parent::onBeforeRender();
     $language = OW::getLanguage();
     $configs = OW::getConfig()->getValues('questions');
     $optionTotal = QUESTIONS_BOL_Service::getInstance()->findOptionCount($this->question->id);
     $answerCount = QUESTIONS_BOL_Service::getInstance()->findTotalAnswersCount($this->question->id);
     $postCount = BOL_CommentService::getInstance()->findCommentCount(QUESTIONS_BOL_Service::ENTITY_TYPE, $this->question->id);
     $questionUrl = OW::getRouter()->urlForRoute('questions-question', array('qid' => $this->question->id));
     $count = QUESTIONS_BOL_Service::DISPLAY_COUNT;
     if ($optionTotal - $count < 2) {
         $count = $optionTotal;
     }
     $answers = new QUESTIONS_CMP_Answers($this->question, $optionTotal, array(0, $count));
     $answers->setTotalAnswerCount($answerCount);
     $answers->setUsersContext($this->getContextUserIds());
     $bubbleActivity = $this->getBubbleActivity();
     $jsSelector = 'QUESTIONS_AnswerListCollection.' . $answers->getUniqId();
     $text = $this->getItemString($bubbleActivity, $jsSelector, $questionUrl);
     $avatars = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($bubbleActivity->userId));
     $allowPopups = !isset($configs['allow_popups']) || $configs['allow_popups'];
     $features = array();
     $onClickStr = "window.location.href='{$questionUrl}'";
     if ($configs['allow_comments']) {
         if ($allowPopups) {
             $onClickStr = "return {$jsSelector}.openQuestionDelegate(true);";
         }
         $features[] = array('class' => 'q-' . $answers->getUniqId() . '-status-comments', 'iconClass' => 'ow_miniic_comment', 'label' => $postCount, 'onclick' => $onClickStr, 'string' => null);
     }
     if ($allowPopups) {
         $onClickStr = "return {$jsSelector}.openQuestionDelegate();";
     }
     $features[] = array('class' => 'q-' . $answers->getUniqId() . '-status-votes', 'iconClass' => 'questions_miniicon_check', 'label' => $answerCount, 'onclick' => $onClickStr, 'string' => null);
     if ($configs['enable_follow']) {
         $onClickStr = "OW.error('" . $language->text('questions', 'follow_not_allowed') . "')";
         $isFollowing = false;
         if (QUESTIONS_BOL_Service::getInstance()->isCurrentUserCanInteract($this->question)) {
             $userId = OW::getUser()->getId();
             $isFollowing = QUESTIONS_BOL_Service::getInstance()->isFollow($userId, $this->question->id);
             $onClickStr = $isFollowing ? $jsSelector . '.unfollowQuestion();' : $jsSelector . '.followQuestion();';
         } else {
             if (OW::getUser()->isAuthenticated()) {
                 $isFollowing = QUESTIONS_BOL_Service::getInstance()->isFollow($userId, $this->question->id);
                 if ($isFollowing) {
                     $onClickStr = $jsSelector . '.unfollowQuestion();';
                 }
             }
         }
         $features[] = array('class' => 'q-' . $answers->getUniqId() . '-status-follows', 'iconClass' => 'questions_miniic_follow', 'label' => QUESTIONS_BOL_Service::getInstance()->findFollowsCount($this->question->id), 'onclick' => $onClickStr, 'active' => $isFollowing);
     }
     $settings = $this->question->getSettings();
     $context = empty($settings['context']['url']) || empty($settings['context']['label']) ? null : array('url' => $settings['context']['url'], 'label' => $settings['context']['label']);
     $tplQuestion = array('questionId' => $this->question->id, 'uniqId' => $this->getUniqId(), 'text' => $text, 'timeStamp' => UTIL_DateTime::formatDate($bubbleActivity->timeStamp), 'lastItem' => $this->lastItem, 'answers' => $answers->render(), 'avatar' => $avatars[$bubbleActivity->userId], 'settings' => $settings, 'context' => $context, 'features' => $features, 'permalink' => $questionUrl);
     $event = new OW_Event(QUESTIONS_BOL_Service::EVENT_ON_LIST_ITEM_RENDER, array("questionId" => $this->question->id, "questionDto" => $this->question, "text" => $text, "settings" => $settings, "uniqId" => $this->getUniqId()), $tplQuestion);
     OW::getEventManager()->trigger($event);
     $this->assign('item', $event->getData());
 }
Exemplo n.º 2
0
 public function isCurrentUserCanInteract(QUESTIONS_BOL_Question $question)
 {
     $canInteract = OW::getUser()->isAuthenticated();
     $event = new OW_Event(self::EVENT_ON_INTERACT_PERMISSION_CHECK, array('questionId' => $question->id, 'settings' => $question->getSettings()), $canInteract);
     OW::getEventManager()->trigger($event);
     return $event->getData();
 }