Exemplo n.º 1
0
 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;
     }
     $question = empty($_POST['question']) ? '' : strip_tags($_POST['question']);
     $question = UTIL_HtmlTag::autoLink($question);
     $answers = empty($_POST['answers']) ? array() : array_filter($_POST['answers'], 'trim');
     $allowAddOprions = !empty($_POST['allowAddOprions']);
     $userId = OW::getUser()->getId();
     $questionDto = $this->service->addQuestion($userId, $question, array('allowAddOprions' => $allowAddOprions));
     foreach ($answers as $ans) {
         $this->service->addOption($questionDto->id, $userId, $ans);
     }
     $event = new OW_Event('feed.action', array('entityType' => QUESTIONS_BOL_Service::ENTITY_TYPE, 'entityId' => $questionDto->id, 'pluginKey' => 'questions', 'userId' => $userId, 'visibility' => 15));
     OW::getEventManager()->trigger($event);
     $activityList = QUESTIONS_BOL_FeedService::getInstance()->findMainActivity(time(), array($questionDto->id), array(0, 6));
     $cmp = new QUESTIONS_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')));
     exit;
 }
Exemplo n.º 2
0
 public function newsfeedAdd()
 {
     if (!OW::getRequest()->isAjax()) {
         throw new Redirect404Exception();
     }
     if (empty($_POST['question'])) {
         echo json_encode(false);
         exit;
     }
     $question = empty($_POST['question']) ? '' : htmlspecialchars($_POST['question']);
     //$question = UTIL_HtmlTag::autoLink($question);
     $answers = empty($_POST['answers']) ? array() : array_filter($_POST['answers'], 'trim');
     $allowAddOprions = !empty($_POST['allowAddOprions']);
     $userId = OW::getUser()->getId();
     $questionDto = $this->service->addQuestion($userId, $question, array('allowAddOprions' => $allowAddOprions, 'context' => array('type' => $_POST['feedType'], 'id' => $_POST['feedId'])));
     foreach ($answers as $ans) {
         $this->service->addOption($questionDto->id, $userId, $ans);
     }
     $event = new OW_Event('feed.action', array('entityType' => QUESTIONS_BOL_Service::ENTITY_TYPE, 'entityId' => $questionDto->id, 'pluginKey' => 'questions', 'userId' => $userId, 'feedType' => $_POST['feedType'], 'feedId' => $_POST['feedId'], 'visibility' => (int) $_POST['visibility']), array('contextFeedType' => $_POST['feedType'], 'contextFeedId' => $_POST['feedId']));
     OW::getEventManager()->trigger($event);
     echo json_encode(array('questionId' => $questionDto->id));
     exit;
 }