3 final class LegalpadDocumentSearchEngine
4 extends PhabricatorApplicationSearchEngine
{
6 public function getResultTypeDescription() {
7 return pht('Legalpad Documents');
10 public function getApplicationClassName() {
11 return 'PhabricatorLegalpadApplication';
14 public function newQuery() {
15 return id(new LegalpadDocumentQuery())
16 ->needViewerSignatures(true);
19 protected function buildCustomSearchFields() {
21 id(new PhabricatorUsersSearchField())
22 ->setLabel(pht('Signed By'))
23 ->setKey('signerPHIDs')
24 ->setAliases(array('signer', 'signers', 'signerPHID'))
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'))
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'))
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'),
48 protected function buildQueryFromParameters(array $map) {
49 $query = $this->newQuery();
51 if ($map['signerPHIDs']) {
52 $query->withSignerPHIDs($map['signerPHIDs']);
55 if ($map['contributorPHIDs']) {
56 $query->withContributorPHIDs($map['contributorPHIDs']);
59 if ($map['creatorPHIDs']) {
60 $query->withCreatorPHIDs($map['creatorPHIDs']);
63 if ($map['createdStart']) {
64 $query->withDateCreatedAfter($map['createdStart']);
67 if ($map['createdEnd']) {
68 $query->withDateCreatedAfter($map['createdStart']);
74 protected function getURI($path) {
75 return '/legalpad/'.$path;
78 protected function getBuiltinQueryNames() {
81 if ($this->requireViewer()->isLoggedIn()) {
82 $names['signed'] = pht('Signed Documents');
85 $names['all'] = pht('All Documents');
90 public function buildSavedQueryFromBuiltin($query_key) {
91 $query = $this->newSavedQuery();
92 $query->setQueryKey($query_key);
94 $viewer = $this->requireViewer();
98 return $query->setParameter('signerPHIDs', array($viewer->getPHID()));
103 return parent
::buildSavedQueryFromBuiltin($query_key);
106 protected function renderResultList(
108 PhabricatorSavedQuery
$query,
110 assert_instances_of($documents, 'LegalpadDocument');
112 $viewer = $this->requireViewer();
114 $list = new PHUIObjectItemListView();
115 $list->setUser($viewer);
116 foreach ($documents as $document) {
117 $last_updated = phabricator_date($document->getDateModified(), $viewer);
119 $title = $document->getTitle();
121 $item = id(new PHUIObjectItemView())
122 ->setObjectName($document->getMonogram())
124 ->setHref('/'.$document->getMonogram())
125 ->setObject($document);
127 $no_signatures = LegalpadDocument
::SIGNATURE_TYPE_NONE
;
128 if ($document->getSignatureType() == $no_signatures) {
129 $item->addIcon('none', pht('Not Signable'));
132 $type_name = $document->getSignatureTypeName();
133 $type_icon = $document->getSignatureTypeIcon();
134 $item->addIcon($type_icon, $type_name);
136 if ($viewer->getPHID()) {
137 $signature = $document->getUserSignature($viewer->getPHID());
145 id(new PHUIIconView())->setIcon('fa-check-square-o', 'green'),
149 phabricator_date($signature->getDateCreated(), $viewer)),
154 id(new PHUIIconView())->setIcon('fa-square-o', 'grey'),
163 pht('Version %d (%s)', $document->getVersions(), $last_updated));
165 $list->addItem($item);
168 $result = new PhabricatorApplicationSearchResultView();
169 $result->setObjectList($list);
170 $result->setNoDataString(pht('No documents found.'));
175 protected function getNewUserBody() {
176 $create_button = id(new PHUIButtonView())
178 ->setText(pht('Create a Document'))
179 ->setHref('/legalpad/edit/')
180 ->setColor(PHUIButtonView
::GREEN
);
182 $icon = $this->getApplication()->getIcon();
183 $app_name = $this->getApplication()->getName();
184 $view = id(new PHUIBigInfoView())
186 ->setTitle(pht('Welcome to %s', $app_name))
188 pht('Create documents and track signatures. Can also be re-used in '.
189 'other areas of Phabricator, like CLAs.'))
190 ->addAction($create_button);