3 final class PonderAnswerSaveController
extends PonderController
{
5 public function handleRequest(AphrontRequest
$request) {
6 $viewer = $request->getViewer();
8 if (!$request->isFormPost()) {
9 return new Aphront400Response();
12 $question_id = $request->getInt('question_id');
13 $question = id(new PonderQuestionQuery())
15 ->withIDs(array($question_id))
19 return new Aphront404Response();
22 $content = $request->getStr('answer');
24 if (!strlen(trim($content))) {
25 $dialog = id(new AphrontDialogView())
27 ->setTitle(pht('Empty Answer'))
29 phutil_tag('p', array(), pht('Your answer must not be empty.')))
30 ->addCancelButton('/Q'.$question_id);
32 return id(new AphrontDialogResponse())->setDialog($dialog);
35 $answer = PonderAnswer
::initializeNewAnswer($viewer, $question);
40 $xactions[] = id(new PonderQuestionTransaction())
41 ->setTransactionType(PonderQuestionAnswerTransaction
::TRANSACTIONTYPE
)
45 array('answer' => $answer),
49 $editor = id(new PonderQuestionEditor())
51 ->setContentSourceFromRequest($request);
53 $editor->applyTransactions($question, $xactions);
57 $template = id(new PonderAnswerTransaction());
60 $xactions[] = id(clone $template)
61 ->setTransactionType(PonderAnswerQuestionIDTransaction
::TRANSACTIONTYPE
)
62 ->setNewValue($question->getID());
64 $xactions[] = id(clone $template)
65 ->setTransactionType(PonderAnswerContentTransaction
::TRANSACTIONTYPE
)
66 ->setNewValue($content);
68 $editor = id(new PonderAnswerEditor())
70 ->setContentSourceFromRequest($request)
71 ->setContinueOnNoEffect(true);
73 $editor->applyTransactions($answer, $xactions);
76 return id(new AphrontRedirectResponse())->setURI(
77 id(new PhutilURI('/Q'.$question->getID())));