[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class LegalpadDocumentManageController extends LegalpadController { 4 5 private $id; 6 7 public function willProcessRequest(array $data) { 8 $this->id = $data['id']; 9 } 10 11 public function processRequest() { 12 $request = $this->getRequest(); 13 $user = $request->getUser(); 14 15 // NOTE: We require CAN_EDIT to view this page. 16 17 $document = id(new LegalpadDocumentQuery()) 18 ->setViewer($user) 19 ->withIDs(array($this->id)) 20 ->needDocumentBodies(true) 21 ->needContributors(true) 22 ->requireCapabilities( 23 array( 24 PhabricatorPolicyCapability::CAN_VIEW, 25 PhabricatorPolicyCapability::CAN_EDIT, 26 )) 27 ->executeOne(); 28 if (!$document) { 29 return new Aphront404Response(); 30 } 31 32 $xactions = id(new LegalpadTransactionQuery()) 33 ->setViewer($user) 34 ->withObjectPHIDs(array($document->getPHID())) 35 ->execute(); 36 37 $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID( 38 $document->getPHID()); 39 40 $document_body = $document->getDocumentBody(); 41 $phids = array(); 42 $phids[] = $document_body->getCreatorPHID(); 43 foreach ($subscribers as $subscriber) { 44 $phids[] = $subscriber; 45 } 46 foreach ($document->getContributors() as $contributor) { 47 $phids[] = $contributor; 48 } 49 $this->loadHandles($phids); 50 51 $engine = id(new PhabricatorMarkupEngine()) 52 ->setViewer($user); 53 $engine->addObject( 54 $document_body, 55 LegalpadDocumentBody::MARKUP_FIELD_TEXT); 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 = $document_body->getTitle(); 66 67 $header = id(new PHUIHeaderView()) 68 ->setHeader($title) 69 ->setUser($user) 70 ->setPolicyObject($document); 71 72 $actions = $this->buildActionView($document); 73 $properties = $this->buildPropertyView($document, $engine, $actions); 74 75 $comment_form_id = celerity_generate_unique_node_id(); 76 77 $xaction_view = id(new LegalpadTransactionView()) 78 ->setUser($this->getRequest()->getUser()) 79 ->setObjectPHID($document->getPHID()) 80 ->setTransactions($xactions) 81 ->setMarkupEngine($engine); 82 83 $add_comment = $this->buildAddCommentView($document, $comment_form_id); 84 85 $crumbs = $this->buildApplicationCrumbs($this->buildSideNav()); 86 $crumbs->setActionList($actions); 87 $crumbs->addTextCrumb( 88 $document->getMonogram(), 89 '/'.$document->getMonogram()); 90 $crumbs->addTextCrumb(pht('Manage')); 91 92 $object_box = id(new PHUIObjectBoxView()) 93 ->setHeader($header) 94 ->addPropertyList($properties) 95 ->addPropertyList($this->buildDocument($engine, $document_body)); 96 97 $content = array( 98 $crumbs, 99 $object_box, 100 $xaction_view, 101 $add_comment, 102 ); 103 104 return $this->buildApplicationPage( 105 $content, 106 array( 107 'title' => $title, 108 'pageObjects' => array($document->getPHID()), 109 )); 110 } 111 112 private function buildDocument( 113 PhabricatorMarkupEngine 114 $engine, LegalpadDocumentBody $body) { 115 116 $view = new PHUIPropertyListView(); 117 $view->addClass('legalpad'); 118 $view->addSectionHeader(pht('Document')); 119 $view->addTextContent( 120 $engine->getOutput($body, LegalpadDocumentBody::MARKUP_FIELD_TEXT)); 121 122 return $view; 123 124 } 125 126 private function buildActionView(LegalpadDocument $document) { 127 $user = $this->getRequest()->getUser(); 128 129 $actions = id(new PhabricatorActionListView()) 130 ->setUser($user) 131 ->setObjectURI($this->getRequest()->getRequestURI()) 132 ->setObject($document); 133 134 $can_edit = PhabricatorPolicyFilter::hasCapability( 135 $user, 136 $document, 137 PhabricatorPolicyCapability::CAN_EDIT); 138 139 $doc_id = $document->getID(); 140 141 $actions->addAction( 142 id(new PhabricatorActionView()) 143 ->setIcon('fa-pencil-square') 144 ->setName(pht('View/Sign Document')) 145 ->setHref('/'.$document->getMonogram())); 146 147 $actions->addAction( 148 id(new PhabricatorActionView()) 149 ->setIcon('fa-pencil') 150 ->setName(pht('Edit Document')) 151 ->setHref($this->getApplicationURI('/edit/'.$doc_id.'/')) 152 ->setDisabled(!$can_edit) 153 ->setWorkflow(!$can_edit)); 154 155 $actions->addAction( 156 id(new PhabricatorActionView()) 157 ->setIcon('fa-terminal') 158 ->setName(pht('View Signatures')) 159 ->setHref($this->getApplicationURI('/signatures/'.$doc_id.'/'))); 160 161 return $actions; 162 } 163 164 private function buildPropertyView( 165 LegalpadDocument $document, 166 PhabricatorMarkupEngine $engine, 167 PhabricatorActionListView $actions) { 168 169 $user = $this->getRequest()->getUser(); 170 171 $properties = id(new PHUIPropertyListView()) 172 ->setUser($user) 173 ->setObject($document) 174 ->setActionList($actions); 175 176 $properties->addProperty( 177 pht('Signature Type'), 178 $document->getSignatureTypeName()); 179 180 $properties->addProperty( 181 pht('Last Updated'), 182 phabricator_datetime($document->getDateModified(), $user)); 183 184 $properties->addProperty( 185 pht('Updated By'), 186 $this->getHandle( 187 $document->getDocumentBody()->getCreatorPHID())->renderLink()); 188 189 $properties->addProperty( 190 pht('Versions'), 191 $document->getVersions()); 192 193 $contributor_view = array(); 194 foreach ($document->getContributors() as $contributor) { 195 $contributor_view[] = $this->getHandle($contributor)->renderLink(); 196 } 197 $contributor_view = phutil_implode_html(', ', $contributor_view); 198 $properties->addProperty( 199 pht('Contributors'), 200 $contributor_view); 201 202 $properties->invokeWillRenderEvent(); 203 204 return $properties; 205 } 206 207 private function buildAddCommentView( 208 LegalpadDocument $document, 209 $comment_form_id) { 210 $user = $this->getRequest()->getUser(); 211 212 $draft = PhabricatorDraft::newFromUserAndKey($user, $document->getPHID()); 213 214 $is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business'); 215 216 $title = $is_serious 217 ? pht('Add Comment') 218 : pht('Debate Legislation'); 219 220 $form = id(new PhabricatorApplicationTransactionCommentView()) 221 ->setUser($user) 222 ->setObjectPHID($document->getPHID()) 223 ->setFormID($comment_form_id) 224 ->setHeaderText($title) 225 ->setDraft($draft) 226 ->setSubmitButtonName(pht('Add Comment')) 227 ->setAction($this->getApplicationURI('/comment/'.$document->getID().'/')) 228 ->setRequestURI($this->getRequest()->getRequestURI()); 229 230 return $form; 231 232 } 233 234 }
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 |