Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / almanac / query / AlmanacDeviceSearchEngine.php
blob9f98abb292f1f1477998d76906d44f7f3f910040
1 <?php
3 final class AlmanacDeviceSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Almanac Devices');
10 public function getApplicationClassName() {
11 return 'PhabricatorAlmanacApplication';
14 public function newQuery() {
15 return new AlmanacDeviceQuery();
18 protected function buildCustomSearchFields() {
19 $status_options = AlmanacDeviceStatus::getStatusMap();
20 $status_options = mpull($status_options, 'getName');
22 return array(
23 id(new PhabricatorSearchTextField())
24 ->setLabel(pht('Name Contains'))
25 ->setKey('match')
26 ->setDescription(pht('Search for devices by name substring.')),
27 id(new PhabricatorSearchStringListField())
28 ->setLabel(pht('Exact Names'))
29 ->setKey('names')
30 ->setDescription(pht('Search for devices with specific names.')),
31 id(new PhabricatorSearchCheckboxesField())
32 ->setLabel(pht('Statuses'))
33 ->setKey('statuses')
34 ->setDescription(pht('Search for devices with given statuses.'))
35 ->setOptions($status_options),
36 id(new PhabricatorSearchThreeStateField())
37 ->setLabel(pht('Cluster Device'))
38 ->setKey('isClusterDevice')
39 ->setOptions(
40 pht('Both Cluster and Non-cluster Devices'),
41 pht('Cluster Devices Only'),
42 pht('Non-cluster Devices Only')),
46 protected function buildQueryFromParameters(array $map) {
47 $query = $this->newQuery();
49 if ($map['match'] !== null) {
50 $query->withNameNgrams($map['match']);
53 if ($map['names']) {
54 $query->withNames($map['names']);
57 if ($map['isClusterDevice'] !== null) {
58 $query->withIsClusterDevice($map['isClusterDevice']);
61 if ($map['statuses']) {
62 $query->withStatuses($map['statuses']);
65 return $query;
68 protected function getURI($path) {
69 return '/almanac/device/'.$path;
72 protected function getBuiltinQueryNames() {
73 $names = array(
74 'active' => pht('Active Devices'),
75 'all' => pht('All Devices'),
78 return $names;
81 public function buildSavedQueryFromBuiltin($query_key) {
82 $query = $this->newSavedQuery();
83 $query->setQueryKey($query_key);
85 switch ($query_key) {
86 case 'active':
87 $active_statuses = AlmanacDeviceStatus::getActiveStatusList();
88 return $query->setParameter('statuses', $active_statuses);
89 case 'all':
90 return $query;
93 return parent::buildSavedQueryFromBuiltin($query_key);
96 protected function renderResultList(
97 array $devices,
98 PhabricatorSavedQuery $query,
99 array $handles) {
100 assert_instances_of($devices, 'AlmanacDevice');
102 $viewer = $this->requireViewer();
104 $list = new PHUIObjectItemListView();
105 $list->setUser($viewer);
106 foreach ($devices as $device) {
107 $item = id(new PHUIObjectItemView())
108 ->setObjectName(pht('Device %d', $device->getID()))
109 ->setHeader($device->getName())
110 ->setHref($device->getURI())
111 ->setObject($device);
113 if ($device->isClusterDevice()) {
114 $item->addIcon('fa-sitemap', pht('Cluster Device'));
117 if ($device->isDisabled()) {
118 $item->setDisabled(true);
121 $status = $device->getStatusObject();
122 $icon_icon = $status->getIconIcon();
123 $icon_color = $status->getIconColor();
124 $icon_label = $status->getName();
126 $item->setStatusIcon(
127 "{$icon_icon} {$icon_color}",
128 $icon_label);
130 $list->addItem($item);
133 $result = new PhabricatorApplicationSearchResultView();
134 $result->setObjectList($list);
135 $result->setNoDataString(pht('No Almanac Devices found.'));
137 return $result;