Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / diffusion / query / DiffusionRepositoryIdentitySearchEngine.php
blobf41b6b89a4ad97494f448472692b20a9a91e23bc
1 <?php
3 final class DiffusionRepositoryIdentitySearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Repository Identities');
10 public function getApplicationClassName() {
11 return 'PhabricatorDiffusionApplication';
14 public function newQuery() {
15 return new PhabricatorRepositoryIdentityQuery();
18 protected function buildCustomSearchFields() {
19 return array(
20 id(new PhabricatorUsersSearchField())
21 ->setLabel(pht('Matching Users'))
22 ->setKey('effectivePHIDs')
23 ->setAliases(
24 array(
25 'effective',
26 'effectivePHID',
28 ->setDescription(pht('Search for identities by effective user.')),
29 id(new DiffusionIdentityAssigneeSearchField())
30 ->setLabel(pht('Assigned To'))
31 ->setKey('assignedPHIDs')
32 ->setAliases(
33 array(
34 'assigned',
35 'assignedPHID',
37 ->setDescription(pht('Search for identities by explicit assignee.')),
38 id(new PhabricatorSearchTextField())
39 ->setLabel(pht('Identity Contains'))
40 ->setKey('match')
41 ->setDescription(pht('Search for identities by substring.')),
42 id(new PhabricatorSearchThreeStateField())
43 ->setLabel(pht('Has Matching User'))
44 ->setKey('hasEffectivePHID')
45 ->setOptions(
46 pht('(Show All)'),
47 pht('Show Identities With Matching Users'),
48 pht('Show Identities Without Matching Users')),
52 protected function buildQueryFromParameters(array $map) {
53 $query = $this->newQuery();
55 if ($map['hasEffectivePHID'] !== null) {
56 $query->withHasEffectivePHID($map['hasEffectivePHID']);
59 if ($map['match'] !== null) {
60 $query->withIdentityNameLike($map['match']);
63 if ($map['assignedPHIDs']) {
64 $query->withAssignedPHIDs($map['assignedPHIDs']);
67 if ($map['effectivePHIDs']) {
68 $query->withEffectivePHIDs($map['effectivePHIDs']);
71 return $query;
74 protected function getURI($path) {
75 return '/diffusion/identity/'.$path;
78 protected function getBuiltinQueryNames() {
79 $names = array(
80 'all' => pht('All Identities'),
83 return $names;
86 public function buildSavedQueryFromBuiltin($query_key) {
88 $query = $this->newSavedQuery();
89 $query->setQueryKey($query_key);
91 switch ($query_key) {
92 case 'all':
93 return $query;
96 return parent::buildSavedQueryFromBuiltin($query_key);
99 protected function renderResultList(
100 array $identities,
101 PhabricatorSavedQuery $query,
102 array $handles) {
103 assert_instances_of($identities, 'PhabricatorRepositoryIdentity');
105 $viewer = $this->requireViewer();
107 $list = id(new PHUIObjectItemListView())
108 ->setViewer($viewer);
110 $phids = array();
111 foreach ($identities as $identity) {
112 $phids[] = $identity->getCurrentEffectiveUserPHID();
113 $phids[] = $identity->getManuallySetUserPHID();
116 $handles = $viewer->loadHandles($phids);
118 $unassigned = DiffusionIdentityUnassignedDatasource::FUNCTION_TOKEN;
120 foreach ($identities as $identity) {
121 $item = id(new PHUIObjectItemView())
122 ->setObjectName($identity->getObjectName())
123 ->setHeader($identity->getIdentityShortName())
124 ->setHref($identity->getURI())
125 ->setObject($identity);
127 $status_icon = 'fa-circle-o grey';
129 $effective_phid = $identity->getCurrentEffectiveUserPHID();
130 if ($effective_phid) {
131 $item->addIcon(
132 'fa-id-badge',
133 pht('Matches User: %s', $handles[$effective_phid]->getName()));
135 $status_icon = 'fa-id-badge';
138 $assigned_phid = $identity->getManuallySetUserPHID();
139 if ($assigned_phid) {
140 if ($assigned_phid === $unassigned) {
141 $item->addIcon(
142 'fa-ban',
143 pht('Explicitly Unassigned'));
144 $status_icon = 'fa-ban';
145 } else {
146 $item->addIcon(
147 'fa-user',
148 pht('Assigned To: %s', $handles[$assigned_phid]->getName()));
149 $status_icon = 'fa-user';
153 $item->setStatusIcon($status_icon);
155 $list->addItem($item);
158 $result = new PhabricatorApplicationSearchResultView();
159 $result->setObjectList($list);
160 $result->setNoDataString(pht('No Identities found.'));
162 return $result;