@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Lightly modernize LegalpadDocumentSearchEngine

Summary: Depends on D18785. Ref T13024. While I'm in here, update this a bit to use the newer stuff.

Test Plan: Searched for Legalpad documents, saw more modern support (subscribers, order by, viewer()).

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T13024

Differential Revision: https://secure.phabricator.com/D18786

+46 -90
+46 -90
src/applications/legalpad/query/LegalpadDocumentSearchEngine.php
··· 11 11 return 'PhabricatorLegalpadApplication'; 12 12 } 13 13 14 - public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 - $saved = new PhabricatorSavedQuery(); 16 - $saved->setParameter( 17 - 'creatorPHIDs', 18 - $this->readUsersFromRequest($request, 'creators')); 19 - 20 - $saved->setParameter( 21 - 'contributorPHIDs', 22 - $this->readUsersFromRequest($request, 'contributors')); 23 - 24 - $saved->setParameter( 25 - 'withViewerSignature', 26 - $request->getBool('withViewerSignature')); 27 - 28 - $saved->setParameter('createdStart', $request->getStr('createdStart')); 29 - $saved->setParameter('createdEnd', $request->getStr('createdEnd')); 14 + public function newQuery() { 15 + return id(new LegalpadDocumentQuery()) 16 + ->needViewerSignatures(true); 17 + } 30 18 31 - return $saved; 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 + ); 32 46 } 33 47 34 - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 35 - $query = id(new LegalpadDocumentQuery()) 36 - ->needViewerSignatures(true); 48 + protected function buildQueryFromParameters(array $map) { 49 + $query = $this->newQuery(); 37 50 38 - $creator_phids = $saved->getParameter('creatorPHIDs', array()); 39 - if ($creator_phids) { 40 - $query->withCreatorPHIDs($creator_phids); 51 + if ($map['signerPHIDs']) { 52 + $query->withSignerPHIDs($map['signerPHIDs']); 41 53 } 42 54 43 - $contributor_phids = $saved->getParameter('contributorPHIDs', array()); 44 - if ($contributor_phids) { 45 - $query->withContributorPHIDs($contributor_phids); 55 + if ($map['contributorPHIDs']) { 56 + $query->withContributorPHIDs($map['creatorPHIDs']); 46 57 } 47 58 48 - if ($saved->getParameter('withViewerSignature')) { 49 - $viewer_phid = $this->requireViewer()->getPHID(); 50 - if ($viewer_phid) { 51 - $query->withSignerPHIDs(array($viewer_phid)); 52 - } 59 + if ($map['creatorPHIDs']) { 60 + $query->withCreatorPHIDs($map['creatorPHIDs']); 53 61 } 54 62 55 - $start = $this->parseDateTime($saved->getParameter('createdStart')); 56 - $end = $this->parseDateTime($saved->getParameter('createdEnd')); 57 - 58 - if ($start) { 59 - $query->withDateCreatedAfter($start); 63 + if ($map['createdStart']) { 64 + $query->withDateCreatedAfter($map['createdStart']); 60 65 } 61 66 62 - if ($end) { 63 - $query->withDateCreatedBefore($end); 67 + if ($map['createdEnd']) { 68 + $query->withDateCreatedAfter($map['createdStart']); 64 69 } 65 70 66 71 return $query; 67 72 } 68 73 69 - public function buildSearchForm( 70 - AphrontFormView $form, 71 - PhabricatorSavedQuery $saved_query) { 72 - 73 - $creator_phids = $saved_query->getParameter('creatorPHIDs', array()); 74 - $contributor_phids = $saved_query->getParameter( 75 - 'contributorPHIDs', array()); 76 - 77 - $viewer_signature = $saved_query->getParameter('withViewerSignature'); 78 - if (!$this->requireViewer()->getPHID()) { 79 - $viewer_signature = false; 80 - } 81 - 82 - $form 83 - ->appendChild( 84 - id(new AphrontFormCheckboxControl()) 85 - ->addCheckbox( 86 - 'withViewerSignature', 87 - 1, 88 - pht('Show only documents I have signed.'), 89 - $viewer_signature) 90 - ->setDisabled(!$this->requireViewer()->getPHID())) 91 - ->appendControl( 92 - id(new AphrontFormTokenizerControl()) 93 - ->setDatasource(new PhabricatorPeopleDatasource()) 94 - ->setName('creators') 95 - ->setLabel(pht('Creators')) 96 - ->setValue($creator_phids)) 97 - ->appendControl( 98 - id(new AphrontFormTokenizerControl()) 99 - ->setDatasource(new PhabricatorPeopleDatasource()) 100 - ->setName('contributors') 101 - ->setLabel(pht('Contributors')) 102 - ->setValue($contributor_phids)); 103 - 104 - $this->buildDateRange( 105 - $form, 106 - $saved_query, 107 - 'createdStart', 108 - pht('Created After'), 109 - 'createdEnd', 110 - pht('Created Before')); 111 - } 112 - 113 74 protected function getURI($path) { 114 75 return '/legalpad/'.$path; 115 76 } ··· 130 91 $query = $this->newSavedQuery(); 131 92 $query->setQueryKey($query_key); 132 93 94 + $viewer = $this->requireViewer(); 95 + 133 96 switch ($query_key) { 134 97 case 'signed': 135 - return $query 136 - ->setParameter('withViewerSignature', true); 98 + return $query->setParameter('signerPHIDs', array($viewer->getPHID())); 137 99 case 'all': 138 100 return $query; 139 101 } 140 102 141 103 return parent::buildSavedQueryFromBuiltin($query_key); 142 - } 143 - 144 - protected function getRequiredHandlePHIDsForResultList( 145 - array $documents, 146 - PhabricatorSavedQuery $query) { 147 - return array(); 148 104 } 149 105 150 106 protected function renderResultList(