2012-08-10 10:44:04 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PonderAnswerSaveController extends PonderController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
2013-07-28 15:38:47 -07:00
|
|
|
$viewer = $request->getUser();
|
|
|
|
|
2012-08-10 10:44:04 -07:00
|
|
|
if (!$request->isFormPost()) {
|
|
|
|
return new Aphront400Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$question_id = $request->getInt('question_id');
|
2013-07-28 15:38:47 -07:00
|
|
|
$question = id(new PonderQuestionQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($question_id))
|
|
|
|
->executeOne();
|
2012-08-10 10:44:04 -07:00
|
|
|
if (!$question) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$answer = $request->getStr('answer');
|
|
|
|
|
2012-09-17 13:48:36 -07:00
|
|
|
if (!strlen(trim($answer))) {
|
2013-07-28 15:38:47 -07:00
|
|
|
$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);
|
2012-09-17 13:48:36 -07:00
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
2012-08-10 10:44:04 -07:00
|
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorContentSource::SOURCE_WEB,
|
|
|
|
array(
|
|
|
|
'ip' => $request->getRemoteAddr(),
|
|
|
|
));
|
|
|
|
|
|
|
|
$res = new PonderAnswer();
|
|
|
|
$res
|
|
|
|
->setContent($answer)
|
2013-07-28 15:38:47 -07:00
|
|
|
->setAuthorPHID($viewer->getPHID())
|
2012-08-10 10:44:04 -07:00
|
|
|
->setVoteCount(0)
|
|
|
|
->setQuestionID($question_id)
|
|
|
|
->setContentSource($content_source);
|
|
|
|
|
|
|
|
id(new PonderAnswerEditor())
|
2013-07-28 15:38:47 -07:00
|
|
|
->setActor($viewer)
|
2012-08-10 10:44:04 -07:00
|
|
|
->setQuestion($question)
|
|
|
|
->setAnswer($res)
|
|
|
|
->saveAnswer();
|
|
|
|
|
2012-09-17 13:48:36 -07:00
|
|
|
return id(new AphrontRedirectResponse())->setURI(
|
|
|
|
id(new PhutilURI('/Q'. $question->getID())));
|
2012-08-10 10:44:04 -07:00
|
|
|
}
|
|
|
|
}
|