Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / phame / query / PhameBlogSearchEngine.php
blobeaef32af1ca8fcea53be32c44e0a6e89dcb74551
1 <?php
3 final class PhameBlogSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Phame Blogs');
10 public function getApplicationClassName() {
11 return 'PhabricatorPhameApplication';
14 public function newQuery() {
15 return id(new PhameBlogQuery())
16 ->needProfileImage(true);
19 protected function buildQueryFromParameters(array $map) {
20 $query = $this->newQuery();
21 if ($map['statuses']) {
22 $query->withStatuses(array($map['statuses']));
24 return $query;
27 protected function buildCustomSearchFields() {
28 return array(
29 id(new PhabricatorSearchSelectField())
30 ->setKey('statuses')
31 ->setLabel(pht('Status'))
32 ->setOptions(array(
33 '' => pht('All'),
34 PhameBlog::STATUS_ACTIVE => pht('Active'),
35 PhameBlog::STATUS_ARCHIVED => pht('Archived'),
36 )),
40 protected function getURI($path) {
41 return '/phame/blog/'.$path;
44 protected function getBuiltinQueryNames() {
45 $names = array(
46 'active' => pht('Active Blogs'),
47 'archived' => pht('Archived Blogs'),
48 'all' => pht('All Blogs'),
50 return $names;
53 public function buildSavedQueryFromBuiltin($query_key) {
54 $query = $this->newSavedQuery();
55 $query->setQueryKey($query_key);
57 switch ($query_key) {
58 case 'all':
59 return $query;
60 case 'active':
61 return $query->setParameter(
62 'statuses', PhameBlog::STATUS_ACTIVE);
63 case 'archived':
64 return $query->setParameter(
65 'statuses', PhameBlog::STATUS_ARCHIVED);
68 return parent::buildSavedQueryFromBuiltin($query_key);
70 protected function renderResultList(
71 array $blogs,
72 PhabricatorSavedQuery $query,
73 array $handles) {
75 assert_instances_of($blogs, 'PhameBlog');
76 $viewer = $this->requireViewer();
78 $list = new PHUIObjectItemListView();
79 $list->setUser($viewer);
81 foreach ($blogs as $blog) {
82 $id = $blog->getID();
83 if ($blog->getDomain()) {
84 $domain = $blog->getDomain();
85 } else {
86 $domain = pht('Local Blog');
88 $item = id(new PHUIObjectItemView())
89 ->setUser($viewer)
90 ->setObject($blog)
91 ->setHeader($blog->getName())
92 ->setImageURI($blog->getProfileImageURI())
93 ->setDisabled($blog->isArchived())
94 ->setHref($this->getApplicationURI("/blog/view/{$id}/"))
95 ->addAttribute($domain);
96 if (!$blog->isArchived()) {
97 $button = id(new PHUIButtonView())
98 ->setTag('a')
99 ->setText('New Post')
100 ->setHref($this->getApplicationURI('/post/edit/?blog='.$id))
101 ->setButtonType(PHUIButtonView::BUTTONTYPE_SIMPLE);
102 $item->setSideColumn($button);
105 $list->addItem($item);
108 $result = new PhabricatorApplicationSearchResultView();
109 $result->setObjectList($list);
110 $result->setNoDataString(pht('No blogs found.'));
112 return $result;