Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phame/query/PhamePostSearchEngine.php
| Show All 13 Lines | final class PhamePostSearchEngine | ||||
| public function newQuery() { | public function newQuery() { | ||||
| return new PhamePostQuery(); | return new PhamePostQuery(); | ||||
| } | } | ||||
| protected function buildQueryFromParameters(array $map) { | protected function buildQueryFromParameters(array $map) { | ||||
| $query = $this->newQuery(); | $query = $this->newQuery(); | ||||
| if (strlen($map['visibility'])) { | if (strlen($map['visibility'])) { | ||||
| $query->withVisibility($map['visibility']); | $query->withVisibility(array($map['visibility'])); | ||||
| } | } | ||||
| return $query; | return $query; | ||||
| } | } | ||||
| protected function buildCustomSearchFields() { | protected function buildCustomSearchFields() { | ||||
| return array( | return array( | ||||
| id(new PhabricatorSearchSelectField()) | id(new PhabricatorSearchSelectField()) | ||||
| ->setKey('visibility') | ->setKey('visibility') | ||||
| ->setLabel(pht('Visibility')) | ->setLabel(pht('Visibility')) | ||||
| ->setOptions( | ->setOptions( | ||||
| array( | array( | ||||
| '' => pht('All'), | '' => pht('All'), | ||||
| PhameConstants::VISIBILITY_PUBLISHED => pht('Published'), | PhameConstants::VISIBILITY_PUBLISHED => pht('Published'), | ||||
| PhameConstants::VISIBILITY_DRAFT => pht('Draft'), | PhameConstants::VISIBILITY_DRAFT => pht('Draft'), | ||||
| PhameConstants::VISIBILITY_ARCHIVED => pht('Archived'), | |||||
| )), | )), | ||||
epriestley: probably include archived as an option here? | |||||
| ); | ); | ||||
| } | } | ||||
| protected function getURI($path) { | protected function getURI($path) { | ||||
| return '/phame/post/'.$path; | return '/phame/post/'.$path; | ||||
| } | } | ||||
| protected function getBuiltinQueryNames() { | protected function getBuiltinQueryNames() { | ||||
| $names = array( | $names = array( | ||||
| 'all' => pht('All Posts'), | 'all' => pht('All Posts'), | ||||
| 'live' => pht('Published Posts'), | 'live' => pht('Published Posts'), | ||||
| 'draft' => pht('Draft Posts'), | 'draft' => pht('Draft Posts'), | ||||
| 'archived' => pht('Archived Posts'), | |||||
| ); | ); | ||||
| return $names; | return $names; | ||||
| } | } | ||||
| public function buildSavedQueryFromBuiltin($query_key) { | public function buildSavedQueryFromBuiltin($query_key) { | ||||
| $query = $this->newSavedQuery(); | $query = $this->newSavedQuery(); | ||||
| $query->setQueryKey($query_key); | $query->setQueryKey($query_key); | ||||
| switch ($query_key) { | switch ($query_key) { | ||||
| case 'all': | case 'all': | ||||
| return $query; | return $query; | ||||
| case 'live': | case 'live': | ||||
| return $query->setParameter( | return $query->setParameter( | ||||
| 'visibility', PhameConstants::VISIBILITY_PUBLISHED); | 'visibility', PhameConstants::VISIBILITY_PUBLISHED); | ||||
| case 'draft': | case 'draft': | ||||
| return $query->setParameter( | return $query->setParameter( | ||||
| 'visibility', PhameConstants::VISIBILITY_DRAFT); | 'visibility', PhameConstants::VISIBILITY_DRAFT); | ||||
| case 'archived': | |||||
| return $query->setParameter( | |||||
| 'visibility', PhameConstants::VISIBILITY_ARCHIVED); | |||||
| } | } | ||||
| return parent::buildSavedQueryFromBuiltin($query_key); | return parent::buildSavedQueryFromBuiltin($query_key); | ||||
| } | } | ||||
| protected function renderResultList( | protected function renderResultList( | ||||
| array $posts, | array $posts, | ||||
| Show All 19 Lines | foreach ($posts as $post) { | ||||
| ->setHeader($post->getTitle()) | ->setHeader($post->getTitle()) | ||||
| ->setStatusIcon('fa-star') | ->setStatusIcon('fa-star') | ||||
| ->setHref($post->getViewURI()) | ->setHref($post->getViewURI()) | ||||
| ->addAttribute($blog_name); | ->addAttribute($blog_name); | ||||
| if ($post->isDraft()) { | if ($post->isDraft()) { | ||||
| $item->setStatusIcon('fa-star-o grey'); | $item->setStatusIcon('fa-star-o grey'); | ||||
| $item->setDisabled(true); | $item->setDisabled(true); | ||||
| $item->addIcon('none', pht('Draft Post')); | $item->addIcon('none', pht('Draft Post')); | ||||
| } else if ($post->isArchived()) { | |||||
| $item->setStatusIcon('fa-ban grey'); | |||||
| $item->setDisabled(true); | |||||
| $item->addIcon('none', pht('Archived Post')); | |||||
| } else { | } else { | ||||
| $date = $post->getDatePublished(); | $date = $post->getDatePublished(); | ||||
| $item->setEpoch($date); | $item->setEpoch($date); | ||||
| } | } | ||||
| $list->addItem($item); | $list->addItem($item); | ||||
| } | } | ||||
| $result = new PhabricatorApplicationSearchResultView(); | $result = new PhabricatorApplicationSearchResultView(); | ||||
| $result->setObjectList($list); | $result->setObjectList($list); | ||||
| $result->setNoDataString(pht('No blogs posts found.')); | $result->setNoDataString(pht('No blogs posts found.')); | ||||
| return $result; | return $result; | ||||
| } | } | ||||
| } | } | ||||
probably include archived as an option here?