2015-03-24 21:04:33 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class ConpherenceNewRoomController extends ConpherenceController {
|
|
|
|
|
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$title = pht('New Room');
|
|
|
|
$e_title = true;
|
|
|
|
$validation_exception = null;
|
|
|
|
|
|
|
|
$conpherence = ConpherenceThread::initializeNewRoom($user);
|
2015-06-25 22:14:20 +02:00
|
|
|
$participants = array();
|
2015-03-24 21:04:33 +01:00
|
|
|
if ($request->isFormPost()) {
|
2015-06-25 22:14:20 +02:00
|
|
|
$editor = new ConpherenceEditor();
|
2015-03-24 21:04:33 +01:00
|
|
|
$xactions = array();
|
2015-06-25 22:14:20 +02:00
|
|
|
|
2016-09-16 23:24:39 +02:00
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
2017-04-13 01:33:43 +02:00
|
|
|
->setTransactionType(ConpherenceThreadTitleTransaction::TRANSACTIONTYPE)
|
2016-09-16 23:24:39 +02:00
|
|
|
->setNewValue($request->getStr('title'));
|
|
|
|
|
2015-06-25 22:14:20 +02:00
|
|
|
$participants = $request->getArr('participants');
|
|
|
|
$participants[] = $user->getPHID();
|
|
|
|
$participants = array_unique($participants);
|
2015-03-24 21:04:33 +01:00
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
2015-06-08 01:54:53 +02:00
|
|
|
->setTransactionType(ConpherenceTransaction::TYPE_PARTICIPANTS)
|
2015-06-25 22:14:20 +02:00
|
|
|
->setNewValue(array('+' => $participants));
|
2016-09-15 03:34:11 +02:00
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
2017-04-13 01:33:43 +02:00
|
|
|
->setTransactionType(ConpherenceThreadTopicTransaction::TRANSACTIONTYPE)
|
2016-09-15 03:34:11 +02:00
|
|
|
->setNewValue($request->getStr('topic'));
|
2015-03-24 21:04:33 +01:00
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_VIEW_POLICY)
|
|
|
|
->setNewValue($request->getStr('viewPolicy'));
|
|
|
|
$xactions[] = id(new ConpherenceTransaction())
|
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_EDIT_POLICY)
|
|
|
|
->setNewValue($request->getStr('editPolicy'));
|
|
|
|
|
|
|
|
try {
|
2015-06-25 22:14:20 +02:00
|
|
|
$editor
|
2015-03-24 21:04:33 +01:00
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setActor($user)
|
|
|
|
->applyTransactions($conpherence, $xactions);
|
|
|
|
|
|
|
|
return id(new AphrontRedirectResponse())
|
2015-05-08 23:59:11 +02:00
|
|
|
->setURI('/'.$conpherence->getMonogram());
|
2015-03-24 21:04:33 +01:00
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
$validation_exception = $ex;
|
|
|
|
|
2017-04-13 01:33:43 +02:00
|
|
|
$e_title = $ex->getShortMessage(
|
|
|
|
ConpherenceThreadTitleTransaction::TRANSACTIONTYPE);
|
2015-03-24 21:04:33 +01:00
|
|
|
|
|
|
|
$conpherence->setViewPolicy($request->getStr('viewPolicy'));
|
|
|
|
$conpherence->setEditPolicy($request->getStr('editPolicy'));
|
|
|
|
}
|
2015-06-25 22:14:20 +02:00
|
|
|
} else {
|
|
|
|
if ($request->getStr('participant')) {
|
|
|
|
$participants[] = $request->getStr('participant');
|
|
|
|
}
|
2015-03-24 21:04:33 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$policies = id(new PhabricatorPolicyQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->setObject($conpherence)
|
|
|
|
->execute();
|
|
|
|
|
2015-06-25 22:14:20 +02:00
|
|
|
$submit_uri = $this->getApplicationURI('new/');
|
2015-03-31 01:25:24 +02:00
|
|
|
$cancel_uri = $this->getApplicationURI('search/');
|
2015-03-24 21:04:33 +01:00
|
|
|
|
|
|
|
$dialog = $this->newDialog()
|
|
|
|
->setWidth(AphrontDialogView::WIDTH_FORM)
|
|
|
|
->setValidationException($validation_exception)
|
|
|
|
->setUser($user)
|
|
|
|
->setTitle($title)
|
|
|
|
->addCancelButton($cancel_uri)
|
|
|
|
->addSubmitButton(pht('Create Room'));
|
|
|
|
|
|
|
|
$form = id(new PHUIFormLayoutView())
|
|
|
|
->setUser($user)
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setError($e_title)
|
2015-06-25 22:14:20 +02:00
|
|
|
->setLabel(pht('Name'))
|
2015-03-24 21:04:33 +01:00
|
|
|
->setName('title')
|
|
|
|
->setValue($request->getStr('title')))
|
2016-09-15 03:34:11 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setLabel(pht('Topic'))
|
|
|
|
->setName('topic')
|
|
|
|
->setValue($request->getStr('topic')))
|
2015-06-25 22:14:20 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setName('participants')
|
|
|
|
->setUser($user)
|
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
|
|
|
->setValue($participants)
|
|
|
|
->setLabel(pht('Other Participants')))
|
2015-03-24 21:04:33 +01:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setName('viewPolicy')
|
|
|
|
->setPolicyObject($conpherence)
|
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_VIEW)
|
|
|
|
->setPolicies($policies))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormPolicyControl())
|
|
|
|
->setName('editPolicy')
|
|
|
|
->setPolicyObject($conpherence)
|
|
|
|
->setCapability(PhabricatorPolicyCapability::CAN_EDIT)
|
2017-04-12 18:07:45 +02:00
|
|
|
->setPolicies($policies));
|
2015-03-24 21:04:33 +01:00
|
|
|
|
|
|
|
$dialog->appendChild($form);
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|