public function processRequest()
 {
     $request = $this->getRequest();
     if (!$request->isFormPost()) {
         return new Aphront400Response();
     }
     $user = $request->getUser();
     $question_id = $request->getInt('question_id');
     $question = PonderQuestionQuery::loadSingle($user, $question_id);
     if (!$question) {
         return new Aphront404Response();
     }
     $answer = $request->getStr('answer');
     // Only want answers with some non whitespace content
     if (!strlen(trim($answer))) {
         $dialog = new AphrontDialogView();
         $dialog->setUser($request->getUser());
         $dialog->setTitle('Empty answer');
         $dialog->appendChild('<p>Your answer must not be empty.</p>');
         $dialog->addCancelButton('/Q' . $question_id);
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_WEB, array('ip' => $request->getRemoteAddr()));
     $res = new PonderAnswer();
     $res->setContent($answer)->setAuthorPHID($user->getPHID())->setVoteCount(0)->setQuestionID($question_id)->setContentSource($content_source);
     id(new PonderAnswerEditor())->setUser($user)->setQuestion($question)->setAnswer($res)->saveAnswer();
     return id(new AphrontRedirectResponse())->setURI(id(new PhutilURI('/Q' . $question->getID())));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     if (!$request->isFormPost()) {
         return new Aphront400Response();
     }
     $user = $request->getUser();
     $question_id = $request->getInt('question_id');
     $question = PonderQuestionQuery::loadSingle($user, $question_id);
     if (!$question) {
         return new Aphront404Response();
     }
     $target = $request->getStr('target');
     $objects = id(new PhabricatorObjectHandleData(array($target)))->loadHandles();
     if (!$objects) {
         return new Aphront404Response();
     }
     $content = $request->getStr('content');
     if (!strlen(trim($content))) {
         $dialog = new AphrontDialogView();
         $dialog->setUser($request->getUser());
         $dialog->setTitle('Empty comment');
         $dialog->appendChild('<p>Your comment must not be empty.</p>');
         $dialog->addCancelButton('/Q' . $question_id);
         return id(new AphrontDialogResponse())->setDialog($dialog);
     }
     $res = new PonderComment();
     $res->setContent($content)->setAuthorPHID($user->getPHID())->setTargetPHID($target);
     id(new PonderCommentEditor())->setQuestion($question)->setComment($res)->setTargetPHID($target)->setUser($user)->save();
     return id(new AphrontRedirectResponse())->setURI(id(new PhutilURI('/Q' . $question->getID())));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $question_id = $request->getInt('question_id');
     $question = PonderQuestionQuery::loadSingle($user, $question_id);
     if (!$question) {
         return new Aphront404Response();
     }
     $author_phid = $user->getPHID();
     $object_phids = array($author_phid);
     $handles = id(new PhabricatorObjectHandleData($object_phids))->loadHandles();
     $answer = new PonderAnswer();
     $answer->setContent($request->getStr('content'));
     $answer->setAuthorPHID($author_phid);
     $view = new PonderCommentBodyView();
     $view->setQuestion($question)->setTarget($answer)->setPreview(true)->setUser($user)->setHandles($handles)->setAction(PonderConstants::ANSWERED_LITERAL);
     return id(new AphrontAjaxResponse())->setContent($view->render());
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     if (!$request->isFormPost()) {
         return new Aphront400Response();
     }
     $user = $request->getUser();
     $question_id = $request->getInt('question_id');
     $question = PonderQuestionQuery::loadSingle($user, $question_id);
     if (!$question) {
         return new Aphront404Response();
     }
     $answer = $request->getStr('answer');
     $content_source = PhabricatorContentSource::newForSource(PhabricatorContentSource::SOURCE_WEB, array('ip' => $request->getRemoteAddr()));
     $res = new PonderAnswer();
     $res->setContent($answer)->setAuthorPHID($user->getPHID())->setVoteCount(0)->setQuestionID($question_id)->setContentSource($content_source);
     id(new PonderAnswerEditor())->setQuestion($question)->setAnswer($res)->saveAnswer();
     PhabricatorSearchPonderIndexer::indexQuestion($question);
     return id(new AphrontRedirectResponse())->setURI(id(new PhutilURI('/Q' . $question->getID()))->setFragment('A' . $res->getID()));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $question = PonderQuestionQuery::loadSingle($user, $this->questionID);
     if (!$question) {
         return new Aphront404Response();
     }
     $question->attachRelated();
     $question->attachVotes($user->getPHID());
     $object_phids = array($user->getPHID(), $question->getAuthorPHID());
     $answers = $question->getAnswers();
     $comments = $question->getComments();
     foreach ($comments as $comment) {
         $object_phids[] = $comment->getAuthorPHID();
     }
     foreach ($answers as $answer) {
         $object_phids[] = $answer->getAuthorPHID();
         $comments = $answer->getComments();
         foreach ($comments as $comment) {
             $object_phids[] = $comment->getAuthorPHID();
         }
     }
     $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID($question->getPHID());
     $object_phids = array_merge($object_phids, $subscribers);
     $handles = $this->loadViewerHandles($object_phids);
     $this->loadHandles($object_phids);
     $detail_panel = new PonderQuestionDetailView();
     $detail_panel->setQuestion($question)->setUser($user)->setHandles($handles);
     $responses_panel = new PonderAnswerListView();
     $responses_panel->setQuestion($question)->setHandles($handles)->setUser($user)->setAnswers($answers);
     $answer_add_panel = new PonderAddAnswerView();
     $answer_add_panel->setQuestion($question)->setUser($user)->setActionURI("/ponder/answer/add/");
     $header = id(new PhabricatorHeaderView())->setObjectName('Q' . $question->getID())->setHeader($question->getTitle());
     $actions = $this->buildActionListView($question);
     $properties = $this->buildPropertyListView($question, $subscribers);
     $nav = $this->buildSideNavView($question);
     $nav->appendChild(array($header, $actions, $properties, $detail_panel, $responses_panel, $answer_add_panel));
     $nav->selectFilter(null);
     return $this->buildApplicationPage($nav, array('device' => true, 'title' => 'Q' . $question->getID() . ' ' . $question->getTitle()));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $question = PonderQuestionQuery::loadSingle($user, $this->questionID);
     if (!$question) {
         return new Aphront404Response();
     }
     $question->attachRelated($user->getPHID());
     $answers = $question->getAnswers();
     $object_phids = array($user->getPHID(), $question->getAuthorPHID());
     foreach ($answers as $answer) {
         $object_phids[] = $answer->getAuthorPHID();
     }
     $handles = id(new PhabricatorObjectHandleData($object_phids))->loadHandles();
     $detail_panel = new PonderQuestionDetailView();
     $detail_panel->setQuestion($question)->setUser($user)->setHandles($handles);
     $responses_panel = new PonderAnswerListView();
     $responses_panel->setQuestion($question)->setHandles($handles)->setUser($user)->setAnswers($answers);
     $answer_add_panel = new PonderAddAnswerView();
     $answer_add_panel->setQuestion($question)->setUser($user)->setActionURI("/ponder/answer/add/");
     return $this->buildStandardPageResponse(array($detail_panel, $responses_panel, $answer_add_panel), array('title' => 'Q' . $question->getID() . ' ' . $question->getTitle()));
 }