Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / phame / query / PhamePostSearchEngine.php
blobd1d9a791ec1a1884888d7b1d7d53484959dadd72
1 <?php
3 final class PhamePostSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Phame Posts');
10 public function getApplicationClassName() {
11 return 'PhabricatorPhameApplication';
14 public function newQuery() {
15 return new PhamePostQuery();
18 protected function buildQueryFromParameters(array $map) {
19 $query = $this->newQuery();
21 if ($map['visibility']) {
22 $query->withVisibility($map['visibility']);
24 if ($map['blogPHIDs']) {
25 $query->withBlogPHIDs($map['blogPHIDs']);
29 return $query;
32 protected function buildCustomSearchFields() {
33 return array(
34 id(new PhabricatorSearchCheckboxesField())
35 ->setKey('visibility')
36 ->setLabel(pht('Visibility'))
37 ->setOptions(
38 array(
39 PhameConstants::VISIBILITY_PUBLISHED => pht('Published'),
40 PhameConstants::VISIBILITY_DRAFT => pht('Draft'),
41 PhameConstants::VISIBILITY_ARCHIVED => pht('Archived'),
42 )),
43 id(new PhabricatorSearchDatasourceField())
44 ->setLabel(pht('Blogs'))
45 ->setKey('blogPHIDs')
46 ->setAliases(array('blog', 'blogs', 'blogPHIDs'))
47 ->setDescription(
48 pht('Search for posts within certain blogs.'))
49 ->setDatasource(new PhameBlogDatasource()),
54 protected function getURI($path) {
55 return '/phame/post/'.$path;
58 protected function getBuiltinQueryNames() {
59 $names = array(
60 'all' => pht('All Posts'),
61 'live' => pht('Published Posts'),
62 'draft' => pht('Draft Posts'),
63 'archived' => pht('Archived Posts'),
65 return $names;
68 public function buildSavedQueryFromBuiltin($query_key) {
69 $query = $this->newSavedQuery();
70 $query->setQueryKey($query_key);
72 switch ($query_key) {
73 case 'all':
74 return $query;
75 case 'live':
76 return $query->setParameter(
77 'visibility', array(PhameConstants::VISIBILITY_PUBLISHED));
78 case 'draft':
79 return $query->setParameter(
80 'visibility', array(PhameConstants::VISIBILITY_DRAFT));
81 case 'archived':
82 return $query->setParameter(
83 'visibility', array(PhameConstants::VISIBILITY_ARCHIVED));
86 return parent::buildSavedQueryFromBuiltin($query_key);
90 protected function renderResultList(
91 array $posts,
92 PhabricatorSavedQuery $query,
93 array $handles) {
95 assert_instances_of($posts, 'PhamePost');
96 $viewer = $this->requireViewer();
98 $list = new PHUIObjectItemListView();
99 $list->setUser($viewer);
101 foreach ($posts as $post) {
102 $id = $post->getID();
103 $blog = $post->getBlog();
105 $blog_name = $viewer->renderHandle($post->getBlogPHID())->render();
106 $blog_name = pht('Blog: %s', $blog_name);
108 $item = id(new PHUIObjectItemView())
109 ->setUser($viewer)
110 ->setObject($post)
111 ->setObjectName($post->getMonogram())
112 ->setHeader($post->getTitle())
113 ->setStatusIcon('fa-star')
114 ->setHref($post->getViewURI())
115 ->addAttribute($blog_name);
116 if ($post->isDraft()) {
117 $item->setStatusIcon('fa-star-o grey');
118 $item->setDisabled(true);
119 $item->addIcon('fa-star-o', pht('Draft Post'));
120 } else if ($post->isArchived()) {
121 $item->setStatusIcon('fa-ban grey');
122 $item->setDisabled(true);
123 $item->addIcon('fa-ban', pht('Archived Post'));
124 } else {
125 $date = $post->getDatePublished();
126 $item->setEpoch($date);
128 $item->addAction(
129 id(new PHUIListItemView())
130 ->setIcon('fa-pencil')
131 ->setHref($post->getEditURI()));
132 $list->addItem($item);
135 $result = new PhabricatorApplicationSearchResultView();
136 $result->setObjectList($list);
137 $result->setNoDataString(pht('No blogs posts found.'));
139 return $result;