public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $this->answerOffset = $request->getInt('aoff');
     $pages = array('feed' => 'All Questions', 'questions' => 'Your Questions', 'answers' => 'Your Answers');
     $side_nav = $this->buildSideNavView();
     $this->page = $side_nav->selectFilter($this->page, 'feed');
     $title = $pages[$this->page];
     switch ($this->page) {
         case 'feed':
         case 'questions':
             $pager = new AphrontPagerView();
             $pager->setOffset($request->getStr('offset'));
             $pager->setURI($request->getRequestURI(), 'offset');
             $query = new PonderQuestionQuery();
             if ($this->page == 'feed') {
                 $query->setOrder(PonderQuestionQuery::ORDER_HOTTEST);
             } else {
                 $query->setOrder(PonderQuestionQuery::ORDER_CREATED)->withAuthorPHIDs(array($user->getPHID()));
             }
             $questions = $query->executeWithOffsetPager($pager);
             $this->loadHandles(mpull($questions, 'getAuthorPHID'));
             $view = $this->buildQuestionListView($questions);
             $view->setPager($pager);
             $side_nav->appendChild(id(new PhabricatorHeaderView())->setHeader($title));
             $side_nav->appendChild($view);
             break;
         case 'answers':
             $answers = PonderAnswerQuery::loadByAuthorWithQuestions($user, $user->getPHID(), $this->answerOffset, self::PROFILE_ANSWER_PAGE_SIZE + 1);
             $side_nav->appendChild(id(new PonderUserProfileView())->setUser($user)->setAnswers($answers)->setAnswerOffset($this->answerOffset)->setPageSize(self::PROFILE_ANSWER_PAGE_SIZE)->setURI(new PhutilURI("/ponder/profile/"), "aoff"));
             break;
     }
     return $this->buildApplicationPage($side_nav, array('device' => true, 'title' => $title));
 }
 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();
     $newvote = $request->getInt("vote");
     $phid = $request->getStr("phid");
     if (1 < $newvote || $newvote < -1) {
         return new Aphront400Response();
     }
     $target = null;
     if ($this->kind == "question") {
         $target = PonderQuestionQuery::loadSingleByPHID($user, $phid);
     } else {
         if ($this->kind == "answer") {
             $target = PonderAnswerQuery::loadSingleByPHID($user, $phid);
         }
     }
     if (!$target) {
         return new Aphront404Response();
     }
     $editor = id(new PonderVoteEditor())->setVotable($target)->setUser($user)->setVote($newvote)->saveVote();
     return id(new AphrontAjaxResponse())->setContent(".");
 }
 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()));
 }
 public function processRequest()
 {
     $request = $this->getRequest();
     $user = $request->getUser();
     $this->feedOffset = $request->getInt('off');
     $this->questionOffset = $request->getInt('qoff');
     $this->answerOffset = $request->getInt('aoff');
     $side_nav = new AphrontSideNavView();
     foreach (self::$pages as $pagename => $pagetitle) {
         $class = "";
         if ($pagename == $this->page) {
             $class = 'aphront-side-nav-selected';
         }
         $linky = phutil_render_tag('a', array('href' => '/ponder/' . $pagename . '/', 'class' => $class), phutil_escape_html($pagetitle));
         $side_nav->addNavItem($linky);
     }
     switch ($this->page) {
         case self::PAGE_FEED:
             $data = PonderQuestionQuery::loadHottest($user, $this->feedOffset, self::FEED_PAGE_SIZE + 1);
             $phids = array();
             foreach ($data as $question) {
                 $phids[] = $question->getAuthorPHID();
             }
             $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
             $side_nav->appendChild(id(new PonderQuestionFeedView())->setUser($user)->setData($data)->setHandles($handles)->setOffset($this->feedOffset)->setPageSize(self::FEED_PAGE_SIZE)->setURI(new PhutilURI("/ponder/feed/"), "off"));
             break;
         case self::PAGE_PROFILE:
             $questions = PonderQuestionQuery::loadByAuthor($user, $user->getPHID(), $this->questionOffset, self::PROFILE_QUESTION_PAGE_SIZE + 1);
             $answers = PonderAnswerQuery::loadByAuthorWithQuestions($user, $user->getPHID(), $this->answerOffset, self::PROFILE_ANSWER_PAGE_SIZE + 1);
             $phids = array($user->getPHID());
             $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
             $side_nav->appendChild(id(new PonderUserProfileView())->setUser($user)->setQuestions($questions)->setAnswers($answers)->setHandles($handles)->setQuestionOffset($this->questionOffset)->setAnswerOffset($this->answerOffset)->setPageSize(self::PROFILE_QUESTION_PAGE_SIZE)->setURI(new PhutilURI("/ponder/profile/"), "qoff", "aoff"));
             break;
     }
     return $this->buildStandardPageResponse($side_nav, array('title' => self::$pages[$this->page]));
 }