Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / ponder / view / PonderAddAnswerView.php
blobd297e6408a5e76b34468c5552c8b3de2eb70a886
1 <?php
3 final class PonderAddAnswerView extends AphrontView {
5 private $question;
6 private $actionURI;
7 private $draft;
9 public function setQuestion($question) {
10 $this->question = $question;
11 return $this;
14 public function setActionURI($uri) {
15 $this->actionURI = $uri;
16 return $this;
19 public function render() {
20 $question = $this->question;
21 $viewer = $this->getViewer();
23 $authors = mpull($question->getAnswers(), null, 'getAuthorPHID');
24 if (isset($authors[$viewer->getPHID()])) {
25 $view = id(new PHUIInfoView())
26 ->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
27 ->setTitle(pht('Already Answered'))
28 ->appendChild(
29 pht(
30 'You have already answered this question. You can not answer '.
31 'twice, but you can edit your existing answer.'));
32 return phutil_tag_div('ponder-add-answer-view', $view);
35 $info_panel = null;
36 if ($question->getStatus() != PonderQuestionStatus::STATUS_OPEN) {
37 $info_panel = id(new PHUIInfoView())
38 ->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
39 ->appendChild(
40 pht(
41 'This question has been marked as closed,
42 but you can still leave a new answer.'));
45 $box_style = null;
46 $header = id(new PHUIHeaderView())
47 ->setHeader(pht('New Answer'))
48 ->addClass('ponder-add-answer-header');
50 $form = new AphrontFormView();
51 $form
52 ->setViewer($viewer)
53 ->setAction($this->actionURI)
54 ->setWorkflow(true)
55 ->addHiddenInput('question_id', $question->getID())
56 ->appendChild(
57 id(new PhabricatorRemarkupControl())
58 ->setName('answer')
59 ->setLabel(pht('Answer'))
60 ->setError(true)
61 ->setID('answer-content')
62 ->setViewer($viewer))
63 ->appendChild(
64 id(new AphrontFormSubmitControl())
65 ->setValue(pht('Add Answer')));
67 if (!$viewer->isLoggedIn()) {
68 $login_href = id(new PhutilURI('/auth/start/'))
69 ->replaceQueryParam('next', '/Q'.$question->getID());
70 $form = id(new PHUIFormLayoutView())
71 ->addClass('login-to-participate')
72 ->appendChild(
73 id(new PHUIButtonView())
74 ->setTag('a')
75 ->setText(pht('Log In to Answer'))
76 ->setHref((string)$login_href));
79 $box = id(new PHUIObjectBoxView())
80 ->appendChild($form)
81 ->setHeaderText(pht('Answer'))
82 ->addClass('ponder-add-answer-view');
84 if ($info_panel) {
85 $box->setInfoView($info_panel);
88 return array($header, $box);