Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / almanac / query / AlmanacNamespaceSearchEngine.php
blob14a96d22a0bb7c587a197c6e9026dfe48cee284f
1 <?php
3 final class AlmanacNamespaceSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Almanac Namespaces');
10 public function getApplicationClassName() {
11 return 'PhabricatorAlmanacApplication';
14 public function newQuery() {
15 return new AlmanacNamespaceQuery();
18 protected function buildCustomSearchFields() {
19 return array(
20 id(new PhabricatorSearchTextField())
21 ->setLabel(pht('Name Contains'))
22 ->setKey('match')
23 ->setDescription(pht('Search for namespaces by name substring.')),
27 protected function buildQueryFromParameters(array $map) {
28 $query = $this->newQuery();
30 if ($map['match'] !== null) {
31 $query->withNameNgrams($map['match']);
34 return $query;
37 protected function getURI($path) {
38 return '/almanac/namespace/'.$path;
41 protected function getBuiltinQueryNames() {
42 $names = array(
43 'all' => pht('All Namespaces'),
46 return $names;
49 public function buildSavedQueryFromBuiltin($query_key) {
51 $query = $this->newSavedQuery();
52 $query->setQueryKey($query_key);
54 switch ($query_key) {
55 case 'all':
56 return $query;
59 return parent::buildSavedQueryFromBuiltin($query_key);
62 protected function renderResultList(
63 array $namespaces,
64 PhabricatorSavedQuery $query,
65 array $handles) {
66 assert_instances_of($namespaces, 'AlmanacNamespace');
68 $viewer = $this->requireViewer();
70 $list = new PHUIObjectItemListView();
71 $list->setUser($viewer);
72 foreach ($namespaces as $namespace) {
73 $id = $namespace->getID();
75 $item = id(new PHUIObjectItemView())
76 ->setObjectName(pht('Namespace %d', $id))
77 ->setHeader($namespace->getName())
78 ->setHref($this->getApplicationURI("namespace/{$id}/"))
79 ->setObject($namespace);
81 $list->addItem($item);
84 $result = new PhabricatorApplicationSearchResultView();
85 $result->setObjectList($list);
86 $result->setNoDataString(pht('No Almanac namespaces found.'));
88 return $result;