Page MenuHomePhabricator

D16199.id38962.diff
No OneTemporary

D16199.id38962.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -3792,6 +3792,7 @@
'PhameBlogArchiveController' => 'applications/phame/controller/blog/PhameBlogArchiveController.php',
'PhameBlogController' => 'applications/phame/controller/blog/PhameBlogController.php',
'PhameBlogCreateCapability' => 'applications/phame/capability/PhameBlogCreateCapability.php',
+ 'PhameBlogDatasource' => 'applications/phame/typeahead/PhameBlogDatasource.php',
'PhameBlogEditConduitAPIMethod' => 'applications/phame/conduit/PhameBlogEditConduitAPIMethod.php',
'PhameBlogEditController' => 'applications/phame/controller/blog/PhameBlogEditController.php',
'PhameBlogEditEngine' => 'applications/phame/editor/PhameBlogEditEngine.php',
@@ -8694,6 +8695,7 @@
'PhameBlogArchiveController' => 'PhameBlogController',
'PhameBlogController' => 'PhameController',
'PhameBlogCreateCapability' => 'PhabricatorPolicyCapability',
+ 'PhameBlogDatasource' => 'PhabricatorTypeaheadDatasource',
'PhameBlogEditConduitAPIMethod' => 'PhabricatorEditEngineAPIMethod',
'PhameBlogEditController' => 'PhameBlogController',
'PhameBlogEditEngine' => 'PhabricatorEditEngine',
diff --git a/src/applications/phame/query/PhamePostSearchEngine.php b/src/applications/phame/query/PhamePostSearchEngine.php
--- a/src/applications/phame/query/PhamePostSearchEngine.php
+++ b/src/applications/phame/query/PhamePostSearchEngine.php
@@ -18,25 +18,36 @@
protected function buildQueryFromParameters(array $map) {
$query = $this->newQuery();
- if (strlen($map['visibility'])) {
- $query->withVisibility(array($map['visibility']));
+ if ($map['visibility']) {
+ $query->withVisibility($map['visibility']);
}
+ if ($map['blogs']) {
+ $query->withBlogPHIDs($map['blogs']);
+ }
+
return $query;
}
protected function buildCustomSearchFields() {
return array(
- id(new PhabricatorSearchSelectField())
+ id(new PhabricatorSearchCheckboxesField())
->setKey('visibility')
->setLabel(pht('Visibility'))
->setOptions(
array(
- '' => pht('All'),
PhameConstants::VISIBILITY_PUBLISHED => pht('Published'),
PhameConstants::VISIBILITY_DRAFT => pht('Draft'),
PhameConstants::VISIBILITY_ARCHIVED => pht('Archived'),
)),
+ id(new PhabricatorSearchDatasourceField())
+ ->setLabel(pht('Blogs'))
+ ->setKey('blogs')
+ ->setAliases(array('blogs'))
+ ->setDescription(
+ pht('Search for posts with certain blogs.'))
+ ->setDatasource(new PhameBlogDatasource()),
+
);
}
@@ -63,13 +74,13 @@
return $query;
case 'live':
return $query->setParameter(
- 'visibility', PhameConstants::VISIBILITY_PUBLISHED);
+ 'visibility', array(PhameConstants::VISIBILITY_PUBLISHED));
case 'draft':
return $query->setParameter(
- 'visibility', PhameConstants::VISIBILITY_DRAFT);
+ 'visibility', array(PhameConstants::VISIBILITY_DRAFT));
case 'archived':
return $query->setParameter(
- 'visibility', PhameConstants::VISIBILITY_ARCHIVED);
+ 'visibility', array(PhameConstants::VISIBILITY_ARCHIVED));
}
return parent::buildSavedQueryFromBuiltin($query_key);
diff --git a/src/applications/phame/typeahead/PhameBlogDatasource.php b/src/applications/phame/typeahead/PhameBlogDatasource.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phame/typeahead/PhameBlogDatasource.php
@@ -0,0 +1,56 @@
+<?php
+
+final class PhameBlogDatasource
+ extends PhabricatorTypeaheadDatasource {
+
+ public function getBrowseTitle() {
+ return pht('Browse Blogs');
+ }
+
+ public function getPlaceholderText() {
+ return pht('Type a blog name...');
+ }
+
+ public function getDatasourceApplicationClass() {
+ return 'PhabricatorPhameApplication';
+ }
+
+ public function loadResults() {
+ $viewer = $this->getViewer();
+ $raw_query = $this->getRawQuery();
+
+ $params = $this->getParameters();
+
+ $blogs = id(new PhameBlogQuery())
+ ->setViewer($viewer)
+ ->needProfileImage(true)
+ ->requireCapabilities(
+ array(
+ PhabricatorPolicyCapability::CAN_VIEW,
+ PhabricatorPolicyCapability::CAN_EDIT,
+ ))
+ ->execute();
+
+ $results = array();
+ foreach ($blogs as $blog) {
+ $closed = null;
+
+ $status = $blog->getStatus();
+ if ($status === PhabricatorBadgesBadge::STATUS_ARCHIVED) {
+ $closed = pht('Archived');
+ }
+
+ $results[] = id(new PhabricatorTypeaheadResult())
+ ->setName($blog->getName())
+ ->setClosed($closed)
+ ->addAttribute(pht('Phame Blog'))
+ ->setImageURI($blog->getProfileImageURI())
+ ->setPHID($blog->getPHID());
+ }
+
+ $results = $this->filterResultsAgainstTokens($results);
+
+ return $results;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Thu, Nov 7, 1:53 AM (1 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6748105
Default Alt Text
D16199.id38962.diff (4 KB)

Event Timeline