/** * Returns an instance of class (singleton pattern implementation). * * @return EQUESTIONS_CLASS_CreditsBridge */ public static function getInstance() { if (self::$classInstance === null) { self::$classInstance = new self(); } return self::$classInstance; }
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); }
private function fullInit() { OW::getRouter()->addRoute(new OW_Route('equestions-index', 'questions', 'EQUESTIONS_CTRL_List', 'all')); OW::getRouter()->addRoute(new OW_Route('equestions-all', 'questions', 'EQUESTIONS_CTRL_List', 'all')); OW::getRouter()->addRoute(new OW_Route('equestions-my', 'questions/my', 'EQUESTIONS_CTRL_List', 'my')); OW::getRouter()->addRoute(new OW_Route('equestions-friends', 'questions/friends', 'EQUESTIONS_CTRL_List', 'friends')); OW::getRouter()->addRoute(new OW_Route('equestions-admin-main', 'admin/plugins/questions', 'EQUESTIONS_CTRL_Admin', 'main')); OW::getRouter()->addRoute(new OW_Route('equestions-question', 'questions/:qid', 'EQUESTIONS_CTRL_Questions', 'question')); $newsfeedBridge = EQUESTIONS_CLASS_NewsfeedBridge::getInstance(); OW::getEventManager()->bind('feed.get_status_update_cmp', array($newsfeedBridge, 'onStatusCmp')); OW::getEventManager()->bind('feed.on_item_render', array($newsfeedBridge, 'onItemRender')); OW::getEventManager()->bind('feed.on_entity_add', array($newsfeedBridge, 'onEntityAdd')); OW::getEventManager()->bind('feed.on_activity', array($newsfeedBridge, 'onActivity')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_ANSWER_ADDED, array($newsfeedBridge, 'onAnswerAdd')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_ANSWER_REMOVED, array($newsfeedBridge, 'onAnswerRemove')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_FOLLOW_ADDED, array($newsfeedBridge, 'onFollowAdd')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_FOLLOW_REMOVED, array($newsfeedBridge, 'onFollowRemove')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_QUESTION_REMOVED, array($newsfeedBridge, 'onQuestionRemove')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_POST_ADDED, array($newsfeedBridge, 'onPostAdd')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_POST_REMOVED, array($newsfeedBridge, 'onPostRemove')); OW::getEventManager()->bind('feed.collect_configurable_activity', array($newsfeedBridge, 'configurableActivity')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_QUESTION_ASKED, array($newsfeedBridge, 'onAsk')); $activityBridge = EQUESTIONS_CLASS_ActivityBridge::getInstance(); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_QUESTION_ADDED, array($activityBridge, 'onQuestionAdd')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_QUESTION_REMOVED, array($activityBridge, 'onQuestionRemove')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_ANSWER_ADDED, array($activityBridge, 'onAnswerAdd')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_ANSWER_REMOVED, array($activityBridge, 'onAnswerRemove')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_FOLLOW_ADDED, array($activityBridge, 'onFollowAdd')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_FOLLOW_REMOVED, array($activityBridge, 'onFollowRemove')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_POST_ADDED, array($activityBridge, 'onPostAdd')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_POST_REMOVED, array($activityBridge, 'onPostRemove')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_QUESTION_ASKED, array($activityBridge, 'onAsk')); $commentBridge = EQUESTIONS_CLASS_CommentsBridge::getInstance(); OW::getEventManager()->bind('base_add_comment', array($commentBridge, 'onCommentAdd')); OW::getEventManager()->bind('base_delete_comment', array($commentBridge, 'onCommentRemove')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_QUESTION_REMOVED, array($commentBridge, 'onQuestionRemove')); $groupsBridge = EQUESTIONS_CLASS_GroupsBridge::getInstance(); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_BEFORE_QUESTION_ADDED, array($groupsBridge, 'onBeforeQuestionAdd')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_ON_INTERACT_PERMISSION_CHECK, array($groupsBridge, 'onCheckInteractPermission')); EQUESTIONS_CLASS_InvitationsBridge::getInstance()->init(); OW::getEventManager()->bind('admin.add_auth_labels', array($this, 'onAuthLabelsCollect')); OW::getEventManager()->bind(OW_EventManager::ON_FINALIZE, array($this, 'onFinalize')); $creditsBridge = EQUESTIONS_CLASS_CreditsBridge::getInstance(); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_QUESTION_ADDED, array($creditsBridge, 'onQuestionAdd')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_ANSWER_ADDED, array($creditsBridge, 'onAnswerAdd')); //OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_FOLLOW_ADDED, array($creditsBridge, 'onFollowAdd')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_POST_ADDED, array($creditsBridge, 'onPostAdd')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_QUESTION_ASKED, array($creditsBridge, 'onAsk')); OW::getEventManager()->bind(EQUESTIONS_BOL_Service::EVENT_OPTION_ADDED, array($creditsBridge, 'onOptionAdd')); EQUESTIONS_CLASS_EnotificationBridge::getInstance()->init(); //Privacy OW::getEventManager()->bind('plugin.privacy.get_action_list', array($this, 'collectPrivacyActions')); OW::getEventManager()->bind('feed.collect_privacy', array($newsfeedBridge, 'collectPrivacy')); OW::getEventManager()->bind('plugin.privacy.on_change_action_privacy', array($this, 'onPrivacyChange')); $credits = new EQUESTIONS_CLASS_Credits(); OW::getEventManager()->bind('usercredits.on_action_collect', array($credits, 'bindCreditActionsCollect')); }
public function addQuestion() { if (!OW::getRequest()->isAjax()) { throw new Redirect404Exception(); } if (!OW::getUser()->isAuthenticated()) { echo json_encode(false); exit; } if (empty($_POST['question'])) { echo json_encode(false); exit; } $permissions = EQUESTIONS_CLASS_CreditsBridge::getInstance()->getAllPermissions(EQUESTIONS_CLASS_Credits::ACTION_ASK); if (!$permissions[EQUESTIONS_CLASS_Credits::ACTION_ASK]) { echo json_encode(array('reset' => false, 'warning' => EQUESTIONS_CLASS_CreditsBridge::getInstance()->credits->getErrorMessage(EQUESTIONS_CLASS_Credits::ACTION_ASK))); exit; } $question = empty($_POST['question']) ? '' : htmlspecialchars($_POST['question']); $answers = empty($_POST['answers']) ? array() : array_filter($_POST['answers'], 'trim'); $allowAddOprions = !empty($_POST['allowAddOprions']); $attachment = empty($_POST['attachment']) ? array() : json_decode($_POST['attachment'], true); if (!empty($attachment)) { if ($attachment['type'] == 'file') { $attachment['url'] = OW::getEventManager()->call('base.attachment_save_image', array('genId' => $attachment['fileId'])); $attachment['type'] = 'photo'; $attachment['href'] = $attachment['url']; } } $userId = OW::getUser()->getId(); $questionDto = $this->service->addQuestion($userId, $question, $attachment, array('allowAddOprions' => $allowAddOprions)); foreach ($answers as $ans) { $this->service->addOption($questionDto->id, $userId, $ans); } $event = new OW_Event('feed.action', array('entityType' => EQUESTIONS_BOL_Service::ENTITY_TYPE, 'entityId' => $questionDto->id, 'pluginKey' => 'equestions', 'userId' => $userId, 'visibility' => 15)); OW::getEventManager()->trigger($event); $activityList = EQUESTIONS_BOL_FeedService::getInstance()->findMainActivity(time(), array($questionDto->id), array(0, 6)); $cmp = new EQUESTIONS_CMP_FeedItem($questionDto, reset($activityList[$questionDto->id]), $activityList[$questionDto->id]); $html = $cmp->render(); $script = OW::getDocument()->getOnloadScript(); echo json_encode(array('markup' => array('html' => $html, 'script' => $script, 'position' => 'prepend'), 'permissions' => $permissions)); exit; }