[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PonderAnswerEditController extends PonderController { 4 5 private $id; 6 7 public function willProcessRequest(array $data) { 8 $this->id = $data['id']; 9 } 10 11 public function processRequest() { 12 $request = $this->getRequest(); 13 $viewer = $request->getUser(); 14 15 $answer = id(new PonderAnswerQuery()) 16 ->setViewer($viewer) 17 ->withIDs(array($this->id)) 18 ->requireCapabilities( 19 array( 20 PhabricatorPolicyCapability::CAN_VIEW, 21 PhabricatorPolicyCapability::CAN_EDIT, 22 )) 23 ->executeOne(); 24 if (!$answer) { 25 return new Aphront404Response(); 26 } 27 28 $v_content = $answer->getContent(); 29 $e_content = true; 30 31 32 $question = $answer->getQuestion(); 33 $qid = $question->getID(); 34 35 $answer_uri = $answer->getURI(); 36 37 $errors = array(); 38 if ($request->isFormPost()) { 39 $v_content = $request->getStr('content'); 40 41 if (!strlen($v_content)) { 42 $errors[] = pht('You must provide some substance in your answer.'); 43 $e_content = pht('Required'); 44 } 45 46 if (!$errors) { 47 $xactions = array(); 48 $xactions[] = id(new PonderAnswerTransaction()) 49 ->setTransactionType(PonderAnswerTransaction::TYPE_CONTENT) 50 ->setNewValue($v_content); 51 52 $editor = id(new PonderAnswerEditor()) 53 ->setActor($viewer) 54 ->setContentSourceFromRequest($request) 55 ->setContinueOnNoEffect(true); 56 57 $editor->applyTransactions($answer, $xactions); 58 59 return id(new AphrontRedirectResponse()) 60 ->setURI($answer_uri); 61 } 62 } 63 64 $answer_content_id = celerity_generate_unique_node_id(); 65 66 $form = id(new AphrontFormView()) 67 ->setUser($viewer) 68 ->appendChild( 69 id(new AphrontFormStaticControl()) 70 ->setLabel(pht('Question')) 71 ->setValue($question->getTitle())) 72 ->appendChild( 73 id(new PhabricatorRemarkupControl()) 74 ->setUser($viewer) 75 ->setLabel(pht('Answer')) 76 ->setName('content') 77 ->setID($answer_content_id) 78 ->setValue($v_content) 79 ->setError($e_content)) 80 ->appendChild( 81 id(new AphrontFormSubmitControl()) 82 ->setValue(pht('Update Answer')) 83 ->addCancelButton($answer_uri)); 84 85 $crumbs = $this->buildApplicationCrumbs(); 86 $crumbs->addTextCrumb("Q{$qid}", $answer_uri); 87 $crumbs->addTextCrumb(pht('Edit Answer')); 88 89 $form_box = id(new PHUIObjectBoxView()) 90 ->setHeaderText(pht('Edit Answer')) 91 ->setFormErrors($errors) 92 ->setForm($form); 93 94 $preview = id(new PHUIRemarkupPreviewPanel()) 95 ->setHeader(pht('Answer Preview')) 96 ->setControlID($answer_content_id) 97 ->setPreviewURI($this->getApplicationURI('preview/')); 98 99 return $this->buildApplicationPage( 100 array( 101 $crumbs, 102 $form_box, 103 $preview, 104 ), 105 array( 106 'title' => pht('Edit Answer'), 107 )); 108 109 } 110 }
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 |