Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/legalpad/controller/LegalpadDocumentManageController.php
13458 views
1
<?php
2
3
final class LegalpadDocumentManageController extends LegalpadController {
4
5
public function handleRequest(AphrontRequest $request) {
6
$viewer = $request->getViewer();
7
$id = $request->getURIData('id');
8
9
// NOTE: We require CAN_EDIT to view this page.
10
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,
20
))
21
->executeOne();
22
if (!$document) {
23
return new Aphront404Response();
24
}
25
26
$subscribers = PhabricatorSubscribersQuery::loadSubscribersForPHID(
27
$document->getPHID());
28
29
$document_body = $document->getDocumentBody();
30
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());
41
42
$title = $document_body->getTitle();
43
44
$header = id(new PHUIHeaderView())
45
->setHeader($title)
46
->setUser($viewer)
47
->setPolicyObject($document)
48
->setHeaderIcon('fa-gavel');
49
50
$curtain = $this->buildCurtainView($document);
51
$properties = $this->buildPropertyView($document, $engine);
52
$document_view = $this->buildDocumentView($document, $engine);
53
54
$comment_form = $this->buildCommentView($document, $timeline);
55
56
$crumbs = $this->buildApplicationCrumbs();
57
$crumbs->addTextCrumb(
58
$document->getMonogram(),
59
'/'.$document->getMonogram());
60
$crumbs->addTextCrumb(pht('Manage'));
61
$crumbs->setBorder(true);
62
63
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
));
73
74
return $this->newPage()
75
->setTitle($title)
76
->setCrumbs($crumbs)
77
->setPageObjectPHIDs(array($document->getPHID()))
78
->appendChild($view);
79
}
80
81
private function buildDocumentView(
82
LegalpadDocument $document,
83
PhabricatorMarkupEngine $engine) {
84
85
$viewer = $this->getViewer();
86
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);
92
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);
101
}
102
103
return id(new PHUIObjectBoxView())
104
->setHeaderText(pht('DOCUMENT'))
105
->addPropertyList($view)
106
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
107
}
108
109
private function buildCurtainView(LegalpadDocument $document) {
110
$viewer = $this->getViewer();
111
112
$curtain = $this->newCurtainView($document);
113
114
$can_edit = PhabricatorPolicyFilter::hasCapability(
115
$viewer,
116
$document,
117
PhabricatorPolicyCapability::CAN_EDIT);
118
119
$doc_id = $document->getID();
120
121
$curtain->addAction(
122
id(new PhabricatorActionView())
123
->setIcon('fa-pencil-square')
124
->setName(pht('View/Sign Document'))
125
->setHref('/'.$document->getMonogram()));
126
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));
134
135
$curtain->addAction(
136
id(new PhabricatorActionView())
137
->setIcon('fa-terminal')
138
->setName(pht('View Signatures'))
139
->setHref($this->getApplicationURI('/signatures/'.$doc_id.'/')));
140
141
return $curtain;
142
}
143
144
private function buildPropertyView(
145
LegalpadDocument $document,
146
PhabricatorMarkupEngine $engine) {
147
148
$viewer = $this->getViewer();
149
150
$properties = id(new PHUIPropertyListView())
151
->setUser($viewer);
152
153
$properties->addProperty(
154
pht('Signature Type'),
155
$document->getSignatureTypeName());
156
157
$properties->addProperty(
158
pht('Last Updated'),
159
phabricator_datetime($document->getDateModified(), $viewer));
160
161
$properties->addProperty(
162
pht('Updated By'),
163
$viewer->renderHandle($document->getDocumentBody()->getCreatorPHID()));
164
165
$properties->addProperty(
166
pht('Versions'),
167
$document->getVersions());
168
169
if ($document->getContributors()) {
170
$properties->addProperty(
171
pht('Contributors'),
172
$viewer
173
->renderHandleList($document->getContributors())
174
->setAsInline(true));
175
}
176
177
return id(new PHUIObjectBoxView())
178
->setHeaderText(pht('Properties'))
179
->addPropertyList($properties)
180
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY);
181
}
182
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);
189
190
return $box;
191
}
192
193
}
194
195