2011-06-13 01:06:17 +02:00
|
|
|
<?php
|
|
|
|
|
2012-03-10 00:46:25 +01:00
|
|
|
final class PhabricatorCountdownEditController
|
2011-06-13 01:06:17 +02:00
|
|
|
extends PhabricatorCountdownController {
|
|
|
|
|
2015-07-22 22:35:34 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2011-06-13 01:06:17 +02:00
|
|
|
|
2015-07-22 22:35:34 +02:00
|
|
|
if ($id) {
|
2013-08-26 20:53:11 +02:00
|
|
|
$page_title = pht('Edit Countdown');
|
2013-07-22 23:42:25 +02:00
|
|
|
$countdown = id(new PhabricatorCountdownQuery())
|
2015-07-22 22:35:34 +02:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
2013-07-23 15:16:19 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
2013-05-23 15:47:54 +02:00
|
|
|
->executeOne();
|
|
|
|
if (!$countdown) {
|
2011-06-13 01:06:17 +02:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
2015-05-06 04:19:20 +02:00
|
|
|
$date_value = AphrontFormDateControlValue::newFromEpoch(
|
2015-07-22 22:35:34 +02:00
|
|
|
$viewer,
|
2015-05-06 04:19:20 +02:00
|
|
|
$countdown->getEpoch());
|
2015-07-22 22:35:34 +02:00
|
|
|
$v_projects = PhabricatorEdgeQuery::loadDestinationPHIDs(
|
|
|
|
$countdown->getPHID(),
|
|
|
|
PhabricatorProjectObjectHasProjectEdgeType::EDGECONST);
|
|
|
|
$v_projects = array_reverse($v_projects);
|
2011-06-13 01:06:17 +02:00
|
|
|
} else {
|
2013-08-26 20:53:11 +02:00
|
|
|
$page_title = pht('Create Countdown');
|
2015-07-22 22:35:34 +02:00
|
|
|
$countdown = PhabricatorCountdown::initializeNewCountdown($viewer);
|
|
|
|
$date_value = AphrontFormDateControlValue::newFromEpoch(
|
|
|
|
$viewer, PhabricatorTime::getNow());
|
|
|
|
$v_projects = array();
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
|
|
|
|
2014-02-05 14:33:14 +01:00
|
|
|
$errors = array();
|
2015-05-06 04:19:20 +02:00
|
|
|
$e_text = true;
|
|
|
|
$e_epoch = null;
|
|
|
|
|
|
|
|
$v_text = $countdown->getTitle();
|
2015-07-23 19:56:18 +02:00
|
|
|
$v_desc = $countdown->getDescription();
|
2015-07-15 19:17:51 +02:00
|
|
|
$v_space = $countdown->getSpacePHID();
|
2015-07-22 22:35:34 +02:00
|
|
|
$v_view = $countdown->getViewPolicy();
|
|
|
|
$v_edit = $countdown->getEditPolicy();
|
2015-05-06 04:19:20 +02:00
|
|
|
|
2011-06-13 01:06:17 +02:00
|
|
|
if ($request->isFormPost()) {
|
2015-05-06 04:19:20 +02:00
|
|
|
$v_text = $request->getStr('title');
|
2015-07-23 19:56:18 +02:00
|
|
|
$v_desc = $request->getStr('description');
|
2015-07-15 19:17:51 +02:00
|
|
|
$v_space = $request->getStr('spacePHID');
|
2015-05-06 04:19:20 +02:00
|
|
|
$date_value = AphrontFormDateControlValue::newFromRequest(
|
|
|
|
$request,
|
|
|
|
'epoch');
|
2015-07-22 22:35:34 +02:00
|
|
|
$v_view = $request->getStr('viewPolicy');
|
|
|
|
$v_edit = $request->getStr('editPolicy');
|
|
|
|
$v_projects = $request->getArr('projects');
|
2011-06-13 01:06:17 +02:00
|
|
|
|
2015-07-22 22:35:34 +02:00
|
|
|
$type_title = PhabricatorCountdownTransaction::TYPE_TITLE;
|
|
|
|
$type_epoch = PhabricatorCountdownTransaction::TYPE_EPOCH;
|
2015-07-23 19:56:18 +02:00
|
|
|
$type_description = PhabricatorCountdownTransaction::TYPE_DESCRIPTION;
|
2015-07-22 22:35:34 +02:00
|
|
|
$type_space = PhabricatorTransactions::TYPE_SPACE;
|
|
|
|
$type_view = PhabricatorTransactions::TYPE_VIEW_POLICY;
|
|
|
|
$type_edit = PhabricatorTransactions::TYPE_EDIT_POLICY;
|
|
|
|
|
|
|
|
$xactions = array();
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorCountdownTransaction())
|
|
|
|
->setTransactionType($type_title)
|
|
|
|
->setNewValue($v_text);
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorCountdownTransaction())
|
|
|
|
->setTransactionType($type_epoch)
|
|
|
|
->setNewValue($date_value);
|
|
|
|
|
2015-07-23 19:56:18 +02:00
|
|
|
$xactions[] = id(new PhabricatorCountdownTransaction())
|
|
|
|
->setTransactionType($type_description)
|
|
|
|
->setNewValue($v_desc);
|
|
|
|
|
2015-07-22 22:35:34 +02:00
|
|
|
$xactions[] = id(new PhabricatorCountdownTransaction())
|
|
|
|
->setTransactionType($type_space)
|
|
|
|
->setNewValue($v_space);
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorCountdownTransaction())
|
|
|
|
->setTransactionType($type_view)
|
|
|
|
->setNewValue($v_view);
|
|
|
|
|
|
|
|
$xactions[] = id(new PhabricatorCountdownTransaction())
|
|
|
|
->setTransactionType($type_edit)
|
|
|
|
->setNewValue($v_edit);
|
|
|
|
|
|
|
|
$proj_edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST;
|
|
|
|
$xactions[] = id(new PhabricatorCountdownTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
|
|
|
|
->setMetadataValue('edge:type', $proj_edge_type)
|
|
|
|
->setNewValue(array('=' => array_fuse($v_projects)));
|
|
|
|
|
|
|
|
$editor = id(new PhabricatorCountdownEditor())
|
|
|
|
->setActor($viewer)
|
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true);
|
|
|
|
|
|
|
|
try {
|
|
|
|
$editor->applyTransactions($countdown, $xactions);
|
2011-06-13 01:06:17 +02:00
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
2015-07-22 22:35:34 +02:00
|
|
|
->setURI('/'.$countdown->getMonogram());
|
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
$validation_exception = $ex;
|
|
|
|
|
|
|
|
$e_title = $ex->getShortMessage($type_title);
|
|
|
|
$e_epoch = $ex->getShortMessage($type_epoch);
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
2015-07-22 22:35:34 +02:00
|
|
|
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
|
|
|
|
2013-07-23 15:16:19 +02:00
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
|
|
|
|
$cancel_uri = '/countdown/';
|
|
|
|
if ($countdown->getID()) {
|
|
|
|
$cancel_uri = '/countdown/'.$countdown->getID().'/';
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb('C'.$countdown->getID(), $cancel_uri);
|
|
|
|
$crumbs->addTextCrumb(pht('Edit'));
|
2013-07-23 15:16:19 +02:00
|
|
|
$submit_label = pht('Save Changes');
|
|
|
|
} else {
|
2013-12-19 02:47:34 +01:00
|
|
|
$crumbs->addTextCrumb(pht('Create Countdown'));
|
2013-07-23 15:16:19 +02:00
|
|
|
$submit_label = pht('Create Countdown');
|
|
|
|
}
|
|
|
|
|
2013-10-16 19:36:08 +02:00
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
2015-07-22 22:35:34 +02:00
|
|
|
->setViewer($viewer)
|
2013-10-16 19:36:08 +02:00
|
|
|
->setObject($countdown)
|
|
|
|
->execute();
|
2013-07-23 15:16:19 +02:00
|
|
|
|
2011-06-13 01:06:17 +02:00
|
|
|
$form = id(new AphrontFormView())
|
2015-07-22 22:35:34 +02:00
|
|
|
->setUser($viewer)
|
2011-06-13 01:06:17 +02:00
|
|
|
->setAction($request->getRequestURI()->getPath())
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
2013-02-25 21:48:55 +01:00
|
|
|
->setLabel(pht('Title'))
|
2015-05-06 04:19:20 +02:00
|
|
|
->setValue($v_text)
|
2013-10-16 19:36:08 +02:00
|
|
|
->setName('title')
|
|
|
|
->setError($e_text))
|
2015-07-22 22:35:34 +02:00
|
|
|
->appendControl(
|
2015-05-06 04:19:20 +02:00
|
|
|
id(new AphrontFormDateControl())
|
|
|
|
->setName('epoch')
|
|
|
|
->setLabel(pht('End Date'))
|
|
|
|
->setError($e_epoch)
|
|
|
|
->setValue($date_value))
|
2015-07-23 19:56:18 +02:00
|
|
|
->appendControl(
|
|
|
|
id(new PhabricatorRemarkupControl())
|
|
|
|
->setName('description')
|
|
|
|
->setLabel(pht('Description'))
|
|
|
|
->setValue($v_desc))
|
2015-07-22 22:35:34 +02:00
|
|
|
->appendControl(
|
2013-10-16 19:36:08 +02:00
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setName('viewPolicy')
|
|
|
|
->setPolicyObject($countdown)
|
|
|
|
->setPolicies($policies)
|
2015-07-15 19:17:51 +02:00
|
|
|
->setSpacePHID($v_space)
|
2015-07-22 22:35:34 +02:00
|
|
|
->setValue($v_view)
|
2013-10-16 19:36:08 +02:00
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW))
|
2015-07-22 22:35:34 +02:00
|
|
|
->appendControl(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setName('editPolicy')
|
|
|
|
->setPolicyObject($countdown)
|
|
|
|
->setPolicies($policies)
|
|
|
|
->setValue($v_edit)
|
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_EDIT))
|
|
|
|
->appendControl(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setLabel(pht('Projects'))
|
|
|
|
->setName('projects')
|
|
|
|
->setValue($v_projects)
|
|
|
|
->setDatasource(new PhabricatorProjectDatasource()))
|
2011-06-13 01:06:17 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSubmitControl())
|
2013-07-23 15:16:19 +02:00
|
|
|
->addCancelButton($cancel_uri)
|
|
|
|
->setValue($submit_label));
|
|
|
|
|
2013-09-25 20:23:29 +02:00
|
|
|
$form_box = id(new PHUIObjectBoxView())
|
2013-08-26 20:53:11 +02:00
|
|
|
->setHeaderText($page_title)
|
2014-01-10 18:17:37 +01:00
|
|
|
->setFormErrors($errors)
|
2013-08-26 20:53:11 +02:00
|
|
|
->setForm($form);
|
2013-02-25 21:48:55 +01:00
|
|
|
|
2015-11-29 00:41:29 +01:00
|
|
|
return $this->newPage()
|
|
|
|
->setTitle($page_title)
|
|
|
|
->setCrumbs($crumbs)
|
|
|
|
->appendChild(
|
|
|
|
array(
|
|
|
|
$form_box,
|
|
|
|
));
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|
2014-07-10 00:12:48 +02:00
|
|
|
|
2011-06-13 01:06:17 +02:00
|
|
|
}
|