[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PonderAnswerSaveController extends PonderController { 4 5 public function processRequest() { 6 $request = $this->getRequest(); 7 $viewer = $request->getUser(); 8 9 if (!$request->isFormPost()) { 10 return new Aphront400Response(); 11 } 12 13 $question_id = $request->getInt('question_id'); 14 $question = id(new PonderQuestionQuery()) 15 ->setViewer($viewer) 16 ->withIDs(array($question_id)) 17 ->needAnswers(true) 18 ->executeOne(); 19 if (!$question) { 20 return new Aphront404Response(); 21 } 22 23 $answer = $request->getStr('answer'); 24 25 if (!strlen(trim($answer))) { 26 $dialog = id(new AphrontDialogView()) 27 ->setUser($viewer) 28 ->setTitle(pht('Empty Answer')) 29 ->appendChild( 30 phutil_tag('p', array(), pht( 31 'Your answer must not be empty.'))) 32 ->addCancelButton('/Q'.$question_id); 33 34 return id(new AphrontDialogResponse())->setDialog($dialog); 35 } 36 37 $content_source = PhabricatorContentSource::newForSource( 38 PhabricatorContentSource::SOURCE_WEB, 39 array( 40 'ip' => $request->getRemoteAddr(), 41 )); 42 43 $res = id(new PonderAnswer()) 44 ->setAuthorPHID($viewer->getPHID()) 45 ->setQuestionID($question->getID()) 46 ->setContent($answer) 47 ->setVoteCount(0) 48 ->setContentSource($content_source); 49 50 $xactions = array(); 51 $xactions[] = id(new PonderQuestionTransaction()) 52 ->setTransactionType(PonderQuestionTransaction::TYPE_ANSWERS) 53 ->setNewValue( 54 array( 55 '+' => array( 56 array('answer' => $res), 57 ), 58 )); 59 60 $editor = id(new PonderQuestionEditor()) 61 ->setActor($viewer) 62 ->setContentSourceFromRequest($request); 63 64 $editor->applyTransactions($question, $xactions); 65 66 return id(new AphrontRedirectResponse())->setURI( 67 id(new PhutilURI('/Q'.$question->getID()))); 68 } 69 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |