1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Allow filtering macros by author

Summary: We can make a query class from it later.

Test Plan: Filtered by author and two authors, explained the query.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4599
This commit is contained in:
vrana 2013-01-23 11:40:47 -08:00
parent afc2cabc4f
commit d1865072ea

View file

@ -9,16 +9,38 @@ final class PhabricatorMacroListController
$viewer = $request->getUser(); $viewer = $request->getUser();
$macro_table = new PhabricatorFileImageMacro(); $macro_table = new PhabricatorFileImageMacro();
$file_table = new PhabricatorFile();
$conn = $macro_table->establishConnection('r');
$where = array();
$join = array();
$join[] = qsprintf($conn, '%T m', $macro_table->getTableName());
$filter = $request->getStr('name'); $filter = $request->getStr('name');
if (strlen($filter)) { if (strlen($filter)) {
$macros = $macro_table->loadAllWhere( $where[] = qsprintf($conn, 'm.name LIKE %~', $filter);
'name LIKE %~', }
$filter);
$nodata = pht( $authors = $request->getArr('authors');
'There are no macros matching the filter "%s".', if ($authors) {
phutil_escape_html($filter)); $join[] = qsprintf(
$conn,
'%T f ON m.filePHID = f.phid',
$file_table->getTableName());
$where[] = qsprintf($conn, 'f.authorPHID IN (%Ls)', $authors);
}
$has_search = $where;
if ($has_search) {
$macros = queryfx_all(
$conn,
'SELECT m.*
FROM '.implode(' JOIN ', $join).'
WHERE '.implode(' AND ', $where));
$macros = $macro_table->loadAllFromArray($macros);
$nodata = pht('There are no macros matching the filter.');
} else { } else {
$pager = new AphrontPagerView(); $pager = new AphrontPagerView();
$pager->setOffset($request->getInt('page')); $pager->setOffset($request->getInt('page'));
@ -31,7 +53,7 @@ final class PhabricatorMacroListController
// Get an exact count since the size here is reasonably going to be a few // Get an exact count since the size here is reasonably going to be a few
// thousand at most in any reasonable case. // thousand at most in any reasonable case.
$count = queryfx_one( $count = queryfx_one(
$macro_table->establishConnection('r'), $conn,
'SELECT COUNT(*) N FROM %T', 'SELECT COUNT(*) N FROM %T',
$macro_table->getTableName()); $macro_table->getTableName());
$count = $count['N']; $count = $count['N'];
@ -42,19 +64,22 @@ final class PhabricatorMacroListController
$nodata = pht('There are no image macros yet.'); $nodata = pht('There are no image macros yet.');
} }
$author_phids = array_combine($authors, $authors);
$file_phids = mpull($macros, 'getFilePHID'); $file_phids = mpull($macros, 'getFilePHID');
$files = array(); $files = array();
if ($file_phids) { if ($file_phids) {
$files = id(new PhabricatorFile())->loadAllWhere( $files = $file_table->loadAllWhere(
"phid IN (%Ls)", "phid IN (%Ls)",
$file_phids); $file_phids);
$author_phids = mpull($files, 'getAuthorPHID', 'getPHID'); $author_phids += mpull($files, 'getAuthorPHID', 'getAuthorPHID');
$this->loadHandles($author_phids);
} }
$files_map = mpull($files, null, 'getPHID'); $files_map = mpull($files, null, 'getPHID');
$this->loadHandles($author_phids);
$author_handles = array_select_keys($this->getLoadedHandles(), $authors);
$filter_form = id(new AphrontFormView()) $filter_form = id(new AphrontFormView())
->setMethod('GET') ->setMethod('GET')
->setUser($request->getUser()) ->setUser($request->getUser())
@ -63,6 +88,12 @@ final class PhabricatorMacroListController
->setName('name') ->setName('name')
->setLabel('Name') ->setLabel('Name')
->setValue($filter)) ->setValue($filter))
->appendChild(
id(new AphrontFormTokenizerControl())
->setName('authors')
->setLabel(pht('Authors'))
->setDatasource('/typeahead/common/users/')
->setValue(mpull($author_handles, 'getFullName')))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) id(new AphrontFormSubmitControl())
->setValue('Filter Image Macros')); ->setValue('Filter Image Macros'));
@ -70,7 +101,6 @@ final class PhabricatorMacroListController
$filter_view = new AphrontListFilterView(); $filter_view = new AphrontListFilterView();
$filter_view->appendChild($filter_form); $filter_view->appendChild($filter_form);
$has_search = strlen($filter);
$nav = $this->buildSideNavView( $nav = $this->buildSideNavView(
$for_app = false, $for_app = false,
$has_search); $has_search);
@ -107,7 +137,7 @@ final class PhabricatorMacroListController
} }
$nav->appendChild($pinboard); $nav->appendChild($pinboard);
if (!strlen($filter)) { if (!$has_search) {
$nav->appendChild($pager); $nav->appendChild($pager);
$name = pht('All Macros'); $name = pht('All Macros');
} else { } else {