[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorCalendarEventEditController 4 extends PhabricatorCalendarController { 5 6 private $id; 7 8 public function willProcessRequest(array $data) { 9 $this->id = idx($data, 'id'); 10 } 11 12 public function isCreate() { 13 return !$this->id; 14 } 15 16 public function processRequest() { 17 $request = $this->getRequest(); 18 $user = $request->getUser(); 19 20 $start_time = id(new AphrontFormDateControl()) 21 ->setUser($user) 22 ->setName('start') 23 ->setLabel(pht('Start')) 24 ->setInitialTime(AphrontFormDateControl::TIME_START_OF_DAY); 25 26 $end_time = id(new AphrontFormDateControl()) 27 ->setUser($user) 28 ->setName('end') 29 ->setLabel(pht('End')) 30 ->setInitialTime(AphrontFormDateControl::TIME_END_OF_DAY); 31 32 if ($this->isCreate()) { 33 $status = new PhabricatorCalendarEvent(); 34 $end_value = $end_time->readValueFromRequest($request); 35 $start_value = $start_time->readValueFromRequest($request); 36 $submit_label = pht('Create'); 37 $filter = 'status/create/'; 38 $page_title = pht('Create Event'); 39 $redirect = 'created'; 40 } else { 41 $status = id(new PhabricatorCalendarEventQuery()) 42 ->setViewer($user) 43 ->withIDs(array($this->id)) 44 ->requireCapabilities( 45 array( 46 PhabricatorPolicyCapability::CAN_VIEW, 47 PhabricatorPolicyCapability::CAN_EDIT, 48 )) 49 ->executeOne(); 50 if (!$status) { 51 return new Aphront404Response(); 52 } 53 54 $end_time->setValue($status->getDateTo()); 55 $start_time->setValue($status->getDateFrom()); 56 $submit_label = pht('Update'); 57 $filter = 'event/edit/'.$status->getID().'/'; 58 $page_title = pht('Update Event'); 59 $redirect = 'updated'; 60 } 61 62 $errors = array(); 63 if ($request->isFormPost()) { 64 $type = $request->getInt('status'); 65 $start_value = $start_time->readValueFromRequest($request); 66 $end_value = $end_time->readValueFromRequest($request); 67 $description = $request->getStr('description'); 68 69 try { 70 $status 71 ->setUserPHID($user->getPHID()) 72 ->setStatus($type) 73 ->setDateFrom($start_value) 74 ->setDateTo($end_value) 75 ->setDescription($description) 76 ->save(); 77 } catch (PhabricatorCalendarEventInvalidEpochException $e) { 78 $errors[] = pht('Start must be before end.'); 79 } 80 81 if (!$errors) { 82 $uri = new PhutilURI($this->getApplicationURI()); 83 $uri->setQueryParams( 84 array( 85 'month' => phabricator_format_local_time($status->getDateFrom(), 86 $user, 87 'm'), 88 'year' => phabricator_format_local_time($status->getDateFrom(), 89 $user, 90 'Y'), 91 $redirect => true, 92 )); 93 if ($request->isAjax()) { 94 $response = id(new AphrontAjaxResponse()) 95 ->setContent(array('redirect_uri' => $uri)); 96 } else { 97 $response = id(new AphrontRedirectResponse()) 98 ->setURI($uri); 99 } 100 return $response; 101 } 102 } 103 104 $error_view = null; 105 if ($errors) { 106 $error_view = id(new AphrontErrorView()) 107 ->setTitle(pht('Status can not be set!')) 108 ->setErrors($errors); 109 } 110 111 $status_select = id(new AphrontFormSelectControl()) 112 ->setLabel(pht('Status')) 113 ->setName('status') 114 ->setValue($status->getStatus()) 115 ->setOptions($status->getStatusOptions()); 116 117 $description = id(new AphrontFormTextAreaControl()) 118 ->setLabel(pht('Description')) 119 ->setName('description') 120 ->setValue($status->getDescription()); 121 122 if ($request->isAjax()) { 123 $dialog = id(new AphrontDialogView()) 124 ->setUser($user) 125 ->setTitle($page_title) 126 ->setWidth(AphrontDialogView::WIDTH_FORM); 127 if ($this->isCreate()) { 128 $dialog->setSubmitURI($this->getApplicationURI('event/create/')); 129 } else { 130 $dialog->setSubmitURI( 131 $this->getApplicationURI('event/edit/'.$status->getID().'/')); 132 } 133 $form = new PHUIFormLayoutView(); 134 if ($error_view) { 135 $form->appendChild($error_view); 136 } 137 } else { 138 $form = id(new AphrontFormView()) 139 ->setUser($user); 140 } 141 142 $form 143 ->appendChild($status_select) 144 ->appendChild($start_time) 145 ->appendChild($end_time) 146 ->appendChild($description); 147 148 if ($request->isAjax()) { 149 $dialog->addSubmitButton($submit_label); 150 $submit = $dialog; 151 } else { 152 $submit = id(new AphrontFormSubmitControl()) 153 ->setValue($submit_label); 154 } 155 if ($this->isCreate()) { 156 $submit->addCancelButton($this->getApplicationURI()); 157 } else { 158 $submit->addCancelButton( 159 $this->getApplicationURI('event/view/'.$status->getID().'/')); 160 } 161 162 if ($request->isAjax()) { 163 $dialog->appendChild($form); 164 return id(new AphrontDialogResponse()) 165 ->setDialog($dialog); 166 } 167 $form->appendChild($submit); 168 169 170 171 $form_box = id(new PHUIObjectBoxView()) 172 ->setHeaderText($page_title) 173 ->setFormErrors($errors) 174 ->setForm($form); 175 176 $nav = $this->buildSideNavView($status); 177 $nav->selectFilter($filter); 178 179 $crumbs = $this 180 ->buildApplicationCrumbs() 181 ->addTextCrumb($page_title); 182 183 $nav->appendChild( 184 array( 185 $crumbs, 186 $form_box, 187 )); 188 189 return $this->buildApplicationPage( 190 $nav, 191 array( 192 'title' => $page_title, 193 )); 194 } 195 196 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |