Changeset View
Changeset View
Standalone View
Standalone View
src/applications/ponder/controller/PonderQuestionEditController.php
Show All 19 Lines | if ($this->id) { | ||||
array( | array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
)) | )) | ||||
->executeOne(); | ->executeOne(); | ||||
if (!$question) { | if (!$question) { | ||||
return new Aphront404Response(); | return new Aphront404Response(); | ||||
} | } | ||||
$v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs( | |||||
$question->getPHID(), | |||||
PhabricatorEdgeConfig::TYPE_OBJECT_HAS_PROJECT); | |||||
$v_projects = array_reverse($v_projects); | |||||
} else { | } else { | ||||
$question = id(new PonderQuestion()) | $question = id(new PonderQuestion()) | ||||
->setStatus(PonderQuestionStatus::STATUS_OPEN) | ->setStatus(PonderQuestionStatus::STATUS_OPEN) | ||||
->setAuthorPHID($user->getPHID()) | ->setAuthorPHID($user->getPHID()) | ||||
->setVoteCount(0) | ->setVoteCount(0) | ||||
->setAnswerCount(0) | ->setAnswerCount(0) | ||||
->setHeat(0.0); | ->setHeat(0.0); | ||||
$v_projects = array(); | |||||
} | } | ||||
$v_title = $question->getTitle(); | $v_title = $question->getTitle(); | ||||
$v_content = $question->getContent(); | $v_content = $question->getContent(); | ||||
$errors = array(); | $errors = array(); | ||||
$e_title = true; | $e_title = true; | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$v_title = $request->getStr('title'); | $v_title = $request->getStr('title'); | ||||
$v_content = $request->getStr('content'); | $v_content = $request->getStr('content'); | ||||
$v_projects = $request->getArr('projects'); | |||||
$len = phutil_utf8_strlen($v_title); | $len = phutil_utf8_strlen($v_title); | ||||
if ($len < 1) { | if ($len < 1) { | ||||
$errors[] = pht('Title must not be empty.'); | $errors[] = pht('Title must not be empty.'); | ||||
$e_title = pht('Required'); | $e_title = pht('Required'); | ||||
} else if ($len > 255) { | } else if ($len > 255) { | ||||
$errors[] = pht('Title is too long.'); | $errors[] = pht('Title is too long.'); | ||||
$e_title = pht('Too Long'); | $e_title = pht('Too Long'); | ||||
} | } | ||||
if (!$errors) { | if (!$errors) { | ||||
$template = id(new PonderQuestionTransaction()); | $template = id(new PonderQuestionTransaction()); | ||||
$xactions = array(); | $xactions = array(); | ||||
$xactions[] = id(clone $template) | $xactions[] = id(clone $template) | ||||
->setTransactionType(PonderQuestionTransaction::TYPE_TITLE) | ->setTransactionType(PonderQuestionTransaction::TYPE_TITLE) | ||||
->setNewValue($v_title); | ->setNewValue($v_title); | ||||
$xactions[] = id(clone $template) | $xactions[] = id(clone $template) | ||||
->setTransactionType(PonderQuestionTransaction::TYPE_CONTENT) | ->setTransactionType(PonderQuestionTransaction::TYPE_CONTENT) | ||||
->setNewValue($v_content); | ->setNewValue($v_content); | ||||
$proj_edge_type = PhabricatorEdgeConfig::TYPE_OBJECT_HAS_PROJECT; | |||||
$xactions[] = id(new PonderQuestionTransaction()) | |||||
->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | |||||
->setMetadataValue('edge:type', $proj_edge_type) | |||||
->setNewValue(array('=' => array_fuse($v_projects))); | |||||
$editor = id(new PonderQuestionEditor()) | $editor = id(new PonderQuestionEditor()) | ||||
->setActor($user) | ->setActor($user) | ||||
->setContentSourceFromRequest($request) | ->setContentSourceFromRequest($request) | ||||
->setContinueOnNoEffect(true); | ->setContinueOnNoEffect(true); | ||||
$editor->applyTransactions($question, $xactions); | $editor->applyTransactions($question, $xactions); | ||||
return id(new AphrontRedirectResponse()) | return id(new AphrontRedirectResponse()) | ||||
Show All 10 Lines | $form = id(new AphrontFormView()) | ||||
->setValue($v_title) | ->setValue($v_title) | ||||
->setError($e_title)) | ->setError($e_title)) | ||||
->appendChild( | ->appendChild( | ||||
id(new PhabricatorRemarkupControl()) | id(new PhabricatorRemarkupControl()) | ||||
->setName('content') | ->setName('content') | ||||
->setID('content') | ->setID('content') | ||||
->setValue($v_content) | ->setValue($v_content) | ||||
->setLabel(pht('Description')) | ->setLabel(pht('Description')) | ||||
->setUser($user)) | ->setUser($user)); | ||||
->appendChild( | |||||
if ($v_projects) { | |||||
$project_handles = $this->loadViewerHandles($v_projects); | |||||
} else { | |||||
$project_handles = array(); | |||||
} | |||||
$form->appendChild( | |||||
id(new AphrontFormTokenizerControl()) | |||||
->setLabel(pht('Projects')) | |||||
->setName('projects') | |||||
->setValue($project_handles) | |||||
->setDatasource('/typeahead/common/projects/')); | |||||
$form ->appendChild( | |||||
id(new AphrontFormSubmitControl()) | id(new AphrontFormSubmitControl()) | ||||
->addCancelButton($this->getApplicationURI()) | ->addCancelButton($this->getApplicationURI()) | ||||
->setValue(pht('Ask Away!'))); | ->setValue(pht('Ask Away!'))); | ||||
$preview = id(new PHUIRemarkupPreviewPanel()) | $preview = id(new PHUIRemarkupPreviewPanel()) | ||||
->setHeader(pht('Question Preview')) | ->setHeader(pht('Question Preview')) | ||||
->setControlID('content') | ->setControlID('content') | ||||
->setPreviewURI($this->getApplicationURI('preview/')); | ->setPreviewURI($this->getApplicationURI('preview/')); | ||||
$form_box = id(new PHUIObjectBoxView()) | $form_box = id(new PHUIObjectBoxView()) | ||||
->setHeaderText(pht('Ask New Question')) | ->setHeaderText(pht('Ask New Question')) | ||||
Show All 26 Lines |