public function onBeforeRender() { if (!empty($this->attachment)) { if ($this->expandedView) { $this->attachment['onclick'] = null; } else { $this->attachment['onclick'] = 'QUESTIONS_AnswerListCollection.' . $this->uniqId . '.openQuestion(); return false;'; if ($this->attachment['type'] != 'link') { $this->attachment['href'] = $this->questionUrl; } } $attachCmp = new EQUESTIONS_CMP_Attachment($this->attachment, $this->expandedView); $this->addComponent('attachment', $attachCmp); } if (!$this->doNotLoadStatic) { EQUESTIONS_Plugin::getInstance()->addStatic(); } if ($this->editable === null) { $this->editable = $this->service->isCurrentUserCanInteract($this->question) && $this->service->isCurrentUserCanAnswer($this->question); } $tmp = $this->service->findOptionListAndAnswerCountList($this->question->id, $this->startStamp, $this->userContext, $this->limit); $optionsDtoList = $tmp['optionList']; $countList = $tmp['countList']; $userContext = null; if (is_array($this->userContext)) { $userContext = $this->userContext; $userContext[] = $this->userId; $userContext = array_unique($userContext); } $totalAnswerCount = $this->totalAnswerCount == null ? $this->service->findTotalAnswersCount($this->question->id) : $this->totalAnswerCount; $answerCount = $this->poll ? $totalAnswerCount : $this->service->findMaxAnswersCount($this->question->id); $optionList = new EQUESTIONS_CMP_OptionList($optionsDtoList, $this->uniqId, $this->userId); $optionList->setAnswerCount($answerCount); $optionList->setEditable($this->editable); $optionList->setIsPoll($this->poll); $optionList->setUsersContext($userContext); $optionList->setEditMode($this->editMode); $options = $optionList->initOption($countList); $shareData = array('userId' => $this->userId, 'ownerId' => $this->question->userId, 'editable' => $this->editable, 'editMode' => $this->editMode, 'questionId' => $this->question->id, 'totalAnswers' => $answerCount, 'poll' => $this->poll, 'uniqId' => $this->uniqId, 'userContext' => $userContext, 'displayedCount' => count($options), 'optionTotal' => $this->optionTotal, 'startStamp' => $this->startStamp, 'ignoreOptions' => array(), 'expandedView' => $this->expandedView, 'inPopupMode' => $this->inPopupMode, 'ownerMode' => $this->userId == $this->question->userId); $shareData['offset'] = $shareData['displayedCount']; $shareData['st']['displayedCount'] = $shareData['displayedCount']; $shareData['st']['optionTotal'] = $shareData['optionTotal']; $jsAccessor = 'questionAnswers'; $js = UTIL_JsGenerator::newInstance(); $js->equateVarables($jsAccessor, array('QUESTIONS_AnswerListCollection', $this->uniqId)); $js->callFunction(array($jsAccessor, 'init'), array($this->uniqId, $options, $shareData, !$this->editable)); $js->callFunction(array($jsAccessor, 'setResponder'), array(OW::getRouter()->urlFor('EQUESTIONS_CTRL_Questions', 'rsp'))); $this->assign('viewMore', $this->viewMore); $this->assign('editMode', $this->editMode); if ($this->viewMore) { $js->callFunction(array($jsAccessor, 'initViewMore'), array()); $this->assign('viewMoreUrl', $this->questionUrl); } $addNewAvaliable = $this->editable && !$this->poll; $this->assign('addNew', $addNewAvaliable); $this->assign('hideAddNew', !$this->isAddNewAvaliable()); if ($addNewAvaliable) { $js->callFunction(array($jsAccessor, 'initAddNew'), array()); } OW::getDocument()->addOnloadScript($js); $this->assign('uniqId', $this->uniqId); $this->addComponent('list', $optionList); OW::getLanguage()->addKeyForJs('equestions', 'option_not_empty_delete_warning'); OW::getLanguage()->addKeyForJs('equestions', 'question_fb_title'); OW::getLanguage()->addKeyForJs('equestions', 'users_fb_title'); }
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); }