private function askUsers($query, $data) { if (!OW::getUser()->isAuthenticated()) { return array('warning' => OW::getLanguage()->text('equestions', 'not_authed_ask_warning')); } $userIds = $query['ids']; $questionId = $data['questionId']; $question = $this->service->findQuestion($questionId); $params = array('userId' => OW::getUser()->getId(), 'questionId' => $questionId); if ($query['all']) { $params['special'] = true; $users = BOL_UserDao::getInstance()->findAll(); foreach ($users as $user) { if ($user->id != $params['userId']) { $userIds[] = $user->id; } } } foreach ($userIds as $uid) { $params['recipientId'] = $uid; $event = new OW_Event(EQUESTIONS_BOL_Service::EVENT_QUESTION_BEFORE_ASK, $params, $data); OW::getEventManager()->trigger($event); } $permissions = EQUESTIONS_CLASS_CreditsBridge::getInstance()->getAllPermissions(EQUESTIONS_CLASS_Credits::ACTION_ASK); return array('message' => OW::getLanguage()->text('equestions', 'question_ask_complete_msg', array('count' => count($userIds))), 'permissions' => $permissions); }
public function onPostAdd(OW_Event $event) { $params = $event->getParams(); $userService = BOL_UserService::getInstance(); $userId = $params['userId']; $question = $this->service->findQuestion($params['questionId']); $post = UTIL_String::truncate($params['text'], 100, '...'); $postId = $params['id']; $ownerId = $question->userId; $questionUrl = OW::getRouter()->urlForRoute('equestions-question', array('qid' => $question->id)); $questionText = UTIL_String::truncate($question->text, 100, '...'); $notificationParams = array('pluginKey' => EQUESTIONS_Plugin::PLUGIN_KEY, 'action' => self::ACTION_POST, 'entityType' => 'questions-post', 'entityId' => $postId, 'userId' => null, 'time' => time()); $uniqId = uniqid('question_post'); $userAvatars = BOL_AvatarService::getInstance()->getDataForUserAvatars(array($userId)); $userAvatar = $userAvatars[$userId]; $string = array('key' => EQUESTIONS_Plugin::PLUGIN_KEY . '+notifications_post', 'vars' => array('question' => '<a class="' . $uniqId . '" href="' . $questionUrl . '" >' . $questionText . '</a>', 'user' => '<a href="' . $userAvatar['url'] . '">' . $userAvatar['title'] . '</a>', 'post' => '<a class="' . $uniqId . '" href="' . $questionUrl . '" >' . $post . '</a>')); $questionSettings = array('userContext' => array((int) $userId), 'questionId' => $question->id, 'relationId' => $question->id); $notificationData = array('string' => $string, 'avatar' => $userAvatar, 'questionSettings' => $questionSettings, 'uniqId' => $uniqId, 'url' => $questionUrl); $follows = $this->service->findFollows($question->id, null, array($userId)); foreach ($follows as $f) { $notificationParams['userId'] = $f->userId; $event = new OW_Event('notifications.add', $notificationParams, $notificationData); OW::getEventManager()->trigger($event); } }
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); }