public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $question = id(new PonderQuestionQuery())->setViewer($viewer)->withIDs(array($id))->needAnswers(true)->needViewerVotes(true)->executeOne();
     if (!$question) {
         return new Aphront404Response();
     }
     $question->attachVotes($viewer->getPHID());
     $question_xactions = $this->buildQuestionTransactions($question);
     $answers = $this->buildAnswers($question->getAnswers());
     $authors = mpull($question->getAnswers(), null, 'getAuthorPHID');
     if (isset($authors[$viewer->getPHID()])) {
         $answer_add_panel = id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_NOTICE)->appendChild(pht('You have already answered this question. You can not answer ' . 'twice, but you can edit your existing answer.'));
     } else {
         $answer_add_panel = new PonderAddAnswerView();
         $answer_add_panel->setQuestion($question)->setUser($viewer)->setActionURI('/ponder/answer/add/');
     }
     $header = new PHUIHeaderView();
     $header->setHeader($question->getTitle());
     $header->setUser($viewer);
     $header->setPolicyObject($question);
     if ($question->getStatus() == PonderQuestionStatus::STATUS_OPEN) {
         $header->setStatus('fa-square-o', 'bluegrey', pht('Open'));
     } else {
         $header->setStatus('fa-check-square-o', 'dark', pht('Closed'));
     }
     $actions = $this->buildActionListView($question);
     $properties = $this->buildPropertyListView($question, $actions);
     $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties);
     $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
     $crumbs->addTextCrumb('Q' . $id, '/Q' . $id);
     $ponder_view = phutil_tag('div', array('class' => 'ponder-question-view'), array($crumbs, $object_box, $question_xactions, $answers, $answer_add_panel));
     return $this->buildApplicationPage(array($ponder_view), array('title' => 'Q' . $question->getID() . ' ' . $question->getTitle(), 'pageObjects' => array_merge(array($question->getPHID()), mpull($question->getAnswers(), 'getPHID'))));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $question = id(new PonderQuestionQuery())->setViewer($viewer)->withIDs(array($id))->needAnswers(true)->needProjectPHIDs(true)->executeOne();
     if (!$question) {
         return new Aphront404Response();
     }
     $answers = $this->buildAnswers($question);
     $answer_add_panel = id(new PonderAddAnswerView())->setQuestion($question)->setUser($viewer)->setActionURI('/ponder/answer/add/');
     $header = new PHUIHeaderView();
     $header->setHeader($question->getTitle());
     $header->setUser($viewer);
     $header->setPolicyObject($question);
     if ($question->getStatus() == PonderQuestionStatus::STATUS_OPEN) {
         $header->setStatus('fa-square-o', 'bluegrey', pht('Open'));
     } else {
         $text = PonderQuestionStatus::getQuestionStatusFullName($question->getStatus());
         $icon = PonderQuestionStatus::getQuestionStatusIcon($question->getStatus());
         $header->setStatus($icon, 'dark', $text);
     }
     $actions = $this->buildActionListView($question);
     $properties = $this->buildPropertyListView($question, $actions);
     $sidebar = $this->buildSidebar($question);
     $content_id = celerity_generate_unique_node_id();
     $timeline = $this->buildTransactionTimeline($question, id(new PonderQuestionTransactionQuery())->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)));
     $xactions = $timeline->getTransactions();
     $add_comment = id(new PhabricatorApplicationTransactionCommentView())->setUser($viewer)->setObjectPHID($question->getPHID())->setShowPreview(false)->setHeaderText(pht('Question Comment'))->setAction($this->getApplicationURI("/question/comment/{$id}/"))->setSubmitButtonName(pht('Comment'));
     $comment_view = phutil_tag('div', array('id' => $content_id, 'style' => 'display: none;'), array($timeline, $add_comment));
     $footer = id(new PonderFooterView())->setContentID($content_id)->setCount(count($xactions));
     $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties)->appendChild($footer);
     if ($viewer->getPHID() == $question->getAuthorPHID()) {
         $status = $question->getStatus();
         $answers_list = $question->getAnswers();
         if ($answers_list && $status == PonderQuestionStatus::STATUS_OPEN) {
             $info_view = id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_WARNING)->appendChild(pht('If this question has been resolved, please consider closing
           the question and marking the answer as helpful.'));
             $object_box->setInfoView($info_view);
         }
     }
     $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
     $crumbs->addTextCrumb('Q' . $id, '/Q' . $id);
     $answer_wiki = null;
     if ($question->getAnswerWiki()) {
         $answer = phutil_tag_div('mlt mlb msr msl', $question->getAnswerWiki());
         $answer_wiki = id(new PHUIObjectBoxView())->setHeaderText(pht('Answer Summary'))->setColor(PHUIObjectBoxView::COLOR_BLUE)->appendChild($answer);
     }
     $ponder_view = id(new PHUITwoColumnView())->setMainColumn(array($object_box, $comment_view, $answer_wiki, $answers, $answer_add_panel))->setSideColumn($sidebar)->addClass('ponder-question-view');
     return $this->buildApplicationPage(array($crumbs, $ponder_view), array('title' => 'Q' . $question->getID() . ' ' . $question->getTitle(), 'pageObjects' => array_merge(array($question->getPHID()), mpull($question->getAnswers(), 'getPHID'))));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $question = id(new PonderQuestionQuery())->setViewer($viewer)->withIDs(array($id))->needAnswers(true)->needProjectPHIDs(true)->executeOne();
     if (!$question) {
         return new Aphront404Response();
     }
     $answers = $this->buildAnswers($question);
     $answer_add_panel = id(new PonderAddAnswerView())->setQuestion($question)->setUser($viewer)->setActionURI('/ponder/answer/add/');
     $header = new PHUIHeaderView();
     $header->setHeader($question->getTitle());
     $header->setUser($viewer);
     $header->setPolicyObject($question);
     $header->setHeaderIcon('fa-university');
     if ($question->getStatus() == PonderQuestionStatus::STATUS_OPEN) {
         $header->setStatus('fa-square-o', 'bluegrey', pht('Open'));
     } else {
         $text = PonderQuestionStatus::getQuestionStatusFullName($question->getStatus());
         $icon = PonderQuestionStatus::getQuestionStatusIcon($question->getStatus());
         $header->setStatus($icon, 'dark', $text);
     }
     $properties = $this->buildPropertyListView($question);
     $actions = $this->buildActionListView($question);
     $details = $this->buildPropertySectionView($question);
     $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $question, PhabricatorPolicyCapability::CAN_EDIT);
     $content_id = celerity_generate_unique_node_id();
     $timeline = $this->buildTransactionTimeline($question, id(new PonderQuestionTransactionQuery())->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)));
     $xactions = $timeline->getTransactions();
     $add_comment = id(new PhabricatorApplicationTransactionCommentView())->setUser($viewer)->setObjectPHID($question->getPHID())->setShowPreview(false)->setAction($this->getApplicationURI("/question/comment/{$id}/"))->setSubmitButtonName(pht('Comment'));
     $add_comment = phutil_tag_div('ponder-question-add-comment-view', $add_comment);
     $comment_view = phutil_tag('div', array('id' => $content_id, 'style' => 'display: none;'), array($timeline, $add_comment));
     $footer = id(new PonderFooterView())->setContentID($content_id)->setCount(count($xactions));
     $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
     $crumbs->addTextCrumb('Q' . $id, '/Q' . $id);
     $crumbs->setBorder(true);
     $subheader = $this->buildSubheaderView($question);
     $answer_wiki = null;
     if ($question->getAnswerWiki()) {
         $wiki = new PHUIRemarkupView($viewer, $question->getAnswerWiki());
         $answer_wiki = id(new PHUIObjectBoxView())->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)->setHeaderText(pht('ANSWER SUMMARY'))->appendChild($wiki)->addClass('ponder-answer-wiki');
     }
     require_celerity_resource('ponder-view-css');
     $ponder_content = phutil_tag('div', array('class' => 'ponder-question-content'), array($answer_wiki, $footer, $comment_view, $answers, $answer_add_panel));
     $ponder_view = id(new PHUITwoColumnView())->setHeader($header)->setSubheader($subheader)->setMainColumn($ponder_content)->setPropertyList($properties)->addPropertySection(pht('DETAILS'), $details)->setActionList($actions)->addClass('ponder-question-view');
     $page_objects = array_merge(array($question->getPHID()), mpull($question->getAnswers(), 'getPHID'));
     return $this->newPage()->setTitle('Q' . $question->getID() . ' ' . $question->getTitle())->setCrumbs($crumbs)->setPageObjectPHIDs($page_objects)->appendChild(array($ponder_view));
 }
 public function handleRequest(AphrontRequest $request)
 {
     $viewer = $request->getViewer();
     $id = $request->getURIData('id');
     $question = id(new PonderQuestionQuery())->setViewer($viewer)->withIDs(array($id))->needAnswers(true)->needProjectPHIDs(true)->executeOne();
     if (!$question) {
         return new Aphront404Response();
     }
     $answers = $this->buildAnswers($question->getAnswers());
     $authors = mpull($question->getAnswers(), null, 'getAuthorPHID');
     if (isset($authors[$viewer->getPHID()])) {
         $answer_add_panel = id(new PHUIInfoView())->setSeverity(PHUIInfoView::SEVERITY_NOTICE)->appendChild(pht('You have already answered this question. You can not answer ' . 'twice, but you can edit your existing answer.'));
     } else {
         $answer_add_panel = new PonderAddAnswerView();
         $answer_add_panel->setQuestion($question)->setUser($viewer)->setActionURI('/ponder/answer/add/');
     }
     $header = new PHUIHeaderView();
     $header->setHeader($question->getTitle());
     $header->setUser($viewer);
     $header->setPolicyObject($question);
     if ($question->getStatus() == PonderQuestionStatus::STATUS_OPEN) {
         $header->setStatus('fa-square-o', 'bluegrey', pht('Open'));
     } else {
         $text = PonderQuestionStatus::getQuestionStatusFullName($question->getStatus());
         $icon = PonderQuestionStatus::getQuestionStatusIcon($question->getStatus());
         $header->setStatus($icon, 'dark', $text);
     }
     $actions = $this->buildActionListView($question);
     $properties = $this->buildPropertyListView($question, $actions);
     $sidebar = $this->buildSidebar($question);
     $content_id = celerity_generate_unique_node_id();
     $timeline = $this->buildTransactionTimeline($question, id(new PonderQuestionTransactionQuery())->withTransactionTypes(array(PhabricatorTransactions::TYPE_COMMENT)));
     $xactions = $timeline->getTransactions();
     $add_comment = id(new PhabricatorApplicationTransactionCommentView())->setUser($viewer)->setObjectPHID($question->getPHID())->setShowPreview(false)->setHeaderText(pht('Question Comment'))->setAction($this->getApplicationURI("/question/comment/{$id}/"))->setSubmitButtonName(pht('Comment'));
     $comment_view = phutil_tag('div', array('id' => $content_id, 'style' => 'display: none;'), array($timeline, $add_comment));
     $footer = id(new PonderFooterView())->setContentID($content_id)->setCount(count($xactions));
     $object_box = id(new PHUIObjectBoxView())->setHeader($header)->addPropertyList($properties)->appendChild($footer);
     $crumbs = $this->buildApplicationCrumbs($this->buildSideNavView());
     $crumbs->addTextCrumb('Q' . $id, '/Q' . $id);
     $ponder_view = id(new PHUITwoColumnView())->setMainColumn(array($object_box, $comment_view, $answers, $answer_add_panel))->setSideColumn($sidebar)->addClass('ponder-question-view');
     return $this->buildApplicationPage(array($crumbs, $ponder_view), array('title' => 'Q' . $question->getID() . ' ' . $question->getTitle(), 'pageObjects' => array_merge(array($question->getPHID()), mpull($question->getAnswers(), 'getPHID'))));
 }