Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/legalpad/query/LegalpadDocumentSearchEngine.php
13456 views
1
<?php
2
3
final class LegalpadDocumentSearchEngine
4
extends PhabricatorApplicationSearchEngine {
5
6
public function getResultTypeDescription() {
7
return pht('Legalpad Documents');
8
}
9
10
public function getApplicationClassName() {
11
return 'PhabricatorLegalpadApplication';
12
}
13
14
public function newQuery() {
15
return id(new LegalpadDocumentQuery())
16
->needViewerSignatures(true);
17
}
18
19
protected function buildCustomSearchFields() {
20
return array(
21
id(new PhabricatorUsersSearchField())
22
->setLabel(pht('Signed By'))
23
->setKey('signerPHIDs')
24
->setAliases(array('signer', 'signers', 'signerPHID'))
25
->setDescription(
26
pht('Search for documents signed by given users.')),
27
id(new PhabricatorUsersSearchField())
28
->setLabel(pht('Creators'))
29
->setKey('creatorPHIDs')
30
->setAliases(array('creator', 'creators', 'creatorPHID'))
31
->setDescription(
32
pht('Search for documents with given creators.')),
33
id(new PhabricatorUsersSearchField())
34
->setLabel(pht('Contributors'))
35
->setKey('contributorPHIDs')
36
->setAliases(array('contributor', 'contributors', 'contributorPHID'))
37
->setDescription(
38
pht('Search for documents with given contributors.')),
39
id(new PhabricatorSearchDateField())
40
->setLabel(pht('Created After'))
41
->setKey('createdStart'),
42
id(new PhabricatorSearchDateField())
43
->setLabel(pht('Created Before'))
44
->setKey('createdEnd'),
45
);
46
}
47
48
protected function buildQueryFromParameters(array $map) {
49
$query = $this->newQuery();
50
51
if ($map['signerPHIDs']) {
52
$query->withSignerPHIDs($map['signerPHIDs']);
53
}
54
55
if ($map['contributorPHIDs']) {
56
$query->withContributorPHIDs($map['contributorPHIDs']);
57
}
58
59
if ($map['creatorPHIDs']) {
60
$query->withCreatorPHIDs($map['creatorPHIDs']);
61
}
62
63
if ($map['createdStart']) {
64
$query->withDateCreatedAfter($map['createdStart']);
65
}
66
67
if ($map['createdEnd']) {
68
$query->withDateCreatedAfter($map['createdStart']);
69
}
70
71
return $query;
72
}
73
74
protected function getURI($path) {
75
return '/legalpad/'.$path;
76
}
77
78
protected function getBuiltinQueryNames() {
79
$names = array();
80
81
if ($this->requireViewer()->isLoggedIn()) {
82
$names['signed'] = pht('Signed Documents');
83
}
84
85
$names['all'] = pht('All Documents');
86
87
return $names;
88
}
89
90
public function buildSavedQueryFromBuiltin($query_key) {
91
$query = $this->newSavedQuery();
92
$query->setQueryKey($query_key);
93
94
$viewer = $this->requireViewer();
95
96
switch ($query_key) {
97
case 'signed':
98
return $query->setParameter('signerPHIDs', array($viewer->getPHID()));
99
case 'all':
100
return $query;
101
}
102
103
return parent::buildSavedQueryFromBuiltin($query_key);
104
}
105
106
protected function renderResultList(
107
array $documents,
108
PhabricatorSavedQuery $query,
109
array $handles) {
110
assert_instances_of($documents, 'LegalpadDocument');
111
112
$viewer = $this->requireViewer();
113
114
$list = new PHUIObjectItemListView();
115
$list->setUser($viewer);
116
foreach ($documents as $document) {
117
$last_updated = phabricator_date($document->getDateModified(), $viewer);
118
119
$title = $document->getTitle();
120
121
$item = id(new PHUIObjectItemView())
122
->setObjectName($document->getMonogram())
123
->setHeader($title)
124
->setHref('/'.$document->getMonogram())
125
->setObject($document);
126
127
$no_signatures = LegalpadDocument::SIGNATURE_TYPE_NONE;
128
if ($document->getSignatureType() == $no_signatures) {
129
$item->addIcon('none', pht('Not Signable'));
130
} else {
131
132
$type_name = $document->getSignatureTypeName();
133
$type_icon = $document->getSignatureTypeIcon();
134
$item->addIcon($type_icon, $type_name);
135
136
if ($viewer->getPHID()) {
137
$signature = $document->getUserSignature($viewer->getPHID());
138
} else {
139
$signature = null;
140
}
141
142
if ($signature) {
143
$item->addAttribute(
144
array(
145
id(new PHUIIconView())->setIcon('fa-check-square-o', 'green'),
146
' ',
147
pht(
148
'Signed on %s',
149
phabricator_date($signature->getDateCreated(), $viewer)),
150
));
151
} else {
152
$item->addAttribute(
153
array(
154
id(new PHUIIconView())->setIcon('fa-square-o', 'grey'),
155
' ',
156
pht('Not Signed'),
157
));
158
}
159
}
160
161
$item->addIcon(
162
'fa-pencil grey',
163
pht('Version %d (%s)', $document->getVersions(), $last_updated));
164
165
$list->addItem($item);
166
}
167
168
$result = new PhabricatorApplicationSearchResultView();
169
$result->setObjectList($list);
170
$result->setNoDataString(pht('No documents found.'));
171
172
return $result;
173
}
174
175
protected function getNewUserBody() {
176
$create_button = id(new PHUIButtonView())
177
->setTag('a')
178
->setText(pht('Create a Document'))
179
->setHref('/legalpad/edit/')
180
->setColor(PHUIButtonView::GREEN);
181
182
$icon = $this->getApplication()->getIcon();
183
$app_name = $this->getApplication()->getName();
184
$view = id(new PHUIBigInfoView())
185
->setIcon($icon)
186
->setTitle(pht('Welcome to %s', $app_name))
187
->setDescription(
188
pht('Create documents and track signatures.'))
189
->addAction($create_button);
190
191
return $view;
192
}
193
194
}
195
196