diff --git a/src/applications/macro/query/PhabricatorMacroQuery.php b/src/applications/macro/query/PhabricatorMacroQuery.php index d4ffe46107..3ba30502d5 100644 --- a/src/applications/macro/query/PhabricatorMacroQuery.php +++ b/src/applications/macro/query/PhabricatorMacroQuery.php @@ -5,7 +5,7 @@ final class PhabricatorMacroQuery private $ids; private $phids; - private $authors; + private $authorPHIDs; private $names; private $nameLike; private $namePrefix; @@ -51,8 +51,8 @@ final class PhabricatorMacroQuery return $this; } - public function withAuthorPHIDs(array $authors) { - $this->authors = $authors; + public function withAuthorPHIDs(array $author_phids) { + $this->authorPHIDs = $author_phids; return $this; } @@ -96,53 +96,46 @@ final class PhabricatorMacroQuery return $this; } - protected function loadPage() { - $macro_table = new PhabricatorFileImageMacro(); - $conn = $macro_table->establishConnection('r'); - - $rows = queryfx_all( - $conn, - 'SELECT m.* FROM %T m %Q %Q %Q', - $macro_table->getTableName(), - $this->buildWhereClause($conn), - $this->buildOrderClause($conn), - $this->buildLimitClause($conn)); - - return $macro_table->loadAllFromArray($rows); + public function newResultObject() { + return new PhabricatorFileImageMacro(); } - protected function buildWhereClause(AphrontDatabaseConnection $conn) { - $where = array(); + protected function loadPage() { + return $this->loadStandardPage(new PhabricatorFileImageMacro()); + } - if ($this->ids) { + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); + + if ($this->ids !== null) { $where[] = qsprintf( $conn, 'm.id IN (%Ld)', $this->ids); } - if ($this->phids) { + if ($this->phids !== null) { $where[] = qsprintf( $conn, 'm.phid IN (%Ls)', $this->phids); } - if ($this->authors) { + if ($this->authorPHIDs !== null) { $where[] = qsprintf( $conn, 'm.authorPHID IN (%Ls)', - $this->authors); + $this->authorPHIDs); } - if ($this->nameLike) { + if (strlen($this->nameLike)) { $where[] = qsprintf( $conn, 'm.name LIKE %~', $this->nameLike); } - if ($this->names) { + if ($this->names !== null) { $where[] = qsprintf( $conn, 'm.name IN (%Ls)', @@ -210,9 +203,7 @@ final class PhabricatorMacroQuery } } - $where[] = $this->buildPagingClause($conn); - - return $this->formatWhereClause($where); + return $where; } protected function didFilterPage(array $macros) { diff --git a/src/applications/macro/query/PhabricatorMacroSearchEngine.php b/src/applications/macro/query/PhabricatorMacroSearchEngine.php index 8d632e818f..6bf41e35bb 100644 --- a/src/applications/macro/query/PhabricatorMacroSearchEngine.php +++ b/src/applications/macro/query/PhabricatorMacroSearchEngine.php @@ -11,123 +11,83 @@ final class PhabricatorMacroSearchEngine return 'PhabricatorMacroApplication'; } - public function buildSavedQueryFromRequest(AphrontRequest $request) { - $saved = new PhabricatorSavedQuery(); - $saved->setParameter( - 'authorPHIDs', - $this->readUsersFromRequest($request, 'authors')); - - $saved->setParameter('status', $request->getStr('status')); - $saved->setParameter('names', $request->getStrList('names')); - $saved->setParameter('nameLike', $request->getStr('nameLike')); - $saved->setParameter('createdStart', $request->getStr('createdStart')); - $saved->setParameter('createdEnd', $request->getStr('createdEnd')); - $saved->setParameter('flagColor', $request->getStr('flagColor', '-1')); - - $this->saveQueryOrder($saved, $request); - - return $saved; + public function newQuery() { + return id(new PhabricatorMacroQuery()) + ->needFiles(true); } - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { - $query = id(new PhabricatorMacroQuery()) - ->needFiles(true) - ->withIDs($saved->getParameter('ids', array())) - ->withPHIDs($saved->getParameter('phids', array())) - ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())); + protected function buildCustomSearchFields() { + return array( + id(new PhabricatorSearchSelectField()) + ->setLabel(pht('Status')) + ->setKey('status') + ->setOptions(PhabricatorMacroQuery::getStatusOptions()), + id(new PhabricatorSearchUsersField()) + ->setLabel(pht('Authors')) + ->setKey('authorPHIDs') + ->setAliases(array('author', 'authors')), + id(new PhabricatorSearchTextField()) + ->setLabel(pht('Name Contains')) + ->setKey('nameLike'), + id(new PhabricatorSearchStringListField()) + ->setLabel(pht('Exact Names')) + ->setKey('names'), + id(new PhabricatorSearchSelectField()) + ->setLabel(pht('Marked with Flag')) + ->setKey('flagColor') + ->setDefault('-1') + ->setOptions(PhabricatorMacroQuery::getFlagColorsOptions()), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created After')) + ->setKey('createdStart'), + id(new PhabricatorSearchDateField()) + ->setLabel(pht('Created Before')) + ->setKey('createdEnd'), + ); + } - $this->setQueryOrder($query, $saved); + protected function getDefaultFieldOrder() { + return array( + '...', + 'createdStart', + 'createdEnd', + ); + } - $status = $saved->getParameter('status'); - $options = PhabricatorMacroQuery::getStatusOptions(); - if (empty($options[$status])) { - $status = head_key($options); - } - $query->withStatus($status); + public function buildQueryFromParameters(array $map) { + $query = $this->newQuery(); - $names = $saved->getParameter('names', array()); - if ($names) { - $query->withNames($names); + if ($map['authorPHIDs']) { + $query->withAuthorPHIDs($map['authorPHIDs']); } - $like = $saved->getParameter('nameLike'); - if (strlen($like)) { - $query->withNameLike($like); + if ($map['status']) { + $query->withStatus($map['status']); } - $start = $this->parseDateTime($saved->getParameter('createdStart')); - $end = $this->parseDateTime($saved->getParameter('createdEnd')); - - if ($start) { - $query->withDateCreatedAfter($start); + if ($map['names']) { + $query->withNames($map['names']); } - if ($end) { - $query->withDateCreatedBefore($end); + if (strlen($map['nameLike'])) { + $query->withNameLike($map['nameLike']); } - $color = $saved->getParameter('flagColor'); - if (strlen($color)) { - $query->withFlagColor($color); + if ($map['createdStart']) { + $query->withDateCreatedAfter($map['createdStart']); + } + + if ($map['createdEnd']) { + $query->withDateCreatedBefore($map['createdEnd']); + } + + if ($map['flagColor'] !== null) { + $query->withFlagColor($map['flagColor']); } return $query; } - public function buildSearchForm( - AphrontFormView $form, - PhabricatorSavedQuery $saved) { - - $author_phids = $saved->getParameter('authorPHIDs', array()); - $status = $saved->getParameter('status'); - $names = implode(', ', $saved->getParameter('names', array())); - $like = $saved->getParameter('nameLike'); - $color = $saved->getParameter('flagColor', '-1'); - - $form - ->appendChild( - id(new AphrontFormSelectControl()) - ->setName('status') - ->setLabel(pht('Status')) - ->setOptions(PhabricatorMacroQuery::getStatusOptions()) - ->setValue($status)) - ->appendControl( - id(new AphrontFormTokenizerControl()) - ->setDatasource(new PhabricatorPeopleDatasource()) - ->setName('authors') - ->setLabel(pht('Authors')) - ->setValue($author_phids)) - ->appendChild( - id(new AphrontFormTextControl()) - ->setName('nameLike') - ->setLabel(pht('Name Contains')) - ->setValue($like)) - ->appendChild( - id(new AphrontFormTextControl()) - ->setName('names') - ->setLabel(pht('Exact Names')) - ->setValue($names)) - ->appendChild( - id(new AphrontFormSelectControl()) - ->setName('flagColor') - ->setLabel(pht('Marked with Flag')) - ->setOptions(PhabricatorMacroQuery::getFlagColorsOptions()) - ->setValue($color)); - - $this->buildDateRange( - $form, - $saved, - 'createdStart', - pht('Created After'), - 'createdEnd', - pht('Created Before')); - - $this->appendOrderFieldsToForm( - $form, - $saved, - new PhabricatorMacroQuery()); - } - protected function getURI($path) { return '/macro/'.$path; } @@ -165,12 +125,6 @@ final class PhabricatorMacroSearchEngine return parent::buildSavedQueryFromBuiltin($query_key); } - protected function getRequiredHandlePHIDsForResultList( - array $macros, - PhabricatorSavedQuery $query) { - return mpull($macros, 'getAuthorPHID'); - } - protected function renderResultList( array $macros, PhabricatorSavedQuery $query, @@ -178,6 +132,7 @@ final class PhabricatorMacroSearchEngine assert_instances_of($macros, 'PhabricatorFileImageMacro'); $viewer = $this->requireViewer(); + $handles = $viewer->loadHandles(mpull($macros, 'getAuthorPHID')); $xform = PhabricatorFileTransform::getTransformByKey( PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD); diff --git a/src/applications/search/field/PhabricatorSearchSelectField.php b/src/applications/search/field/PhabricatorSearchSelectField.php index ca68415583..0806174220 100644 --- a/src/applications/search/field/PhabricatorSearchSelectField.php +++ b/src/applications/search/field/PhabricatorSearchSelectField.php @@ -4,6 +4,7 @@ final class PhabricatorSearchSelectField extends PhabricatorSearchField { private $options; + private $default; public function setOptions(array $options) { $this->options = $options; @@ -15,7 +16,12 @@ final class PhabricatorSearchSelectField } protected function getDefaultValue() { - return null; + return $this->default; + } + + public function setDefault($default) { + $this->default = $default; + return $this; } protected function getValueFromRequest(AphrontRequest $request, $key) {