Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / fund / query / FundBackerSearchEngine.php
blobba4b3bc39e43dbf80e23e427439e35d1c0a5d242
1 <?php
3 final class FundBackerSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 private $initiative;
8 public function setInitiative(FundInitiative $initiative) {
9 $this->initiative = $initiative;
10 return $this;
13 public function getInitiative() {
14 return $this->initiative;
17 public function getResultTypeDescription() {
18 return pht('Fund Backers');
21 public function getApplicationClassName() {
22 return 'PhabricatorFundApplication';
25 public function buildSavedQueryFromRequest(AphrontRequest $request) {
26 $saved = new PhabricatorSavedQuery();
28 $saved->setParameter(
29 'backerPHIDs',
30 $this->readUsersFromRequest($request, 'backers'));
32 return $saved;
35 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
36 $query = id(new FundBackerQuery());
38 $query->withStatuses(array(FundBacker::STATUS_PURCHASED));
40 if ($this->getInitiative()) {
41 $query->withInitiativePHIDs(
42 array(
43 $this->getInitiative()->getPHID(),
44 ));
47 $backer_phids = $saved->getParameter('backerPHIDs');
48 if ($backer_phids) {
49 $query->withBackerPHIDs($backer_phids);
52 return $query;
55 public function buildSearchForm(
56 AphrontFormView $form,
57 PhabricatorSavedQuery $saved) {
59 $backer_phids = $saved->getParameter('backerPHIDs', array());
61 $form
62 ->appendControl(
63 id(new AphrontFormTokenizerControl())
64 ->setLabel(pht('Backers'))
65 ->setName('backers')
66 ->setDatasource(new PhabricatorPeopleDatasource())
67 ->setValue($backer_phids));
70 protected function getURI($path) {
71 if ($this->getInitiative()) {
72 return '/fund/backers/'.$this->getInitiative()->getID().'/'.$path;
73 } else {
74 return '/fund/backers/'.$path;
78 protected function getBuiltinQueryNames() {
79 $names = array();
80 $names['all'] = pht('All Backers');
82 return $names;
85 public function buildSavedQueryFromBuiltin($query_key) {
86 $query = $this->newSavedQuery();
87 $query->setQueryKey($query_key);
89 switch ($query_key) {
90 case 'all':
91 return $query;
94 return parent::buildSavedQueryFromBuiltin($query_key);
97 protected function getRequiredHandlePHIDsForResultList(
98 array $backers,
99 PhabricatorSavedQuery $query) {
101 $phids = array();
102 foreach ($backers as $backer) {
103 $phids[] = $backer->getBackerPHID();
104 $phids[] = $backer->getInitiativePHID();
107 return $phids;
110 protected function renderResultList(
111 array $backers,
112 PhabricatorSavedQuery $query,
113 array $handles) {
114 assert_instances_of($backers, 'FundBacker');
116 $viewer = $this->requireViewer();
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),
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'),
137 ->setColumnClasses(
138 array(
139 null,
140 null,
141 'wide right',
142 'right',
145 $result = new PhabricatorApplicationSearchResultView();
146 $result->setTable($table);
148 return $result;