Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / fund / query / FundInitiativeSearchEngine.php
blobe075fe5063f4844a621a6f949e0d201c5e6bdfe2
1 <?php
3 final class FundInitiativeSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Fund Initiatives');
10 public function getApplicationClassName() {
11 return 'PhabricatorFundApplication';
14 public function newQuery() {
15 return new FundInitiativeQuery();
18 protected function buildCustomSearchFields() {
19 return array(
20 id(new PhabricatorUsersSearchField())
21 ->setKey('ownerPHIDs')
22 ->setAliases(array('owner', 'ownerPHID', 'owners'))
23 ->setLabel(pht('Owners')),
24 id(new PhabricatorSearchCheckboxesField())
25 ->setKey('statuses')
26 ->setLabel(pht('Statuses'))
27 ->setOptions(FundInitiative::getStatusNameMap()),
31 protected function buildQueryFromParameters(array $map) {
32 $query = $this->newQuery();
34 if ($map['ownerPHIDs']) {
35 $query->withOwnerPHIDs($map['ownerPHIDs']);
38 if ($map['statuses']) {
39 $query->withStatuses($map['statuses']);
42 return $query;
45 protected function getURI($path) {
46 return '/fund/'.$path;
49 protected function getBuiltinQueryNames() {
50 $names = array();
52 $names['open'] = pht('Open Initiatives');
53 if ($this->requireViewer()->isLoggedIn()) {
54 $names['owned'] = pht('Owned Initiatives');
56 $names['all'] = pht('All Initiatives');
58 return $names;
61 public function buildSavedQueryFromBuiltin($query_key) {
62 $query = $this->newSavedQuery();
63 $query->setQueryKey($query_key);
65 switch ($query_key) {
66 case 'all':
67 return $query;
68 case 'owned':
69 return $query->setParameter(
70 'ownerPHIDs',
71 array(
72 $this->requireViewer()->getPHID(),
73 ));
74 case 'open':
75 return $query->setParameter(
76 'statuses',
77 array(
78 FundInitiative::STATUS_OPEN,
79 ));
82 return parent::buildSavedQueryFromBuiltin($query_key);
85 protected function renderResultList(
86 array $initiatives,
87 PhabricatorSavedQuery $query,
88 array $handles) {
89 assert_instances_of($initiatives, 'FundInitiative');
91 $viewer = $this->requireViewer();
93 $load_phids = array();
94 foreach ($initiatives as $initiative) {
95 $load_phids[] = $initiative->getOwnerPHID();
98 if ($initiatives) {
99 $edge_query = id(new PhabricatorEdgeQuery())
100 ->withSourcePHIDs(mpull($initiatives, 'getPHID'))
101 ->withEdgeTypes(
102 array(
103 PhabricatorProjectObjectHasProjectEdgeType::EDGECONST,
106 $edge_query->execute();
108 foreach ($edge_query->getDestinationPHIDs() as $phid) {
109 $load_phids[] = $phid;
113 $handles = $viewer->loadHandles($load_phids);
114 $handles = iterator_to_array($handles);
116 $list = new PHUIObjectItemListView();
117 foreach ($initiatives as $initiative) {
118 $owner_handle = $handles[$initiative->getOwnerPHID()];
120 $item = id(new PHUIObjectItemView())
121 ->setObjectName($initiative->getMonogram())
122 ->setHeader($initiative->getName())
123 ->setHref('/'.$initiative->getMonogram())
124 ->addByline(pht('Owner: %s', $owner_handle->renderLink()));
126 if ($initiative->isClosed()) {
127 $item->setDisabled(true);
130 $project_phids = $edge_query->getDestinationPHIDs(
131 array(
132 $initiative->getPHID(),
135 $project_handles = array_select_keys($handles, $project_phids);
136 if ($project_handles) {
137 $item->addAttribute(
138 id(new PHUIHandleTagListView())
139 ->setLimit(4)
140 ->setSlim(true)
141 ->setHandles($project_handles));
144 $list->addItem($item);
147 $result = new PhabricatorApplicationSearchResultView();
148 $result->setObjectList($list);
149 $result->setNoDataString(pht('No initiatives found.'));
151 return $result;