Skip to content

Commit 23ec515

Browse files
author
Chad Little
committedJun 30, 2016
Improve PhamePost search options
Summary: Ref T9360. This adds ability to search posts by blog(s) and by type better. Test Plan: Create some posts, search for them. {F1705961} Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T9360 Differential Revision: https://secure.phabricator.com/D16199
1 parent 163f2c4 commit 23ec515

File tree

4 files changed

+81
-7
lines changed

4 files changed

+81
-7
lines changed
 

‎src/__phutil_library_map__.php

+2
Original file line numberDiff line numberDiff line change
@@ -3794,6 +3794,7 @@
37943794
'PhameBlogArchiveController' => 'applications/phame/controller/blog/PhameBlogArchiveController.php',
37953795
'PhameBlogController' => 'applications/phame/controller/blog/PhameBlogController.php',
37963796
'PhameBlogCreateCapability' => 'applications/phame/capability/PhameBlogCreateCapability.php',
3797+
'PhameBlogDatasource' => 'applications/phame/typeahead/PhameBlogDatasource.php',
37973798
'PhameBlogEditConduitAPIMethod' => 'applications/phame/conduit/PhameBlogEditConduitAPIMethod.php',
37983799
'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php',
37993800
'PhameBlogEditEngine' => 'applications/phame/editor/PhameBlogEditEngine.php',
@@ -8698,6 +8699,7 @@
86988699
'PhameBlogArchiveController' => 'PhameBlogController',
86998700
'PhameBlogController' => 'PhameController',
87008701
'PhameBlogCreateCapability' => 'PhabricatorPolicyCapability',
8702+
'PhameBlogDatasource' => 'PhabricatorTypeaheadDatasource',
87018703
'PhameBlogEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
87028704
'PhameBlogEditController' => 'PhameBlogController',
87038705
'PhameBlogEditEngine' => 'PhabricatorEditEngine',

‎src/applications/phame/controller/blog/PhameBlogViewController.php

+8
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ private function renderActions(PhameBlog $blog) {
139139
->setDisabled(!$can_edit)
140140
->setWorkflow(!$can_edit));
141141

142+
$actions->addAction(
143+
id(new PhabricatorActionView())
144+
->setUser($viewer)
145+
->setIcon('fa-search')
146+
->setHref(
147+
$this->getApplicationURI('post/?blog='.$blog->getPHID()))
148+
->setName(pht('Search Posts')));
149+
142150
$actions->addAction(
143151
id(new PhabricatorActionView())
144152
->setUser($viewer)

‎src/applications/phame/query/PhamePostSearchEngine.php

+18-7
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,36 @@ public function newQuery() {
1818
protected function buildQueryFromParameters(array $map) {
1919
$query = $this->newQuery();
2020

21-
if (strlen($map['visibility'])) {
22-
$query->withVisibility(array($map['visibility']));
21+
if ($map['visibility']) {
22+
$query->withVisibility($map['visibility']);
2323
}
24+
if ($map['blogPHIDs']) {
25+
$query->withBlogPHIDs($map['blogPHIDs']);
26+
}
27+
2428

2529
return $query;
2630
}
2731

2832
protected function buildCustomSearchFields() {
2933
return array(
30-
id(new PhabricatorSearchSelectField())
34+
id(new PhabricatorSearchCheckboxesField())
3135
->setKey('visibility')
3236
->setLabel(pht('Visibility'))
3337
->setOptions(
3438
array(
35-
'' => pht('All'),
3639
PhameConstants::VISIBILITY_PUBLISHED => pht('Published'),
3740
PhameConstants::VISIBILITY_DRAFT => pht('Draft'),
3841
PhameConstants::VISIBILITY_ARCHIVED => pht('Archived'),
3942
)),
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()),
50+
4051
);
4152
}
4253

@@ -63,13 +74,13 @@ public function buildSavedQueryFromBuiltin($query_key) {
6374
return $query;
6475
case 'live':
6576
return $query->setParameter(
66-
'visibility', PhameConstants::VISIBILITY_PUBLISHED);
77+
'visibility', array(PhameConstants::VISIBILITY_PUBLISHED));
6778
case 'draft':
6879
return $query->setParameter(
69-
'visibility', PhameConstants::VISIBILITY_DRAFT);
80+
'visibility', array(PhameConstants::VISIBILITY_DRAFT));
7081
case 'archived':
7182
return $query->setParameter(
72-
'visibility', PhameConstants::VISIBILITY_ARCHIVED);
83+
'visibility', array(PhameConstants::VISIBILITY_ARCHIVED));
7384
}
7485

7586
return parent::buildSavedQueryFromBuiltin($query_key);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
final class PhameBlogDatasource
4+
extends PhabricatorTypeaheadDatasource {
5+
6+
public function getBrowseTitle() {
7+
return pht('Browse Blogs');
8+
}
9+
10+
public function getPlaceholderText() {
11+
return pht('Type a blog name...');
12+
}
13+
14+
public function getDatasourceApplicationClass() {
15+
return 'PhabricatorPhameApplication';
16+
}
17+
18+
public function loadResults() {
19+
$viewer = $this->getViewer();
20+
21+
$blogs = id(new PhameBlogQuery())
22+
->setViewer($viewer)
23+
->needProfileImage(true)
24+
->requireCapabilities(
25+
array(
26+
PhabricatorPolicyCapability::CAN_VIEW,
27+
PhabricatorPolicyCapability::CAN_EDIT,
28+
))
29+
->execute();
30+
31+
$results = array();
32+
foreach ($blogs as $blog) {
33+
$closed = null;
34+
35+
$status = $blog->getStatus();
36+
if ($status === PhabricatorBadgesBadge::STATUS_ARCHIVED) {
37+
$closed = pht('Archived');
38+
}
39+
40+
$results[] = id(new PhabricatorTypeaheadResult())
41+
->setName($blog->getName())
42+
->setClosed($closed)
43+
->addAttribute(pht('Phame Blog'))
44+
->setImageURI($blog->getProfileImageURI())
45+
->setPHID($blog->getPHID());
46+
}
47+
48+
$results = $this->filterResultsAgainstTokens($results);
49+
50+
return $results;
51+
}
52+
53+
}

0 commit comments

Comments
 (0)
Failed to load comments.