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); }
private function reload($query, $data) { $question = EQUESTIONS_BOL_Service::getInstance()->findQuestion($data['questionId']); $optionTotal = EQUESTIONS_BOL_Service::getInstance()->findOptionCount($data['questionId']); $answerCount = !empty($query['answerCount']) ? $query['answerCount'] : EQUESTIONS_BOL_Service::getInstance()->findTotalAnswersCount($data['questionId']); $count = EQUESTIONS_BOL_Service::DISPLAY_COUNT; if ($optionTotal - $count < 2) { $count = $optionTotal; } $cmp = new EQUESTIONS_CMP_Answers($question, $optionTotal, array(0, $count), $data['uniqId']); $cmp->setUsersContext($data['userContext']); $cmp->setTotalAnswerCount($answerCount); $markup = $cmp->render(); $js = OW::getDocument()->getOnloadScript(); return array('reload' => array('markup' => $markup, 'script' => $js), 'status' => array('posts' => false, 'votes' => $answerCount, 'follows' => false)); }
public function onItemRender(OW_Event $event) { $params = $event->getParams(); $data = $event->getData(); if ($params['action']['entityType'] != EQUESTIONS_BOL_Service::ENTITY_TYPE) { return; } $language = OW::getLanguage(); $configs = OW::getConfig()->getValues('equestions'); $questionId = $params['action']['entityId']; $userId = OW::getUser()->getId(); $question = $this->service->findQuestion($questionId); $optionTotal = $this->service->findOptionCount($questionId); $answerCount = $this->service->findTotalAnswersCount($questionId); $postCount = BOL_CommentService::getInstance()->findCommentCount(EQUESTIONS_BOL_Service::ENTITY_TYPE, $params['action']['entityId']); $userContext = array(); $count = EQUESTIONS_BOL_Service::DISPLAY_COUNT; if ($optionTotal - $count < 2) { $count = $optionTotal; } $cmp = new EQUESTIONS_CMP_Answers($question, $optionTotal, array(0, $count)); $cmp->setTotalAnswerCount($answerCount); if (in_array($params['feedType'], array('user', 'my'))) { foreach ($params['activity'] as $act) { if ($act['activityType'] == 'answer') { $userContext[] = $act['userId']; } } $cmp->setUsersContext($userContext); } $lastActivity = $this->getBubbleActivity($params); $data['assign']['answers'] = $cmp->render(); $questionUrl = OW::getRouter()->urlForRoute('equestions-question', array('qid' => $question->id)); $jsSelector = 'QUESTIONS_AnswerListCollection.' . $cmp->getUniqId(); $allowPopups = !isset($configs['allow_popups']) || $configs['allow_popups']; $data['assign']['string'] = $data['string'] = $this->getItemString($question, $lastActivity, $jsSelector, $questionUrl); $data['features'] = array(); $onClickStr = "window.location.href='{$questionUrl}'"; if ($configs['allow_comments']) { if ($allowPopups) { $onClickStr = "return {$jsSelector}.openQuestionDelegate(true);"; } $data['features'][] = array('class' => 'q-' . $cmp->getUniqId() . '-status-comments', 'iconClass' => 'ow_miniic_comment', 'label' => $postCount, 'onclick' => $onClickStr, 'string' => null); } if ($allowPopups) { $onClickStr = "return {$jsSelector}.openQuestionDelegate();"; } $data['features'][] = array('class' => 'q-' . $cmp->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 ($this->service->isCurrentUserCanInteract($question)) { $isFollowing = $this->service->isFollow($userId, $question->id); $onClickStr = $isFollowing ? $jsSelector . '.unfollowQuestion();' : $jsSelector . '.followQuestion();'; } else { if (OW::getUser()->isAuthenticated()) { $isFollowing = $this->service->isFollow($userId, $question->id); if ($isFollowing) { $onClickStr = $jsSelector . '.unfollowQuestion();'; } } } $data['features'][] = array('class' => 'q-' . $cmp->getUniqId() . '-status-follows', 'iconClass' => 'questions_miniic_follow', 'label' => $this->service->findFollowsCount($question->id), 'onclick' => $onClickStr, 'active' => $isFollowing); } $settings = $question->getSettings(); if (isset($settings['context']) && $settings['context']['type'] != $params['feedType']) { if (!empty($settings['context']['url']) && !empty($settings['context']['label'])) { $data['context'] = $settings['context']; } } $event->setData($data); }