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() {
20 id(new PhabricatorUsersSearchField())
21 ->setLabel(pht('Matching Users'))
22 ->setKey('effectivePHIDs')
28 ->setDescription(pht('Search for identities by effective user.')),
29 id(new DiffusionIdentityAssigneeSearchField())
30 ->setLabel(pht('Assigned To'))
31 ->setKey('assignedPHIDs')
37 ->setDescription(pht('Search for identities by explicit assignee.')),
38 id(new PhabricatorSearchTextField())
39 ->setLabel(pht('Identity Contains'))
41 ->setDescription(pht('Search for identities by substring.')),
42 id(new PhabricatorSearchThreeStateField())
43 ->setLabel(pht('Has Matching User'))
44 ->setKey('hasEffectivePHID')
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']);
74 protected function getURI($path) {
75 return '/diffusion/identity/'.$path;
78 protected function getBuiltinQueryNames() {
80 'all' => pht('All Identities'),
86 public function buildSavedQueryFromBuiltin($query_key) {
88 $query = $this->newSavedQuery();
89 $query->setQueryKey($query_key);
96 return parent
::buildSavedQueryFromBuiltin($query_key);
99 protected function renderResultList(
101 PhabricatorSavedQuery
$query,
103 assert_instances_of($identities, 'PhabricatorRepositoryIdentity');
105 $viewer = $this->requireViewer();
107 $list = id(new PHUIObjectItemListView())
108 ->setViewer($viewer);
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) {
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) {
143 pht('Explicitly Unassigned'));
144 $status_icon = 'fa-ban';
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.'));