1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 02:02:41 +01:00
phorge-phorge/src/applications/ponder/controller/PonderAnswerSaveController.php
epriestley 8fa5944768 Make adding an answer to a Ponder question a QuestionTransaction operation
Summary: Ref T3578. This is currently handled in a weird way in the Answer transaction. Instead, make it a Question transaction so, e.g., viewing Question transaction history shows who added answers and when.

Test Plan: Added answers to questions in Ponder.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3578

Differential Revision: https://secure.phabricator.com/D6603
2013-07-29 12:03:48 -07:00

69 lines
1.9 KiB
PHP

<?php
final class PonderAnswerSaveController extends PonderController {
public function processRequest() {
$request = $this->getRequest();
$viewer = $request->getUser();
if (!$request->isFormPost()) {
return new Aphront400Response();
}
$question_id = $request->getInt('question_id');
$question = id(new PonderQuestionQuery())
->setViewer($viewer)
->withIDs(array($question_id))
->needAnswers(true)
->executeOne();
if (!$question) {
return new Aphront404Response();
}
$answer = $request->getStr('answer');
if (!strlen(trim($answer))) {
$dialog = id(new AphrontDialogView())
->setUser($viewer)
->setTitle(pht('Empty Answer'))
->appendChild(
phutil_tag('p', array(), pht(
'Your answer must not be empty.')))
->addCancelButton('/Q'.$question_id);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_WEB,
array(
'ip' => $request->getRemoteAddr(),
));
$res = id(new PonderAnswer())
->setAuthorPHID($viewer->getPHID())
->setQuestionID($question->getID())
->setContent($answer)
->setVoteCount(0)
->setContentSource($content_source);
$xactions = array();
$xactions[] = id(new PonderQuestionTransaction())
->setTransactionType(PonderQuestionTransaction::TYPE_ANSWERS)
->setNewValue(
array(
'+' => array(
array('answer' => $res),
),
));
$editor = id(new PonderQuestionEditor())
->setActor($viewer)
->setContentSourceFromRequest($request);
$editor->applyTransactions($question, $xactions);
return id(new AphrontRedirectResponse())->setURI(
id(new PhutilURI('/Q'.$question->getID())));
}
}