Differential D12934 Diff 31137 src/applications/calendar/controller/PhabricatorCalendarEventEditController.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/calendar/controller/PhabricatorCalendarEventEditController.php
<?php | <?php | ||||
final class PhabricatorCalendarEventEditController | final class PhabricatorCalendarEventEditController | ||||
extends PhabricatorCalendarController { | extends PhabricatorCalendarController { | ||||
private $id; | private $id; | ||||
public function willProcessRequest(array $data) { | public function willProcessRequest(array $data) { | ||||
$this->id = idx($data, 'id'); | $this->id = idx($data, 'id'); | ||||
} | } | ||||
public function isCreate() { | public function isCreate() { | ||||
return !$this->id; | return !$this->id; | ||||
} | } | ||||
public function processRequest() { | public function handleRequest(AphrontRequest $request) { | ||||
$request = $this->getRequest(); | |||||
$user = $request->getUser(); | $user = $request->getUser(); | ||||
$user_phid = $user->getPHID(); | $user_phid = $user->getPHID(); | ||||
$error_name = true; | $error_name = true; | ||||
$error_start_date = true; | $error_start_date = true; | ||||
$error_end_date = true; | $error_end_date = true; | ||||
$validation_exception = null; | $validation_exception = null; | ||||
if ($this->isCreate()) { | if ($this->isCreate()) { | ||||
▲ Show 20 Lines • Show All 43 Lines • ▼ Show 20 Lines | if ($this->isCreate()) { | ||||
} | } | ||||
$cancel_uri = '/'.$event->getMonogram(); | $cancel_uri = '/'.$event->getMonogram(); | ||||
} | } | ||||
$name = $event->getName(); | $name = $event->getName(); | ||||
$description = $event->getDescription(); | $description = $event->getDescription(); | ||||
$is_all_day = $event->getIsAllDay(); | $is_all_day = $event->getIsAllDay(); | ||||
$icon = $event->getIcon(); | |||||
$current_policies = id(new PhabricatorPolicyQuery()) | $current_policies = id(new PhabricatorPolicyQuery()) | ||||
->setViewer($user) | ->setViewer($user) | ||||
->setObject($event) | ->setObject($event) | ||||
->execute(); | ->execute(); | ||||
if ($request->isFormPost()) { | if ($request->isFormPost()) { | ||||
$xactions = array(); | $xactions = array(); | ||||
$name = $request->getStr('name'); | $name = $request->getStr('name'); | ||||
$start_value = AphrontFormDateControlValue::newFromRequest( | $start_value = AphrontFormDateControlValue::newFromRequest( | ||||
$request, | $request, | ||||
'start'); | 'start'); | ||||
$end_value = AphrontFormDateControlValue::newFromRequest( | $end_value = AphrontFormDateControlValue::newFromRequest( | ||||
$request, | $request, | ||||
'end'); | 'end'); | ||||
$description = $request->getStr('description'); | $description = $request->getStr('description'); | ||||
$subscribers = $request->getArr('subscribers'); | $subscribers = $request->getArr('subscribers'); | ||||
$edit_policy = $request->getStr('editPolicy'); | $edit_policy = $request->getStr('editPolicy'); | ||||
$view_policy = $request->getStr('viewPolicy'); | $view_policy = $request->getStr('viewPolicy'); | ||||
$is_all_day = $request->getStr('isAllDay'); | $is_all_day = $request->getStr('isAllDay'); | ||||
$icon = $request->getStr('icon'); | |||||
$invitees = $request->getArr('invitees'); | $invitees = $request->getArr('invitees'); | ||||
$new_invitees = $this->getNewInviteeList($invitees, $event); | $new_invitees = $this->getNewInviteeList($invitees, $event); | ||||
$status_attending = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; | $status_attending = PhabricatorCalendarEventInvitee::STATUS_ATTENDING; | ||||
if ($this->isCreate()) { | if ($this->isCreate()) { | ||||
$status = idx($new_invitees, $user->getPHID()); | $status = idx($new_invitees, $user->getPHID()); | ||||
if ($status) { | if ($status) { | ||||
$new_invitees[$user->getPHID()] = $status_attending; | $new_invitees[$user->getPHID()] = $status_attending; | ||||
} | } | ||||
} | } | ||||
$xactions[] = id(new PhabricatorCalendarEventTransaction()) | $xactions[] = id(new PhabricatorCalendarEventTransaction()) | ||||
->setTransactionType( | ->setTransactionType( | ||||
PhabricatorCalendarEventTransaction::TYPE_NAME) | PhabricatorCalendarEventTransaction::TYPE_NAME) | ||||
->setNewValue($name); | ->setNewValue($name); | ||||
$xactions[] = id(new PhabricatorCalendarEventTransaction()) | $xactions[] = id(new PhabricatorCalendarEventTransaction()) | ||||
->setTransactionType( | ->setTransactionType( | ||||
PhabricatorCalendarEventTransaction::TYPE_ALL_DAY) | PhabricatorCalendarEventTransaction::TYPE_ALL_DAY) | ||||
->setNewValue($is_all_day); | ->setNewValue($is_all_day); | ||||
$xactions[] = id(new PhabricatorCalendarEventTransaction()) | $xactions[] = id(new PhabricatorCalendarEventTransaction()) | ||||
->setTransactionType( | ->setTransactionType( | ||||
PhabricatorCalendarEventTransaction::TYPE_ICON) | |||||
->setNewValue($icon); | |||||
$xactions[] = id(new PhabricatorCalendarEventTransaction()) | |||||
->setTransactionType( | |||||
PhabricatorCalendarEventTransaction::TYPE_START_DATE) | PhabricatorCalendarEventTransaction::TYPE_START_DATE) | ||||
->setNewValue($start_value); | ->setNewValue($start_value); | ||||
$xactions[] = id(new PhabricatorCalendarEventTransaction()) | $xactions[] = id(new PhabricatorCalendarEventTransaction()) | ||||
->setTransactionType( | ->setTransactionType( | ||||
PhabricatorCalendarEventTransaction::TYPE_END_DATE) | PhabricatorCalendarEventTransaction::TYPE_END_DATE) | ||||
->setNewValue($end_value); | ->setNewValue($end_value); | ||||
▲ Show 20 Lines • Show All 112 Lines • ▼ Show 20 Lines | public function handleRequest(AphrontRequest $request) { | ||||
$invitees = id(new AphrontFormTokenizerControl()) | $invitees = id(new AphrontFormTokenizerControl()) | ||||
->setLabel(pht('Invitees')) | ->setLabel(pht('Invitees')) | ||||
->setName('invitees') | ->setName('invitees') | ||||
->setValue($invitees) | ->setValue($invitees) | ||||
->setUser($user) | ->setUser($user) | ||||
->setDatasource(new PhabricatorMetaMTAMailableDatasource()); | ->setDatasource(new PhabricatorMetaMTAMailableDatasource()); | ||||
if ($this->isCreate()) { | |||||
$icon_uri = $this->getApplicationURI('icon/'); | |||||
} else { | |||||
$icon_uri = $this->getApplicationURI('icon/'.$event->getID().'/'); | |||||
} | |||||
$icon_display = PhabricatorCalendarIcon::renderIconForChooser($icon); | |||||
$icon = id(new AphrontFormChooseButtonControl()) | |||||
->setLabel(pht('Icon')) | |||||
->setName('icon') | |||||
->setDisplayValue($icon_display) | |||||
->setButtonText(pht('Choose Icon...')) | |||||
->setChooseURI($icon_uri) | |||||
->setValue($icon); | |||||
$form = id(new AphrontFormView()) | $form = id(new AphrontFormView()) | ||||
->setUser($user) | ->setUser($user) | ||||
->appendChild($name) | ->appendChild($name) | ||||
->appendChild($all_day_checkbox) | ->appendChild($all_day_checkbox) | ||||
->appendChild($start_control) | ->appendChild($start_control) | ||||
->appendChild($end_control) | ->appendChild($end_control) | ||||
->appendControl($view_policies) | ->appendControl($view_policies) | ||||
->appendControl($edit_policies) | ->appendControl($edit_policies) | ||||
->appendControl($subscribers) | ->appendControl($subscribers) | ||||
->appendControl($invitees) | ->appendControl($invitees) | ||||
->appendChild($description); | ->appendChild($description) | ||||
->appendChild($icon); | |||||
if ($request->isAjax()) { | if ($request->isAjax()) { | ||||
return $this->newDialog() | return $this->newDialog() | ||||
->setTitle($page_title) | ->setTitle($page_title) | ||||
->setWidth(AphrontDialogView::WIDTH_FULL) | ->setWidth(AphrontDialogView::WIDTH_FULL) | ||||
->appendForm($form) | ->appendForm($form) | ||||
->addCancelButton($cancel_uri) | ->addCancelButton($cancel_uri) | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |