3 final class PonderAnswerEditController
extends PonderController
{
5 public function handleRequest(AphrontRequest
$request) {
6 $viewer = $request->getViewer();
7 $id = $request->getURIData('id');
9 $answer = id(new PonderAnswerQuery())
12 ->requireCapabilities(
14 PhabricatorPolicyCapability
::CAN_VIEW
,
15 PhabricatorPolicyCapability
::CAN_EDIT
,
19 return new Aphront404Response();
22 $v_content = $answer->getContent();
23 $v_status = $answer->getStatus();
27 $question = $answer->getQuestion();
28 $qid = $question->getID();
30 $answer_uri = $answer->getURI();
33 if ($request->isFormPost()) {
34 $v_content = $request->getStr('content');
35 $v_status = $request->getStr('status');
37 if (!strlen($v_content)) {
38 $errors[] = pht('You must provide some substance in your answer.');
39 $e_content = pht('Required');
44 $xactions[] = id(new PonderAnswerTransaction())
45 ->setTransactionType(PonderAnswerContentTransaction
::TRANSACTIONTYPE
)
46 ->setNewValue($v_content);
48 $xactions[] = id(new PonderAnswerTransaction())
49 ->setTransactionType(PonderAnswerStatusTransaction
::TRANSACTIONTYPE
)
50 ->setNewValue($v_status);
52 $editor = id(new PonderAnswerEditor())
54 ->setContentSourceFromRequest($request)
55 ->setContinueOnNoEffect(true);
57 $editor->applyTransactions($answer, $xactions);
59 return id(new AphrontRedirectResponse())
60 ->setURI($answer_uri);
64 $answer_content_id = celerity_generate_unique_node_id();
66 $form = id(new AphrontFormView())
69 id(new AphrontFormStaticControl())
70 ->setLabel(pht('Question'))
71 ->setValue($question->getTitle()))
73 id(new AphrontFormSelectControl())
74 ->setLabel(pht('Status'))
77 ->setOptions(PonderAnswerStatus
::getAnswerStatusMap()))
79 id(new PhabricatorRemarkupControl())
81 ->setLabel(pht('Answer'))
83 ->setID($answer_content_id)
84 ->setValue($v_content)
85 ->setError($e_content))
87 id(new AphrontFormSubmitControl())
88 ->setValue(pht('Submit'))
89 ->addCancelButton($answer_uri));
91 $crumbs = $this->buildApplicationCrumbs();
92 $crumbs->addTextCrumb("Q{$qid}", $answer_uri);
93 $crumbs->addTextCrumb(pht('Edit Answer'));
94 $crumbs->setBorder(true);
96 $header = id(new PHUIHeaderView())
97 ->setHeader(pht('Edit Answer'))
98 ->setHeaderIcon('fa-pencil');
100 $box = id(new PHUIObjectBoxView())
101 ->setHeaderText(pht('Answer'))
102 ->setFormErrors($errors)
103 ->setBackground(PHUIObjectBoxView
::BLUE_PROPERTY
)
106 $preview = id(new PHUIRemarkupPreviewPanel())
107 ->setHeader(pht('Answer Preview'))
108 ->setControlID($answer_content_id)
109 ->setPreviewURI($this->getApplicationURI('preview/'));
111 $view = id(new PHUITwoColumnView())
118 return $this->newPage()
119 ->setTitle(pht('Edit Answer'))
121 ->appendChild($view);