Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / legalpad / controller / LegalpadDocumentManageController.php
blobb39bc8927095b5cfa82cb95912ca2ca1b2c8e7e2
1 <?php
3 final class LegalpadDocumentManageController extends LegalpadController {
5 public function handleRequest(AphrontRequest $request) {
6 $viewer = $request->getViewer();
7 $id = $request->getURIData('id');
9 // NOTE: We require CAN_EDIT to view this page.
11 $document = id(new LegalpadDocumentQuery())
12 ->setViewer($viewer)
13 ->withIDs(array($id))
14 ->needDocumentBodies(true)
15 ->needContributors(true)
16 ->requireCapabilities(
17 array(
18 PhabricatorPolicyCapability::CAN_VIEW,
19 PhabricatorPolicyCapability::CAN_EDIT,
21 ->executeOne();
22 if (!$document) {
23 return new Aphront404Response();
26 $subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
27 $document->getPHID());
29 $document_body = $document->getDocumentBody();
31 $engine = id(new PhabricatorMarkupEngine())
32 ->setViewer($viewer);
33 $engine->addObject(
34 $document_body,
35 LegalpadDocumentBody::MARKUP_FIELD_TEXT);
36 $timeline = $this->buildTransactionTimeline(
37 $document,
38 new LegalpadTransactionQuery(),
39 $engine);
40 $timeline->setQuoteRef($document->getMonogram());
42 $title = $document_body->getTitle();
44 $header = id(new PHUIHeaderView())
45 ->setHeader($title)
46 ->setUser($viewer)
47 ->setPolicyObject($document)
48 ->setHeaderIcon('fa-gavel');
50 $curtain = $this->buildCurtainView($document);
51 $properties = $this->buildPropertyView($document, $engine);
52 $document_view = $this->buildDocumentView($document, $engine);
54 $comment_form = $this->buildCommentView($document, $timeline);
56 $crumbs = $this->buildApplicationCrumbs();
57 $crumbs->addTextCrumb(
58 $document->getMonogram(),
59 '/'.$document->getMonogram());
60 $crumbs->addTextCrumb(pht('Manage'));
61 $crumbs->setBorder(true);
64 $view = id(new PHUITwoColumnView())
65 ->setHeader($header)
66 ->setCurtain($curtain)
67 ->setMainColumn(array(
68 $properties,
69 $document_view,
70 $timeline,
71 $comment_form,
72 ));
74 return $this->newPage()
75 ->setTitle($title)
76 ->setCrumbs($crumbs)
77 ->setPageObjectPHIDs(array($document->getPHID()))
78 ->appendChild($view);
81 private function buildDocumentView(
82 LegalpadDocument $document,
83 PhabricatorMarkupEngine $engine) {
85 $viewer = $this->getViewer();
87 $view = id(new PHUIPropertyListView())
88 ->setUser($viewer);
89 $document_body = $document->getDocumentBody();
90 $document_text = $engine->getOutput(
91 $document_body, LegalpadDocumentBody::MARKUP_FIELD_TEXT);
93 $preamble_box = null;
94 if (strlen($document->getPreamble())) {
95 $preamble_text = new PHUIRemarkupView($viewer, $document->getPreamble());
96 $view->addTextContent($preamble_text);
97 $view->addSectionHeader('');
98 $view->addTextContent($document_text);
99 } else {
100 $view->addTextContent($document_text);
103 return id(new PHUIObjectBoxView())
104 ->setHeaderText(pht('DOCUMENT'))
105 ->addPropertyList($view)
106 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
109 private function buildCurtainView(LegalpadDocument $document) {
110 $viewer = $this->getViewer();
112 $curtain = $this->newCurtainView($document);
114 $can_edit = PhabricatorPolicyFilter::hasCapability(
115 $viewer,
116 $document,
117 PhabricatorPolicyCapability::CAN_EDIT);
119 $doc_id = $document->getID();
121 $curtain->addAction(
122 id(new PhabricatorActionView())
123 ->setIcon('fa-pencil-square')
124 ->setName(pht('View/Sign Document'))
125 ->setHref('/'.$document->getMonogram()));
127 $curtain->addAction(
128 id(new PhabricatorActionView())
129 ->setIcon('fa-pencil')
130 ->setName(pht('Edit Document'))
131 ->setHref($this->getApplicationURI('/edit/'.$doc_id.'/'))
132 ->setDisabled(!$can_edit)
133 ->setWorkflow(!$can_edit));
135 $curtain->addAction(
136 id(new PhabricatorActionView())
137 ->setIcon('fa-terminal')
138 ->setName(pht('View Signatures'))
139 ->setHref($this->getApplicationURI('/signatures/'.$doc_id.'/')));
141 return $curtain;
144 private function buildPropertyView(
145 LegalpadDocument $document,
146 PhabricatorMarkupEngine $engine) {
148 $viewer = $this->getViewer();
150 $properties = id(new PHUIPropertyListView())
151 ->setUser($viewer);
153 $properties->addProperty(
154 pht('Signature Type'),
155 $document->getSignatureTypeName());
157 $properties->addProperty(
158 pht('Last Updated'),
159 phabricator_datetime($document->getDateModified(), $viewer));
161 $properties->addProperty(
162 pht('Updated By'),
163 $viewer->renderHandle($document->getDocumentBody()->getCreatorPHID()));
165 $properties->addProperty(
166 pht('Versions'),
167 $document->getVersions());
169 if ($document->getContributors()) {
170 $properties->addProperty(
171 pht('Contributors'),
172 $viewer
173 ->renderHandleList($document->getContributors())
174 ->setAsInline(true));
177 return id(new PHUIObjectBoxView())
178 ->setHeaderText(pht('Properties'))
179 ->addPropertyList($properties)
180 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
183 private function buildCommentView(LegalpadDocument $document, $timeline) {
184 $viewer = $this->getViewer();
185 $box = id(new LegalpadDocumentEditEngine())
186 ->setViewer($viewer)
187 ->buildEditEngineCommentView($document)
188 ->setTransactionTimeline($timeline);
190 return $box;