Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/legalpad/query/LegalpadDocumentSignatureSearchEngine.php
13450 views
1
<?php
2
3
final class LegalpadDocumentSignatureSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
private $document;
7
8
public function getResultTypeDescription() {
9
return pht('Legalpad Signatures');
10
}
11
12
public function getApplicationClassName() {
13
return 'PhabricatorLegalpadApplication';
14
}
15
16
public function setDocument(LegalpadDocument $document) {
17
$this->document = $document;
18
return $this;
19
}
20
21
public function buildSavedQueryFromRequest(AphrontRequest $request) {
22
$saved = new PhabricatorSavedQuery();
23
24
$saved->setParameter(
25
'signerPHIDs',
26
$this->readUsersFromRequest($request, 'signers'));
27
28
$saved->setParameter(
29
'documentPHIDs',
30
$this->readPHIDsFromRequest(
31
$request,
32
'documents',
33
array(
34
PhabricatorLegalpadDocumentPHIDType::TYPECONST,
35
)));
36
37
$saved->setParameter('nameContains', $request->getStr('nameContains'));
38
$saved->setParameter('emailContains', $request->getStr('emailContains'));
39
40
return $saved;
41
}
42
43
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
44
$query = id(new LegalpadDocumentSignatureQuery());
45
46
$signer_phids = $saved->getParameter('signerPHIDs', array());
47
if ($signer_phids) {
48
$query->withSignerPHIDs($signer_phids);
49
}
50
51
if ($this->document) {
52
$query->withDocumentPHIDs(array($this->document->getPHID()));
53
} else {
54
$document_phids = $saved->getParameter('documentPHIDs', array());
55
if ($document_phids) {
56
$query->withDocumentPHIDs($document_phids);
57
}
58
}
59
60
$name_contains = $saved->getParameter('nameContains');
61
if (strlen($name_contains)) {
62
$query->withNameContains($name_contains);
63
}
64
65
$email_contains = $saved->getParameter('emailContains');
66
if (strlen($email_contains)) {
67
$query->withEmailContains($email_contains);
68
}
69
70
return $query;
71
}
72
73
public function buildSearchForm(
74
AphrontFormView $form,
75
PhabricatorSavedQuery $saved_query) {
76
77
$document_phids = $saved_query->getParameter('documentPHIDs', array());
78
$signer_phids = $saved_query->getParameter('signerPHIDs', array());
79
80
if (!$this->document) {
81
$form
82
->appendControl(
83
id(new AphrontFormTokenizerControl())
84
->setDatasource(new LegalpadDocumentDatasource())
85
->setName('documents')
86
->setLabel(pht('Documents'))
87
->setValue($document_phids));
88
}
89
90
$name_contains = $saved_query->getParameter('nameContains', '');
91
$email_contains = $saved_query->getParameter('emailContains', '');
92
93
$form
94
->appendControl(
95
id(new AphrontFormTokenizerControl())
96
->setDatasource(new PhabricatorPeopleDatasource())
97
->setName('signers')
98
->setLabel(pht('Signers'))
99
->setValue($signer_phids))
100
->appendChild(
101
id(new AphrontFormTextControl())
102
->setLabel(pht('Name Contains'))
103
->setName('nameContains')
104
->setValue($name_contains))
105
->appendChild(
106
id(new AphrontFormTextControl())
107
->setLabel(pht('Email Contains'))
108
->setName('emailContains')
109
->setValue($email_contains));
110
}
111
112
protected function getURI($path) {
113
if ($this->document) {
114
return '/legalpad/signatures/'.$this->document->getID().'/'.$path;
115
} else {
116
return '/legalpad/signatures/'.$path;
117
}
118
}
119
120
protected function getBuiltinQueryNames() {
121
$names = array(
122
'all' => pht('All Signatures'),
123
);
124
125
return $names;
126
}
127
128
public function buildSavedQueryFromBuiltin($query_key) {
129
130
$query = $this->newSavedQuery();
131
$query->setQueryKey($query_key);
132
133
switch ($query_key) {
134
case 'all':
135
return $query;
136
}
137
138
return parent::buildSavedQueryFromBuiltin($query_key);
139
}
140
141
protected function getRequiredHandlePHIDsForResultList(
142
array $signatures,
143
PhabricatorSavedQuery $query) {
144
145
return array_merge(
146
mpull($signatures, 'getSignerPHID'),
147
mpull($signatures, 'getDocumentPHID'));
148
}
149
150
protected function renderResultList(
151
array $signatures,
152
PhabricatorSavedQuery $query,
153
array $handles) {
154
assert_instances_of($signatures, 'LegalpadDocumentSignature');
155
156
$viewer = $this->requireViewer();
157
158
Javelin::initBehavior('phabricator-tooltips');
159
160
$sig_good = $this->renderIcon(
161
'fa-check',
162
null,
163
pht('Verified, Current'));
164
165
$sig_corp = $this->renderIcon(
166
'fa-building-o',
167
null,
168
pht('Verified, Corporate'));
169
170
$sig_old = $this->renderIcon(
171
'fa-clock-o',
172
'orange',
173
pht('Signed Older Version'));
174
175
$sig_unverified = $this->renderIcon(
176
'fa-envelope',
177
'red',
178
pht('Unverified Email'));
179
180
$sig_exemption = $this->renderIcon(
181
'fa-asterisk',
182
'indigo',
183
pht('Exemption'));
184
185
id(new PHUIIconView())
186
->setIcon('fa-envelope', 'red')
187
->addSigil('has-tooltip')
188
->setMetadata(array('tip' => pht('Unverified Email')));
189
190
$type_corporate = LegalpadDocument::SIGNATURE_TYPE_CORPORATION;
191
192
$rows = array();
193
foreach ($signatures as $signature) {
194
$name = $signature->getSignerName();
195
$email = $signature->getSignerEmail();
196
197
$document = $signature->getDocument();
198
199
if ($signature->getIsExemption()) {
200
$sig_icon = $sig_exemption;
201
} else if (!$signature->isVerified()) {
202
$sig_icon = $sig_unverified;
203
} else if ($signature->getDocumentVersion() != $document->getVersions()) {
204
$sig_icon = $sig_old;
205
} else if ($signature->getSignatureType() == $type_corporate) {
206
$sig_icon = $sig_corp;
207
} else {
208
$sig_icon = $sig_good;
209
}
210
211
$signature_href = $this->getApplicationURI(
212
'signature/'.$signature->getID().'/');
213
214
$sig_icon = javelin_tag(
215
'a',
216
array(
217
'href' => $signature_href,
218
'sigil' => 'workflow',
219
),
220
$sig_icon);
221
222
$signer_phid = $signature->getSignerPHID();
223
224
$rows[] = array(
225
$sig_icon,
226
$handles[$document->getPHID()]->renderLink(),
227
$signer_phid
228
? $handles[$signer_phid]->renderLink()
229
: phutil_tag('em', array(), pht('None')),
230
$name,
231
phutil_tag(
232
'a',
233
array(
234
'href' => 'mailto:'.$email,
235
),
236
$email),
237
phabricator_datetime($signature->getDateCreated(), $viewer),
238
);
239
}
240
241
$table = id(new AphrontTableView($rows))
242
->setNoDataString(pht('No signatures match the query.'))
243
->setHeaders(
244
array(
245
'',
246
pht('Document'),
247
pht('Account'),
248
pht('Name'),
249
pht('Email'),
250
pht('Signed'),
251
))
252
->setColumnVisibility(
253
array(
254
true,
255
256
// Only show the "Document" column if we aren't scoped to a
257
// particular document.
258
!$this->document,
259
))
260
->setColumnClasses(
261
array(
262
'',
263
'',
264
'',
265
'',
266
'wide',
267
'right',
268
));
269
270
$button = null;
271
if ($this->document) {
272
$document_id = $this->document->getID();
273
274
$button = id(new PHUIButtonView())
275
->setText(pht('Add Exemption'))
276
->setTag('a')
277
->setHref($this->getApplicationURI('addsignature/'.$document_id.'/'))
278
->setWorkflow(true)
279
->setIcon('fa-pencil');
280
}
281
282
if (!$this->document) {
283
$table->setNotice(
284
pht('NOTE: You can only see your own signatures and signatures on '.
285
'documents you have permission to edit.'));
286
}
287
288
$result = new PhabricatorApplicationSearchResultView();
289
$result->setTable($table);
290
if ($button) {
291
$result->addAction($button);
292
}
293
294
return $result;
295
296
}
297
298
private function renderIcon($icon, $color, $title) {
299
Javelin::initBehavior('phabricator-tooltips');
300
301
return array(
302
id(new PHUIIconView())
303
->setIcon($icon, $color)
304
->addSigil('has-tooltip')
305
->setMetadata(array('tip' => $title)),
306
javelin_tag(
307
'span',
308
array(
309
'aural' => true,
310
),
311
$title),
312
);
313
}
314
315
}
316
317