@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
at upstream/main 151 lines 3.6 kB view raw
1<?php 2 3final class FundBackerSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 private $initiative; 7 8 public function setInitiative(FundInitiative $initiative) { 9 $this->initiative = $initiative; 10 return $this; 11 } 12 13 public function getInitiative() { 14 return $this->initiative; 15 } 16 17 public function getResultTypeDescription() { 18 return pht('Fund Backers'); 19 } 20 21 public function getApplicationClassName() { 22 return PhabricatorFundApplication::class; 23 } 24 25 public function buildSavedQueryFromRequest(AphrontRequest $request) { 26 $saved = new PhabricatorSavedQuery(); 27 28 $saved->setParameter( 29 'backerPHIDs', 30 $this->readUsersFromRequest($request, 'backers')); 31 32 return $saved; 33 } 34 35 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 36 $query = new FundBackerQuery(); 37 38 $query->withStatuses(array(FundBacker::STATUS_PURCHASED)); 39 40 if ($this->getInitiative()) { 41 $query->withInitiativePHIDs( 42 array( 43 $this->getInitiative()->getPHID(), 44 )); 45 } 46 47 $backer_phids = $saved->getParameter('backerPHIDs'); 48 if ($backer_phids) { 49 $query->withBackerPHIDs($backer_phids); 50 } 51 52 return $query; 53 } 54 55 public function buildSearchForm( 56 AphrontFormView $form, 57 PhabricatorSavedQuery $saved) { 58 59 $backer_phids = $saved->getParameter('backerPHIDs', array()); 60 61 $form 62 ->appendControl( 63 id(new AphrontFormTokenizerControl()) 64 ->setLabel(pht('Backers')) 65 ->setName('backers') 66 ->setDatasource(new PhabricatorPeopleDatasource()) 67 ->setValue($backer_phids)); 68 } 69 70 protected function getURI($path) { 71 if ($this->getInitiative()) { 72 return '/fund/backers/'.$this->getInitiative()->getID().'/'.$path; 73 } else { 74 return '/fund/backers/'.$path; 75 } 76 } 77 78 protected function getBuiltinQueryNames() { 79 $names = array(); 80 $names['all'] = pht('All Backers'); 81 82 return $names; 83 } 84 85 public function buildSavedQueryFromBuiltin($query_key) { 86 $query = $this->newSavedQuery(); 87 $query->setQueryKey($query_key); 88 89 switch ($query_key) { 90 case 'all': 91 return $query; 92 } 93 94 return parent::buildSavedQueryFromBuiltin($query_key); 95 } 96 97 protected function getRequiredHandlePHIDsForResultList( 98 array $backers, 99 PhabricatorSavedQuery $query) { 100 101 $phids = array(); 102 foreach ($backers as $backer) { 103 $phids[] = $backer->getBackerPHID(); 104 $phids[] = $backer->getInitiativePHID(); 105 } 106 107 return $phids; 108 } 109 110 protected function renderResultList( 111 array $backers, 112 PhabricatorSavedQuery $query, 113 array $handles) { 114 assert_instances_of($backers, 'FundBacker'); 115 116 $viewer = $this->requireViewer(); 117 118 $rows = array(); 119 foreach ($backers as $backer) { 120 $rows[] = array( 121 $handles[$backer->getInitiativePHID()]->renderLink(), 122 $handles[$backer->getBackerPHID()]->renderLink(), 123 $backer->getAmountAsCurrency()->formatForDisplay(), 124 phabricator_datetime($backer->getDateCreated(), $viewer), 125 ); 126 } 127 128 $table = id(new AphrontTableView($rows)) 129 ->setNoDataString(pht('No backers found.')) 130 ->setHeaders( 131 array( 132 pht('Initiative'), 133 pht('Backer'), 134 pht('Amount'), 135 pht('Date'), 136 )) 137 ->setColumnClasses( 138 array( 139 null, 140 null, 141 'wide right', 142 'right', 143 )); 144 145 $result = new PhabricatorApplicationSearchResultView(); 146 $result->setTable($table); 147 148 return $result; 149 } 150 151}