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']);
32 protected function buildCustomSearchFields() {
34 id(new PhabricatorSearchCheckboxesField())
35 ->setKey('visibility')
36 ->setLabel(pht('Visibility'))
39 PhameConstants
::VISIBILITY_PUBLISHED
=> pht('Published'),
40 PhameConstants
::VISIBILITY_DRAFT
=> pht('Draft'),
41 PhameConstants
::VISIBILITY_ARCHIVED
=> pht('Archived'),
43 id(new PhabricatorSearchDatasourceField())
44 ->setLabel(pht('Blogs'))
46 ->setAliases(array('blog', 'blogs', 'blogPHIDs'))
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() {
60 'all' => pht('All Posts'),
61 'live' => pht('Published Posts'),
62 'draft' => pht('Draft Posts'),
63 'archived' => pht('Archived Posts'),
68 public function buildSavedQueryFromBuiltin($query_key) {
69 $query = $this->newSavedQuery();
70 $query->setQueryKey($query_key);
76 return $query->setParameter(
77 'visibility', array(PhameConstants
::VISIBILITY_PUBLISHED
));
79 return $query->setParameter(
80 'visibility', array(PhameConstants
::VISIBILITY_DRAFT
));
82 return $query->setParameter(
83 'visibility', array(PhameConstants
::VISIBILITY_ARCHIVED
));
86 return parent
::buildSavedQueryFromBuiltin($query_key);
90 protected function renderResultList(
92 PhabricatorSavedQuery
$query,
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())
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'));
125 $date = $post->getDatePublished();
126 $item->setEpoch($date);
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.'));