1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +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();
$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');
if (strlen($filter)) {
$macros = $macro_table->loadAllWhere(
'name LIKE %~',
$filter);
$where[] = qsprintf($conn, 'm.name LIKE %~', $filter);
}
$nodata = pht(
'There are no macros matching the filter "%s".',
phutil_escape_html($filter));
$authors = $request->getArr('authors');
if ($authors) {
$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 {
$pager = new AphrontPagerView();
$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
// thousand at most in any reasonable case.
$count = queryfx_one(
$macro_table->establishConnection('r'),
$conn,
'SELECT COUNT(*) N FROM %T',
$macro_table->getTableName());
$count = $count['N'];
@ -42,19 +64,22 @@ final class PhabricatorMacroListController
$nodata = pht('There are no image macros yet.');
}
$author_phids = array_combine($authors, $authors);
$file_phids = mpull($macros, 'getFilePHID');
$files = array();
if ($file_phids) {
$files = id(new PhabricatorFile())->loadAllWhere(
$files = $file_table->loadAllWhere(
"phid IN (%Ls)",
$file_phids);
$author_phids = mpull($files, 'getAuthorPHID', 'getPHID');
$this->loadHandles($author_phids);
$author_phids += mpull($files, 'getAuthorPHID', 'getAuthorPHID');
}
$files_map = mpull($files, null, 'getPHID');
$this->loadHandles($author_phids);
$author_handles = array_select_keys($this->getLoadedHandles(), $authors);
$filter_form = id(new AphrontFormView())
->setMethod('GET')
->setUser($request->getUser())
@ -63,6 +88,12 @@ final class PhabricatorMacroListController
->setName('name')
->setLabel('Name')
->setValue($filter))
->appendChild(
id(new AphrontFormTokenizerControl())
->setName('authors')
->setLabel(pht('Authors'))
->setDatasource('/typeahead/common/users/')
->setValue(mpull($author_handles, 'getFullName')))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue('Filter Image Macros'));
@ -70,7 +101,6 @@ final class PhabricatorMacroListController
$filter_view = new AphrontListFilterView();
$filter_view->appendChild($filter_form);
$has_search = strlen($filter);
$nav = $this->buildSideNavView(
$for_app = false,
$has_search);
@ -107,7 +137,7 @@ final class PhabricatorMacroListController
}
$nav->appendChild($pinboard);
if (!strlen($filter)) {
if (!$has_search) {
$nav->appendChild($pager);
$name = pht('All Macros');
} else {