Esempio n. 1
0
 public function onBeforeRender()
 {
     parent::onBeforeRender();
     $language = OW::getLanguage();
     $configs = OW::getConfig()->getValues('equestions');
     $optionTotal = EQUESTIONS_BOL_Service::getInstance()->findOptionCount($this->question->id);
     $answerCount = EQUESTIONS_BOL_Service::getInstance()->findTotalAnswersCount($this->question->id);
     $postCount = BOL_CommentService::getInstance()->findCommentCount(EQUESTIONS_BOL_Service::ENTITY_TYPE, $this->question->id);
     $questionUrl = OW::getRouter()->urlForRoute('equestions-question', array('qid' => $this->question->id));
     $count = EQUESTIONS_BOL_Service::DISPLAY_COUNT;
     if ($optionTotal - $count < 2) {
         $count = $optionTotal;
     }
     $answers = new EQUESTIONS_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('equestions', 'follow_not_allowed') . "')";
         $isFollowing = false;
         if (EQUESTIONS_BOL_Service::getInstance()->isCurrentUserCanInteract($this->question)) {
             $userId = OW::getUser()->getId();
             $isFollowing = EQUESTIONS_BOL_Service::getInstance()->isFollow($userId, $this->question->id);
             $onClickStr = $isFollowing ? $jsSelector . '.unfollowQuestion();' : $jsSelector . '.followQuestion();';
         } else {
             if (OW::getUser()->isAuthenticated()) {
                 $isFollowing = EQUESTIONS_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' => EQUESTIONS_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);
     $this->assign('item', $tplQuestion);
 }
Esempio n. 2
0
 public function __construct(EQUESTIONS_BOL_Question $question, $optionTotal, array $listLimit = null, $uniqId = null)
 {
     parent::__construct();
     $this->uniqId = empty($uniqId) ? uniqid('questionsAnswers_') : $uniqId;
     $this->question = $question;
     $this->limit = $listLimit;
     $this->startStamp = time();
     $this->service = EQUESTIONS_BOL_Service::getInstance();
     $this->userId = OW::getUser()->getId();
     $this->attachment = $this->question->getAttachment();
     $this->editMode = $this->service->isCurrentUserCanEdit($question);
     $settings = json_decode($this->question->settings, true);
     $this->poll = !$settings['allowAddOprions'];
     $this->optionTotal = $optionTotal;
     $this->viewMore = $this->optionTotal - (empty($this->limit[1]) ? $this->optionTotal : $this->limit[1]);
     $this->viewMore = $this->viewMore > 0 ? $this->viewMore : 0;
     $jsConstructor = $this->poll ? 'QUESTIONS_PollAnswers' : 'QUESTIONS_QuestionAnswers';
     $js = UTIL_JsGenerator::newInstance()->newObject(array('QUESTIONS_AnswerListCollection', $this->uniqId), $jsConstructor);
     OW::getDocument()->addOnloadScript($js);
     $this->questionUrl = OW::getRouter()->urlForRoute('equestions-question', array('qid' => $this->question->id));
 }
Esempio n. 3
0
 public function isCurrentUserCanInteract(EQUESTIONS_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();
 }