2012-08-10 19:44:04 +02:00
|
|
|
<?php
|
|
|
|
|
2013-07-29 00:02:18 +02:00
|
|
|
final class PonderQuestionEditController extends PonderController {
|
|
|
|
|
2015-07-22 22:23:11 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
2015-08-05 00:41:09 +02:00
|
|
|
$viewer = $request->getViewer();
|
2015-07-22 22:23:11 +02:00
|
|
|
$id = $request->getURIData('id');
|
2013-07-29 00:02:18 +02:00
|
|
|
|
2015-07-22 22:23:11 +02:00
|
|
|
if ($id) {
|
2013-07-29 00:02:18 +02:00
|
|
|
$question = id(new PonderQuestionQuery())
|
2015-08-05 00:41:09 +02:00
|
|
|
->setViewer($viewer)
|
2015-07-22 22:23:11 +02:00
|
|
|
->withIDs(array($id))
|
2013-07-29 00:02:18 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
if (!$question) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2014-06-10 20:18:03 +02:00
|
|
|
$v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
|
|
|
$question->getPHID(),
|
2014-07-18 00:42:19 +02:00
|
|
|
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
|
2014-06-10 20:18:03 +02:00
|
|
|
$v_projects = array_reverse($v_projects);
|
2015-08-14 03:23:33 +02:00
|
|
|
$is_new = false;
|
2013-07-29 00:02:18 +02:00
|
|
|
} else {
|
2015-08-14 03:23:33 +02:00
|
|
|
$is_new = true;
|
2015-08-05 00:41:09 +02:00
|
|
|
$question = PonderQuestion::initializeNewQuestion($viewer);
|
2014-06-10 20:18:03 +02:00
|
|
|
$v_projects = array();
|
2013-07-29 00:02:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$v_title = $question->getTitle();
|
|
|
|
$v_content = $question->getContent();
|
2015-08-29 22:59:33 +02:00
|
|
|
$v_wiki = $question->getAnswerWiki();
|
2015-08-05 00:41:09 +02:00
|
|
|
$v_view = $question->getViewPolicy();
|
2015-08-05 18:38:14 +02:00
|
|
|
$v_space = $question->getSpacePHID();
|
2015-08-08 19:23:33 +02:00
|
|
|
$v_status = $question->getStatus();
|
|
|
|
|
2012-08-10 19:44:04 +02:00
|
|
|
|
2012-10-01 05:09:18 +02:00
|
|
|
$errors = array();
|
|
|
|
$e_title = true;
|
|
|
|
if ($request->isFormPost()) {
|
2013-07-29 00:02:18 +02:00
|
|
|
$v_title = $request->getStr('title');
|
|
|
|
$v_content = $request->getStr('content');
|
2015-08-29 22:59:33 +02:00
|
|
|
$v_wiki = $request->getStr('answerWiki');
|
2014-06-10 20:18:03 +02:00
|
|
|
$v_projects = $request->getArr('projects');
|
2015-08-05 00:41:09 +02:00
|
|
|
$v_view = $request->getStr('viewPolicy');
|
2015-08-05 18:38:14 +02:00
|
|
|
$v_space = $request->getStr('spacePHID');
|
2015-08-08 19:23:33 +02:00
|
|
|
$v_status = $request->getStr('status');
|
2012-10-01 05:09:18 +02:00
|
|
|
|
2013-07-29 00:02:18 +02:00
|
|
|
$len = phutil_utf8_strlen($v_title);
|
2012-10-01 05:09:18 +02:00
|
|
|
if ($len < 1) {
|
|
|
|
$errors[] = pht('Title must not be empty.');
|
|
|
|
$e_title = pht('Required');
|
|
|
|
} else if ($len > 255) {
|
|
|
|
$errors[] = pht('Title is too long.');
|
|
|
|
$e_title = pht('Too Long');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$errors) {
|
2013-07-29 00:02:18 +02:00
|
|
|
$template = id(new PonderQuestionTransaction());
|
|
|
|
$xactions = array();
|
2012-10-01 05:09:18 +02:00
|
|
|
|
2013-07-29 00:02:18 +02:00
|
|
|
$xactions[] = id(clone $template)
|
2017-05-01 20:16:38 +02:00
|
|
|
->setTransactionType(PonderQuestionTitleTransaction::TRANSACTIONTYPE)
|
2013-07-29 00:02:18 +02:00
|
|
|
->setNewValue($v_title);
|
|
|
|
|
|
|
|
$xactions[] = id(clone $template)
|
2017-05-01 20:16:38 +02:00
|
|
|
->setTransactionType(
|
|
|
|
PonderQuestionContentTransaction::TRANSACTIONTYPE)
|
2013-07-29 00:02:18 +02:00
|
|
|
->setNewValue($v_content);
|
|
|
|
|
2015-08-29 22:59:33 +02:00
|
|
|
$xactions[] = id(clone $template)
|
2017-05-01 20:16:38 +02:00
|
|
|
->setTransactionType(
|
|
|
|
PonderQuestionAnswerWikiTransaction::TRANSACTIONTYPE)
|
2015-08-29 22:59:33 +02:00
|
|
|
->setNewValue($v_wiki);
|
|
|
|
|
2015-08-14 18:51:52 +02:00
|
|
|
if (!$is_new) {
|
|
|
|
$xactions[] = id(clone $template)
|
2017-05-01 20:16:38 +02:00
|
|
|
->setTransactionType(
|
|
|
|
PonderQuestionStatusTransaction::TRANSACTIONTYPE)
|
2015-08-14 18:51:52 +02:00
|
|
|
->setNewValue($v_status);
|
|
|
|
}
|
2015-08-08 19:23:33 +02:00
|
|
|
|
2015-08-05 00:41:09 +02:00
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
|
|
|
->setNewValue($v_view);
|
|
|
|
|
2015-08-05 18:38:14 +02:00
|
|
|
$xactions[] = id(clone $template)
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_SPACE)
|
|
|
|
->setNewValue($v_space);
|
|
|
|
|
2014-07-18 00:42:19 +02:00
|
|
|
$proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
|
2014-06-10 20:18:03 +02:00
|
|
|
$xactions[] = id(new PonderQuestionTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
|
|
|
->setMetadataValue('edge:type', $proj_edge_type)
|
|
|
|
->setNewValue(array('=' => array_fuse($v_projects)));
|
|
|
|
|
2013-07-29 00:02:18 +02:00
|
|
|
$editor = id(new PonderQuestionEditor())
|
2015-08-05 00:41:09 +02:00
|
|
|
->setActor($viewer)
|
2013-07-29 00:02:18 +02:00
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true);
|
|
|
|
|
|
|
|
$editor->applyTransactions($question, $xactions);
|
2012-10-01 05:09:18 +02:00
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
|
|
->setURI('/Q'.$question->getID());
|
|
|
|
}
|
|
|
|
}
|
2012-08-10 19:44:04 +02:00
|
|
|
|
2015-08-05 00:41:09 +02:00
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->setObject($question)
|
|
|
|
->execute();
|
|
|
|
|
2012-10-01 05:09:18 +02:00
|
|
|
$form = id(new AphrontFormView())
|
2015-08-05 00:41:09 +02:00
|
|
|
->setUser($viewer)
|
2012-08-10 19:44:04 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2012-10-01 05:09:18 +02:00
|
|
|
->setLabel(pht('Question'))
|
2012-08-10 19:44:04 +02:00
|
|
|
->setName('title')
|
2013-07-29 00:02:18 +02:00
|
|
|
->setValue($v_title)
|
2012-10-01 05:09:18 +02:00
|
|
|
->setError($e_title))
|
2012-08-10 19:44:04 +02:00
|
|
|
->appendChild(
|
2012-09-19 21:27:28 +02:00
|
|
|
id(new PhabricatorRemarkupControl())
|
2015-08-05 00:41:09 +02:00
|
|
|
->setUser($viewer)
|
2012-08-10 19:44:04 +02:00
|
|
|
->setName('content')
|
|
|
|
->setID('content')
|
2013-07-29 00:02:18 +02:00
|
|
|
->setValue($v_content)
|
2015-08-29 22:59:33 +02:00
|
|
|
->setLabel(pht('Question Details'))
|
|
|
|
->setUser($viewer))
|
|
|
|
->appendChild(
|
|
|
|
id(new PhabricatorRemarkupControl())
|
|
|
|
->setUser($viewer)
|
|
|
|
->setName('answerWiki')
|
|
|
|
->setID('answerWiki')
|
|
|
|
->setValue($v_wiki)
|
|
|
|
->setLabel(pht('Answer Summary'))
|
2015-08-05 00:41:09 +02:00
|
|
|
->setUser($viewer))
|
|
|
|
->appendControl(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setName('viewPolicy')
|
|
|
|
->setPolicyObject($question)
|
2015-08-05 18:38:14 +02:00
|
|
|
->setSpacePHID($v_space)
|
2015-08-05 00:41:09 +02:00
|
|
|
->setPolicies($policies)
|
|
|
|
->setValue($v_view)
|
2015-08-14 03:23:33 +02:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW));
|
|
|
|
|
|
|
|
|
|
|
|
if (!$is_new) {
|
|
|
|
$form->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('Status'))
|
|
|
|
->setName('status')
|
|
|
|
->setValue($v_status)
|
|
|
|
->setOptions(PonderQuestionStatus::getQuestionStatusMap()));
|
|
|
|
}
|
2014-06-10 20:18:03 +02:00
|
|
|
|
2015-03-31 23:10:55 +02:00
|
|
|
$form->appendControl(
|
2014-06-10 20:18:03 +02:00
|
|
|
id(new AphrontFormTokenizerControl())
|
Consistently refer to 'Projects' as 'Tags'
Summary:
In calendar, dashboard, diffusion, diviner, feed, fund,
maniphest, pholio, ponder, and slowvote use the term 'tags' if possible.
This intenctionally skips diffusion, differential, and the projects application itself.
Ref T10326 Ref T10349
Test Plan: inspection on a running, locally modified, system
Reviewers: avivey, epriestley, #blessed_reviewers
Reviewed By: epriestley, #blessed_reviewers
Subscribers: Korvin
Maniphest Tasks: T10835, T10326, T10349
Differential Revision: https://secure.phabricator.com/D15753
2016-04-19 18:48:21 +02:00
|
|
|
->setLabel(pht('Tags'))
|
2014-06-10 20:18:03 +02:00
|
|
|
->setName('projects')
|
2015-03-31 23:10:55 +02:00
|
|
|
->setValue($v_projects)
|
2014-07-11 02:28:29 +02:00
|
|
|
->setDatasource(new PhabricatorProjectDatasource()));
|
2014-06-10 20:18:03 +02:00
|
|
|
|
2015-08-08 02:19:44 +02:00
|
|
|
$form->appendChild(
|
2014-06-10 20:18:03 +02:00
|
|
|
id(new AphrontFormSubmitControl())
|
|
|
|
->addCancelButton($this->getApplicationURI())
|
2015-08-14 03:23:33 +02:00
|
|
|
->setValue(pht('Submit')));
|
2012-08-10 19:44:04 +02:00
|
|
|
|
2013-08-05 19:47:06 +02:00
|
|
|
$preview = id(new PHUIRemarkupPreviewPanel())
|
|
|
|
->setHeader(pht('Question Preview'))
|
|
|
|
->setControlID('content')
|
|
|
|
->setPreviewURI($this->getApplicationURI('preview/'));
|
2012-08-10 19:44:04 +02:00
|
|
|
|
2015-08-29 22:59:33 +02:00
|
|
|
$answer_preview = id(new PHUIRemarkupPreviewPanel())
|
|
|
|
->setHeader(pht('Answer Summary Preview'))
|
|
|
|
->setControlID('answerWiki')
|
|
|
|
->setPreviewURI($this->getApplicationURI('preview/'));
|
|
|
|
|
2013-07-18 21:40:51 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
2013-07-29 00:02:18 +02:00
|
|
|
|
|
|
|
$id = $question->getID();
|
|
|
|
if ($id) {
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb("Q{$id}", "/Q{$id}");
|
|
|
|
$crumbs->addTextCrumb(pht('Edit'));
|
2015-08-08 19:23:33 +02:00
|
|
|
$title = pht('Edit Question');
|
2016-03-27 22:07:53 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader($title)
|
|
|
|
->setHeaderIcon('fa-pencil');
|
2013-07-29 00:02:18 +02:00
|
|
|
} else {
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('Ask Question'));
|
2015-08-08 19:23:33 +02:00
|
|
|
$title = pht('Ask New Question');
|
2016-03-27 22:07:53 +02:00
|
|
|
$header = id(new PHUIHeaderView())
|
|
|
|
->setHeader($title)
|
|
|
|
->setHeaderIcon('fa-plus-square');
|
2013-07-29 00:02:18 +02:00
|
|
|
}
|
2016-03-27 22:07:53 +02:00
|
|
|
$crumbs->setBorder(true);
|
2012-10-01 05:09:18 +02:00
|
|
|
|
2016-03-27 22:07:53 +02:00
|
|
|
$box = id(new PHUIObjectBoxView())
|
|
|
|
->setHeaderText(pht('Question'))
|
2015-08-08 19:23:33 +02:00
|
|
|
->setFormErrors($errors)
|
2016-03-27 22:07:53 +02:00
|
|
|
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY)
|
2015-08-08 19:23:33 +02:00
|
|
|
->setForm($form);
|
|
|
|
|
2016-03-27 22:07:53 +02:00
|
|
|
$view = id(new PHUITwoColumnView())
|
|
|
|
->setHeader($header)
|
|
|
|
->setFooter(array(
|
|
|
|
$box,
|
2012-10-01 05:09:18 +02:00
|
|
|
$preview,
|
2015-08-29 22:59:33 +02:00
|
|
|
$answer_preview,
|
2013-02-19 22:33:10 +01:00
|
|
|
));
|
2016-03-27 22:07:53 +02:00
|
|
|
|
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($title)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild($view);
|
|
|
|
|
2012-08-10 19:44:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|