diff --git a/src/applications/pholio/query/PholioMockQuery.php b/src/applications/pholio/query/PholioMockQuery.php index 2f6edd313f..f431ec07a1 100644 --- a/src/applications/pholio/query/PholioMockQuery.php +++ b/src/applications/pholio/query/PholioMockQuery.php @@ -59,10 +59,14 @@ final class PholioMockQuery $data = queryfx_all( $conn_r, - 'SELECT * FROM %T %Q %Q %Q', + '%Q FROM %T mock %Q %Q %Q %Q %Q %Q', + $this->buildSelectClause($conn_r), $table->getTableName(), + $this->buildJoinClause($conn_r), $this->buildWhereClause($conn_r), + $this->buildGroupClause($conn_r), $this->buildOrderClause($conn_r), + $this->buildHavingClause($conn_r), $this->buildLimitClause($conn_r)); $mocks = $table->loadAllFromArray($data); @@ -85,33 +89,33 @@ final class PholioMockQuery protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array(); - $where[] = $this->buildPagingClause($conn_r); + $where[] = $this->buildWhereClauseParts($conn_r); - if ($this->ids) { + if ($this->ids !== null) { $where[] = qsprintf( $conn_r, - 'id IN (%Ld)', + 'mock.id IN (%Ld)', $this->ids); } - if ($this->phids) { + if ($this->phids !== null) { $where[] = qsprintf( $conn_r, - 'phid IN (%Ls)', + 'mock.phid IN (%Ls)', $this->phids); } - if ($this->authorPHIDs) { + if ($this->authorPHIDs !== null) { $where[] = qsprintf( $conn_r, - 'authorPHID in (%Ls)', + 'mock.authorPHID in (%Ls)', $this->authorPHIDs); } - if ($this->statuses) { + if ($this->statuses !== null) { $where[] = qsprintf( $conn_r, - 'status IN (%Ls)', + 'mock.status IN (%Ls)', $this->statuses); } @@ -178,4 +182,8 @@ final class PholioMockQuery return 'PhabricatorPholioApplication'; } + public function getPrimaryTableAlias() { + return 'mock'; + } + } diff --git a/src/applications/pholio/query/PholioMockSearchEngine.php b/src/applications/pholio/query/PholioMockSearchEngine.php index 91bc61f323..c04ece1da0 100644 --- a/src/applications/pholio/query/PholioMockSearchEngine.php +++ b/src/applications/pholio/query/PholioMockSearchEngine.php @@ -12,9 +12,15 @@ final class PholioMockSearchEngine extends PhabricatorApplicationSearchEngine { public function buildSavedQueryFromRequest(AphrontRequest $request) { $saved = new PhabricatorSavedQuery(); + $saved->setParameter( 'authorPHIDs', $this->readUsersFromRequest($request, 'authors')); + + $saved->setParameter( + 'projects', + $this->readProjectsFromRequest($request, 'projects')); + $saved->setParameter( 'statuses', $request->getStrList('status')); @@ -26,9 +32,23 @@ final class PholioMockSearchEngine extends PhabricatorApplicationSearchEngine { $query = id(new PholioMockQuery()) ->needCoverFiles(true) ->needImages(true) - ->needTokenCounts(true) - ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())) - ->withStatuses($saved->getParameter('statuses', array())); + ->needTokenCounts(true); + + $datasource = id(new PhabricatorTypeaheadUserParameterizedDatasource()) + ->setViewer($this->requireViewer()); + + $author_phids = $saved->getParameter('authorPHIDs', array()); + $author_phids = $datasource->evaluateTokens($author_phids); + if ($author_phids) { + $query->withAuthorPHIDs($author_phids); + } + + $statuses = $saved->getParameter('statuses', array()); + if ($statuses) { + $query->withStatuses($statuses); + } + + $this->setQueryProjects($query, $saved); return $query; } @@ -38,6 +58,7 @@ final class PholioMockSearchEngine extends PhabricatorApplicationSearchEngine { PhabricatorSavedQuery $saved_query) { $author_phids = $saved_query->getParameter('authorPHIDs', array()); + $projects = $saved_query->getParameter('projects', array()); $statuses = array( '' => pht('Any Status'), @@ -51,10 +72,16 @@ final class PholioMockSearchEngine extends PhabricatorApplicationSearchEngine { $form ->appendControl( id(new AphrontFormTokenizerControl()) - ->setDatasource(new PhabricatorPeopleDatasource()) + ->setDatasource(new PhabricatorTypeaheadUserParameterizedDatasource()) ->setName('authors') ->setLabel(pht('Authors')) ->setValue($author_phids)) + ->appendControl( + id(new AphrontFormTokenizerControl()) + ->setDatasource(new PhabricatorProjectLogicalDatasource()) + ->setName('projects') + ->setLabel(pht('Projects')) + ->setValue($projects)) ->appendChild( id(new AphrontFormSelectControl()) ->setLabel(pht('Status'))