[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PholioMockViewController extends PholioController { 4 5 private $id; 6 private $imageID; 7 private $maniphestTaskPHIDs = array(); 8 9 private function setManiphestTaskPHIDs($maniphest_task_phids) { 10 $this->maniphestTaskPHIDs = $maniphest_task_phids; 11 return $this; 12 } 13 private function getManiphestTaskPHIDs() { 14 return $this->maniphestTaskPHIDs; 15 } 16 17 public function shouldAllowPublic() { 18 return true; 19 } 20 21 public function willProcessRequest(array $data) { 22 $this->id = $data['id']; 23 $this->imageID = idx($data, 'imageID'); 24 } 25 26 public function processRequest() { 27 $request = $this->getRequest(); 28 $user = $request->getUser(); 29 30 $mock = id(new PholioMockQuery()) 31 ->setViewer($user) 32 ->withIDs(array($this->id)) 33 ->needImages(true) 34 ->needInlineComments(true) 35 ->executeOne(); 36 37 if (!$mock) { 38 return new Aphront404Response(); 39 } 40 41 $xactions = id(new PholioTransactionQuery()) 42 ->setViewer($user) 43 ->withObjectPHIDs(array($mock->getPHID())) 44 ->execute(); 45 46 $phids = PhabricatorEdgeQuery::loadDestinationPHIDs( 47 $mock->getPHID(), 48 PhabricatorEdgeConfig::TYPE_MOCK_HAS_TASK); 49 $this->setManiphestTaskPHIDs($phids); 50 $phids[] = $mock->getAuthorPHID(); 51 $this->loadHandles($phids); 52 53 $engine = id(new PhabricatorMarkupEngine()) 54 ->setViewer($user); 55 $engine->addObject($mock, PholioMock::MARKUP_FIELD_DESCRIPTION); 56 foreach ($xactions as $xaction) { 57 if ($xaction->getComment()) { 58 $engine->addObject( 59 $xaction->getComment(), 60 PhabricatorApplicationTransactionComment::MARKUP_FIELD_COMMENT); 61 } 62 } 63 $engine->process(); 64 65 $title = $mock->getName(); 66 67 if ($mock->isClosed()) { 68 $header_icon = 'fa-ban'; 69 $header_name = pht('Closed'); 70 $header_color = 'dark'; 71 } else { 72 $header_icon = 'fa-square-o'; 73 $header_name = pht('Open'); 74 $header_color = 'bluegrey'; 75 } 76 77 $header = id(new PHUIHeaderView()) 78 ->setHeader($title) 79 ->setUser($user) 80 ->setStatus($header_icon, $header_color, $header_name) 81 ->setPolicyObject($mock); 82 83 $actions = $this->buildActionView($mock); 84 $properties = $this->buildPropertyView($mock, $engine, $actions); 85 86 require_celerity_resource('pholio-css'); 87 require_celerity_resource('pholio-inline-comments-css'); 88 89 $comment_form_id = celerity_generate_unique_node_id(); 90 $output = id(new PholioMockImagesView()) 91 ->setRequestURI($request->getRequestURI()) 92 ->setCommentFormID($comment_form_id) 93 ->setUser($user) 94 ->setMock($mock) 95 ->setImageID($this->imageID); 96 97 $output = id(new PHUIObjectBoxView()) 98 ->setHeaderText(pht('Image')) 99 ->appendChild($output); 100 101 $xaction_view = id(new PholioTransactionView()) 102 ->setUser($this->getRequest()->getUser()) 103 ->setMock($mock) 104 ->setObjectPHID($mock->getPHID()) 105 ->setTransactions($xactions) 106 ->setMarkupEngine($engine); 107 108 $add_comment = $this->buildAddCommentView($mock, $comment_form_id); 109 110 $crumbs = $this->buildApplicationCrumbs(); 111 $crumbs->setActionList($actions); 112 $crumbs->addTextCrumb('M'.$mock->getID(), '/M'.$mock->getID()); 113 114 $object_box = id(new PHUIObjectBoxView()) 115 ->setHeader($header) 116 ->addPropertyList($properties); 117 118 $thumb_grid = id(new PholioMockThumbGridView()) 119 ->setUser($user) 120 ->setMock($mock); 121 122 $content = array( 123 $crumbs, 124 $object_box, 125 $output, 126 $thumb_grid, 127 $xaction_view, 128 $add_comment, 129 ); 130 131 return $this->buildApplicationPage( 132 $content, 133 array( 134 'title' => 'M'.$mock->getID().' '.$title, 135 'pageObjects' => array($mock->getPHID()), 136 )); 137 } 138 139 private function buildActionView(PholioMock $mock) { 140 $user = $this->getRequest()->getUser(); 141 142 $actions = id(new PhabricatorActionListView()) 143 ->setUser($user) 144 ->setObjectURI($this->getRequest()->getRequestURI()) 145 ->setObject($mock); 146 147 $can_edit = PhabricatorPolicyFilter::hasCapability( 148 $user, 149 $mock, 150 PhabricatorPolicyCapability::CAN_EDIT); 151 152 $actions->addAction( 153 id(new PhabricatorActionView()) 154 ->setIcon('fa-pencil') 155 ->setName(pht('Edit Mock')) 156 ->setHref($this->getApplicationURI('/edit/'.$mock->getID().'/')) 157 ->setDisabled(!$can_edit) 158 ->setWorkflow(!$can_edit)); 159 160 $actions->addAction( 161 id(new PhabricatorActionView()) 162 ->setIcon('fa-anchor') 163 ->setName(pht('Edit Maniphest Tasks')) 164 ->setHref("/search/attach/{$mock->getPHID()}/TASK/edge/") 165 ->setDisabled(!$user->isLoggedIn()) 166 ->setWorkflow(true)); 167 168 return $actions; 169 } 170 171 private function buildPropertyView( 172 PholioMock $mock, 173 PhabricatorMarkupEngine $engine, 174 PhabricatorActionListView $actions) { 175 176 $user = $this->getRequest()->getUser(); 177 178 $properties = id(new PHUIPropertyListView()) 179 ->setUser($user) 180 ->setObject($mock) 181 ->setActionList($actions); 182 183 $properties->addProperty( 184 pht('Author'), 185 $this->getHandle($mock->getAuthorPHID())->renderLink()); 186 187 $properties->addProperty( 188 pht('Created'), 189 phabricator_datetime($mock->getDateCreated(), $user)); 190 191 if ($this->getManiphestTaskPHIDs()) { 192 $properties->addProperty( 193 pht('Maniphest Tasks'), 194 $this->renderHandlesForPHIDs($this->getManiphestTaskPHIDs())); 195 } 196 197 $properties->invokeWillRenderEvent(); 198 199 $properties->addSectionHeader( 200 pht('Description'), 201 PHUIPropertyListView::ICON_SUMMARY); 202 203 $properties->addImageContent( 204 $engine->getOutput($mock, PholioMock::MARKUP_FIELD_DESCRIPTION)); 205 206 return $properties; 207 } 208 209 private function buildAddCommentView(PholioMock $mock, $comment_form_id) { 210 $user = $this->getRequest()->getUser(); 211 212 $draft = PhabricatorDraft::newFromUserAndKey($user, $mock->getPHID()); 213 214 $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); 215 $title = $is_serious 216 ? pht('Add Comment') 217 : pht('History Beckons'); 218 219 $form = id(new PhabricatorApplicationTransactionCommentView()) 220 ->setUser($user) 221 ->setObjectPHID($mock->getPHID()) 222 ->setFormID($comment_form_id) 223 ->setDraft($draft) 224 ->setHeaderText($title) 225 ->setSubmitButtonName(pht('Add Comment')) 226 ->setAction($this->getApplicationURI('/comment/'.$mock->getID().'/')) 227 ->setRequestURI($this->getRequest()->getRequestURI()); 228 229 return $form; 230 } 231 232 }
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 |