Changeset View
Changeset View
Standalone View
Standalone View
src/applications/macro/query/PhabricatorMacroSearchEngine.php
Show All 11 Lines | final class PhabricatorMacroSearchEngine | ||||
} | } | ||||
public function buildSavedQueryFromRequest(AphrontRequest $request) { | public function buildSavedQueryFromRequest(AphrontRequest $request) { | ||||
$saved = new PhabricatorSavedQuery(); | $saved = new PhabricatorSavedQuery(); | ||||
$saved->setParameter( | $saved->setParameter( | ||||
'authorPHIDs', | 'authorPHIDs', | ||||
$this->readUsersFromRequest($request, 'authors')); | $this->readUsersFromRequest($request, 'authors')); | ||||
$abuser_phids = $this->readUsersFromRequest($request, 'abusers'); | |||||
$saved->setParameter( | |||||
'abuserPHIDs', | |||||
$abuser_phids); | |||||
$saved->setParameter('popularitySort', !empty($abuser_phids)); | |||||
$saved->setParameter('status', $request->getStr('status')); | $saved->setParameter('status', $request->getStr('status')); | ||||
$saved->setParameter('names', $request->getStrList('names')); | $saved->setParameter('names', $request->getStrList('names')); | ||||
$saved->setParameter('nameLike', $request->getStr('nameLike')); | $saved->setParameter('nameLike', $request->getStr('nameLike')); | ||||
$saved->setParameter('createdStart', $request->getStr('createdStart')); | $saved->setParameter('createdStart', $request->getStr('createdStart')); | ||||
$saved->setParameter('createdEnd', $request->getStr('createdEnd')); | $saved->setParameter('createdEnd', $request->getStr('createdEnd')); | ||||
$saved->setParameter('flagColor', $request->getStr('flagColor', '-1')); | $saved->setParameter('flagColor', $request->getStr('flagColor', '-1')); | ||||
$this->saveQueryOrder($saved, $request); | $this->saveQueryOrder($saved, $request); | ||||
return $saved; | return $saved; | ||||
} | } | ||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { | public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { | ||||
$query = id(new PhabricatorMacroQuery()) | $query = id(new PhabricatorMacroQuery()) | ||||
->needFiles(true) | ->needFiles(true) | ||||
->withIDs($saved->getParameter('ids', array())) | ->withIDs($saved->getParameter('ids', array())) | ||||
->withPHIDs($saved->getParameter('phids', array())) | ->withPHIDs($saved->getParameter('phids', array())) | ||||
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())); | ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())) | ||||
->withAbuserPHIDs($saved->getParameter('abuserPHIDs', array())) | |||||
->withPopularitySort($saved->getParameter('popularitySort', false)); | |||||
$this->setQueryOrder($query, $saved); | $this->setQueryOrder($query, $saved); | ||||
$status = $saved->getParameter('status'); | $status = $saved->getParameter('status'); | ||||
$options = PhabricatorMacroQuery::getStatusOptions(); | $options = PhabricatorMacroQuery::getStatusOptions(); | ||||
if (empty($options[$status])) { | if (empty($options[$status])) { | ||||
$status = head_key($options); | $status = head_key($options); | ||||
} | } | ||||
Show All 28 Lines | public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { | ||||
return $query; | return $query; | ||||
} | } | ||||
public function buildSearchForm( | public function buildSearchForm( | ||||
AphrontFormView $form, | AphrontFormView $form, | ||||
PhabricatorSavedQuery $saved) { | PhabricatorSavedQuery $saved) { | ||||
$author_phids = $saved->getParameter('authorPHIDs', array()); | $author_phids = $saved->getParameter('authorPHIDs', array()); | ||||
$abuser_phids = $saved->getParameter('abuserPHIDs', array()); | |||||
$status = $saved->getParameter('status'); | $status = $saved->getParameter('status'); | ||||
$names = implode(', ', $saved->getParameter('names', array())); | $names = implode(', ', $saved->getParameter('names', array())); | ||||
$like = $saved->getParameter('nameLike'); | $like = $saved->getParameter('nameLike'); | ||||
$color = $saved->getParameter('flagColor', '-1'); | $color = $saved->getParameter('flagColor', '-1'); | ||||
$form | $form | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormSelectControl()) | id(new AphrontFormSelectControl()) | ||||
->setName('status') | ->setName('status') | ||||
->setLabel(pht('Status')) | ->setLabel(pht('Status')) | ||||
->setOptions(PhabricatorMacroQuery::getStatusOptions()) | ->setOptions(PhabricatorMacroQuery::getStatusOptions()) | ||||
->setValue($status)) | ->setValue($status)) | ||||
->appendControl( | ->appendControl( | ||||
id(new AphrontFormTokenizerControl()) | id(new AphrontFormTokenizerControl()) | ||||
->setDatasource(new PhabricatorPeopleDatasource()) | ->setDatasource(new PhabricatorPeopleDatasource()) | ||||
->setName('authors') | ->setName('authors') | ||||
->setLabel(pht('Authors')) | ->setLabel(pht('Authors')) | ||||
->setValue($author_phids)) | ->setValue($author_phids)) | ||||
->appendControl( | |||||
id(new AphrontFormTokenizerControl()) | |||||
->setDatasource(new PhabricatorPeopleDatasource()) | |||||
->setName('abusers') | |||||
->setLabel(pht('Abused By')) | |||||
->setValue($abuser_phids)) | |||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setName('nameLike') | ->setName('nameLike') | ||||
->setLabel(pht('Name Contains')) | ->setLabel(pht('Name Contains')) | ||||
->setValue($like)) | ->setValue($like)) | ||||
->appendChild( | ->appendChild( | ||||
id(new AphrontFormTextControl()) | id(new AphrontFormTextControl()) | ||||
->setName('names') | ->setName('names') | ||||
Show All 22 Lines | final class PhabricatorMacroSearchEngine | ||||
protected function getURI($path) { | protected function getURI($path) { | ||||
return '/macro/'.$path; | return '/macro/'.$path; | ||||
} | } | ||||
protected function getBuiltinQueryNames() { | protected function getBuiltinQueryNames() { | ||||
$names = array( | $names = array( | ||||
'active' => pht('Active'), | 'active' => pht('Active'), | ||||
'all' => pht('All'), | 'recent' => pht('Recent'), | ||||
'popular' => pht('Popular'), | |||||
); | ); | ||||
if ($this->requireViewer()->isLoggedIn()) { | if ($this->requireViewer()->isLoggedIn()) { | ||||
$names['authored'] = pht('Authored'); | $names['authored'] = pht('Authored'); | ||||
$names['favorites'] = pht('Favorites'); | |||||
} | } | ||||
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 'active': | case 'active': | ||||
return $query; | return $query; | ||||
case 'all': | case 'recent': | ||||
return $query->setParameter( | return $query->setParameter( | ||||
'status', | 'status', | ||||
PhabricatorMacroQuery::STATUS_ANY); | PhabricatorMacroQuery::STATUS_ANY); | ||||
case 'authored': | case 'authored': | ||||
return $query->setParameter( | return $query->setParameter( | ||||
'authorPHIDs', | 'authorPHIDs', | ||||
array($this->requireViewer()->getPHID())); | array($this->requireViewer()->getPHID())); | ||||
case 'popular': | |||||
return $query | |||||
->setParameter( | |||||
'status', | |||||
PhabricatorMacroQuery::STATUS_ANY) | |||||
->setParameter( | |||||
'popularitySort', | |||||
true); | |||||
case 'favorites': | |||||
return $query | |||||
->setParameter( | |||||
'status', | |||||
PhabricatorMacroQuery::STATUS_ANY) | |||||
->setParameter( | |||||
'popularitySort', | |||||
true) | |||||
->setParameter( | |||||
'abuserPHIDs', | |||||
array($this->requireViewer()->getPHID())); | |||||
} | } | ||||
return parent::buildSavedQueryFromBuiltin($query_key); | return parent::buildSavedQueryFromBuiltin($query_key); | ||||
} | } | ||||
protected function getRequiredHandlePHIDsForResultList( | protected function getRequiredHandlePHIDsForResultList( | ||||
array $macros, | array $macros, | ||||
PhabricatorSavedQuery $query) { | PhabricatorSavedQuery $query) { | ||||
return mpull($macros, 'getAuthorPHID'); | return array_merge( | ||||
mpull($macros, 'getAuthorPHID'), | |||||
ipull(mpull($macros, 'getPopularity'), 'top_abuser')); | |||||
} | } | ||||
protected function renderResultList( | protected function renderResultList( | ||||
array $macros, | array $macros, | ||||
PhabricatorSavedQuery $query, | PhabricatorSavedQuery $query, | ||||
array $handles) { | array $handles) { | ||||
assert_instances_of($macros, 'PhabricatorFileImageMacro'); | assert_instances_of($macros, 'PhabricatorFileImageMacro'); | ||||
Show All 27 Lines | foreach ($macros as $macro) { | ||||
} | } | ||||
if ($macro->getAuthorPHID()) { | if ($macro->getAuthorPHID()) { | ||||
$author_handle = $handles[$macro->getAuthorPHID()]; | $author_handle = $handles[$macro->getAuthorPHID()]; | ||||
$item->appendChild( | $item->appendChild( | ||||
pht('Created by %s', $author_handle->renderLink())); | pht('Created by %s', $author_handle->renderLink())); | ||||
} | } | ||||
$popularity = $macro->getPopularity(); | |||||
if ($popularity != null) { | |||||
$popularizer_phid = $popularity['top_abuser']; | |||||
$item->appendChild( | |||||
phutil_tag( | |||||
'div', | |||||
array(), | |||||
pht('Popularity %d', $popularity['popularity']))); | |||||
$message = $popularity['popularity'] == 0 ? | |||||
pht('Wow. This macro must suck.') : | |||||
pht('Abused most by %s (%d time%s)', | |||||
$handles[$popularizer_phid]->renderLink(), | |||||
$popularity['top_abuser_count'], | |||||
$popularity['top_abuser_count'] != 1 ? 's' : ''); | |||||
$item->appendChild( | |||||
phutil_tag( | |||||
'div', | |||||
array(), | |||||
$message)); | |||||
} | |||||
$item->setURI($this->getApplicationURI('/view/'.$macro->getID().'/')); | $item->setURI($this->getApplicationURI('/view/'.$macro->getID().'/')); | ||||
$item->setDisabled($macro->getisDisabled()); | $item->setDisabled($macro->getisDisabled()); | ||||
$item->setHeader($macro->getName()); | $item->setHeader($macro->getName()); | ||||
$pinboard->addItem($item); | $pinboard->addItem($item); | ||||
} | } | ||||
return $pinboard; | return $pinboard; | ||||
} | } | ||||
} | } |