[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorProjectColumnEditController 4 extends PhabricatorProjectBoardController { 5 6 private $id; 7 private $projectID; 8 9 public function willProcessRequest(array $data) { 10 $this->projectID = $data['projectID']; 11 $this->id = idx($data, 'id'); 12 } 13 14 public function processRequest() { 15 $request = $this->getRequest(); 16 $viewer = $request->getUser(); 17 18 $project = id(new PhabricatorProjectQuery()) 19 ->setViewer($viewer) 20 ->requireCapabilities( 21 array( 22 PhabricatorPolicyCapability::CAN_VIEW, 23 PhabricatorPolicyCapability::CAN_EDIT, 24 )) 25 ->withIDs(array($this->projectID)) 26 ->executeOne(); 27 28 if (!$project) { 29 return new Aphront404Response(); 30 } 31 $this->setProject($project); 32 33 $is_new = ($this->id ? false : true); 34 35 if (!$is_new) { 36 $column = id(new PhabricatorProjectColumnQuery()) 37 ->setViewer($viewer) 38 ->withIDs(array($this->id)) 39 ->requireCapabilities( 40 array( 41 PhabricatorPolicyCapability::CAN_VIEW, 42 PhabricatorPolicyCapability::CAN_EDIT, 43 )) 44 ->executeOne(); 45 if (!$column) { 46 return new Aphront404Response(); 47 } 48 } else { 49 $column = PhabricatorProjectColumn::initializeNewColumn($viewer); 50 } 51 52 $e_name = null; 53 $e_limit = null; 54 55 $v_limit = $column->getPointLimit(); 56 $v_name = $column->getName(); 57 58 $validation_exception = null; 59 $base_uri = '/board/'.$this->projectID.'/'; 60 if ($is_new) { 61 // we want to go back to the board 62 $view_uri = $this->getApplicationURI($base_uri); 63 } else { 64 $view_uri = $this->getApplicationURI($base_uri.'column/'.$this->id.'/'); 65 } 66 67 if ($request->isFormPost()) { 68 $v_name = $request->getStr('name'); 69 $v_limit = $request->getStr('limit'); 70 71 if ($is_new) { 72 $column->setProjectPHID($project->getPHID()); 73 $column->attachProject($project); 74 75 $columns = id(new PhabricatorProjectColumnQuery()) 76 ->setViewer($viewer) 77 ->withProjectPHIDs(array($project->getPHID())) 78 ->execute(); 79 80 $new_sequence = 1; 81 if ($columns) { 82 $values = mpull($columns, 'getSequence'); 83 $new_sequence = max($values) + 1; 84 } 85 $column->setSequence($new_sequence); 86 } 87 88 $xactions = array(); 89 90 $type_name = PhabricatorProjectColumnTransaction::TYPE_NAME; 91 $xactions[] = id(new PhabricatorProjectColumnTransaction()) 92 ->setTransactionType($type_name) 93 ->setNewValue($v_name); 94 95 $type_limit = PhabricatorProjectColumnTransaction::TYPE_LIMIT; 96 $xactions[] = id(new PhabricatorProjectColumnTransaction()) 97 ->setTransactionType($type_limit) 98 ->setNewValue($v_limit); 99 100 try { 101 $editor = id(new PhabricatorProjectColumnTransactionEditor()) 102 ->setActor($viewer) 103 ->setContinueOnNoEffect(true) 104 ->setContentSourceFromRequest($request) 105 ->applyTransactions($column, $xactions); 106 return id(new AphrontRedirectResponse())->setURI($view_uri); 107 } catch (PhabricatorApplicationTransactionValidationException $ex) { 108 $e_name = $ex->getShortMessage($type_name); 109 $e_limit = $ex->getShortMessage($type_limit); 110 $validation_exception = $ex; 111 } 112 } 113 114 $form = new AphrontFormView(); 115 $form 116 ->setUser($request->getUser()) 117 ->appendChild( 118 id(new AphrontFormTextControl()) 119 ->setValue($v_name) 120 ->setLabel(pht('Name')) 121 ->setName('name') 122 ->setError($e_name) 123 ->setCaption( 124 pht('This will be displayed as the header of the column.'))) 125 ->appendChild( 126 id(new AphrontFormTextControl()) 127 ->setValue($v_limit) 128 ->setLabel(pht('Point Limit')) 129 ->setName('limit') 130 ->setError($e_limit) 131 ->setCaption( 132 pht('Maximum number of points of tasks allowed in the column.'))); 133 134 135 if ($is_new) { 136 $title = pht('Create Column'); 137 $submit = pht('Create Column'); 138 $crumb_text = pht('Create Column'); 139 } else { 140 $title = pht('Edit %s', $column->getDisplayName()); 141 $submit = pht('Save Column'); 142 $crumb_text = pht('Edit'); 143 } 144 145 $form->appendChild( 146 id(new AphrontFormSubmitControl()) 147 ->setValue($submit) 148 ->addCancelButton($view_uri)); 149 150 $crumbs = $this->buildApplicationCrumbs(); 151 $crumbs->addTextCrumb( 152 pht('Board'), 153 $this->getApplicationURI('board/'.$project->getID().'/')); 154 155 if (!$is_new) { 156 $crumbs->addTextCrumb( 157 $column->getDisplayName(), 158 $view_uri); 159 } 160 161 $crumbs->addTextCrumb($crumb_text); 162 163 $form_box = id(new PHUIObjectBoxView()) 164 ->setHeaderText($title) 165 ->setValidationException($validation_exception) 166 ->setForm($form); 167 168 return $this->buildApplicationPage( 169 array( 170 $crumbs, 171 $form_box, 172 ), 173 array( 174 'title' => $title, 175 )); 176 } 177 }
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 |