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() {
20 id(new PhabricatorUsersSearchField())
21 ->setKey('ownerPHIDs')
22 ->setAliases(array('owner', 'ownerPHID', 'owners'))
23 ->setLabel(pht('Owners')),
24 id(new PhabricatorSearchCheckboxesField())
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']);
45 protected function getURI($path) {
46 return '/fund/'.$path;
49 protected function getBuiltinQueryNames() {
52 $names['open'] = pht('Open Initiatives');
53 if ($this->requireViewer()->isLoggedIn()) {
54 $names['owned'] = pht('Owned Initiatives');
56 $names['all'] = pht('All Initiatives');
61 public function buildSavedQueryFromBuiltin($query_key) {
62 $query = $this->newSavedQuery();
63 $query->setQueryKey($query_key);
69 return $query->setParameter(
72 $this->requireViewer()->getPHID(),
75 return $query->setParameter(
78 FundInitiative
::STATUS_OPEN
,
82 return parent
::buildSavedQueryFromBuiltin($query_key);
85 protected function renderResultList(
87 PhabricatorSavedQuery
$query,
89 assert_instances_of($initiatives, 'FundInitiative');
91 $viewer = $this->requireViewer();
93 $load_phids = array();
94 foreach ($initiatives as $initiative) {
95 $load_phids[] = $initiative->getOwnerPHID();
99 $edge_query = id(new PhabricatorEdgeQuery())
100 ->withSourcePHIDs(mpull($initiatives, 'getPHID'))
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(
132 $initiative->getPHID(),
135 $project_handles = array_select_keys($handles, $project_phids);
136 if ($project_handles) {
138 id(new PHUIHandleTagListView())
141 ->setHandles($project_handles));
144 $list->addItem($item);
147 $result = new PhabricatorApplicationSearchResultView();
148 $result->setObjectList($list);
149 $result->setNoDataString(pht('No initiatives found.'));