1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-20 20:40:56 +01:00

Modernize Ponder Search

Summary: Use new search hotness.

Test Plan: Tested searching open, closed, answered, by project, etc.

Reviewers: btrahan, epriestley

Reviewed By: epriestley

Subscribers: r.ksiazek87, epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D13667
This commit is contained in:
Chad Little 2015-07-22 07:14:49 -07:00
parent 690463b037
commit a9e8e03524
3 changed files with 58 additions and 100 deletions

View file

@ -36,48 +36,39 @@ final class PonderAnswerQuery
return $this; return $this;
} }
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = array(); $where = parent::buildWhereClauseParts($conn);
if ($this->ids) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'id IN (%Ld)', 'id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'phid IN (%Ls)', 'phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->authorPHIDs) { if ($this->authorPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'authorPHID IN (%Ls)', 'authorPHID IN (%Ls)',
$this->authorPHIDs); $this->authorPHIDs);
} }
$where[] = $this->buildPagingClause($conn_r); return $where;
}
return $this->formatWhereClause($where); public function newResultObject() {
return new PonderAnswer();
} }
protected function loadPage() { protected function loadPage() {
$answer = new PonderAnswer(); return $this->loadStandardPage(new PonderAnswer());
$conn_r = $answer->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT a.* FROM %T a %Q %Q %Q',
$answer->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $answer->loadAllFromArray($data);
} }
protected function willFilterPage(array $answers) { protected function willFilterPage(array $answers) {

View file

@ -9,6 +9,7 @@ final class PonderQuestionQuery
private $answererPHIDs; private $answererPHIDs;
private $status = 'status-any'; private $status = 'status-any';
const STATUS_ANY = 'status-any'; const STATUS_ANY = 'status-any';
const STATUS_OPEN = 'status-open'; const STATUS_OPEN = 'status-open';
const STATUS_CLOSED = 'status-closed'; const STATUS_CLOSED = 'status-closed';
@ -51,43 +52,43 @@ final class PonderQuestionQuery
return $this; return $this;
} }
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = array(); $where = parent::buildWhereClauseParts($conn);
if ($this->ids) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'q.id IN (%Ld)', 'q.id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'q.phid IN (%Ls)', 'q.phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->authorPHIDs) { if ($this->authorPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'q.authorPHID IN (%Ls)', 'q.authorPHID IN (%Ls)',
$this->authorPHIDs); $this->authorPHIDs);
} }
if ($this->status) { if ($this->status !== null) {
switch ($this->status) { switch ($this->status) {
case self::STATUS_ANY: case self::STATUS_ANY:
break; break;
case self::STATUS_OPEN: case self::STATUS_OPEN:
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'q.status = %d', 'q.status = %d',
PonderQuestionStatus::STATUS_OPEN); PonderQuestionStatus::STATUS_OPEN);
break; break;
case self::STATUS_CLOSED: case self::STATUS_CLOSED:
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn,
'q.status = %d', 'q.status = %d',
PonderQuestionStatus::STATUS_CLOSED); PonderQuestionStatus::STATUS_CLOSED);
break; break;
@ -96,25 +97,15 @@ final class PonderQuestionQuery
} }
} }
$where[] = $this->buildPagingClause($conn_r); return $where;
}
return $this->formatWhereClause($where); public function newResultObject() {
return new PonderQuestion();
} }
protected function loadPage() { protected function loadPage() {
$question = new PonderQuestion(); return $this->loadStandardPage(new PonderQuestion());
$conn_r = $question->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT q.* FROM %T q %Q %Q %Q %Q',
$question->getTableName(),
$this->buildJoinsClause($conn_r),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $question->loadAllFromArray($data);
} }
protected function willFilterPage(array $questions) { protected function willFilterPage(array $questions) {
@ -175,6 +166,10 @@ final class PonderQuestionQuery
return implode(' ', $joins); return implode(' ', $joins);
} }
protected function getPrimaryTableAlias() {
return 'q';
}
public function getQueryApplicationClass() { public function getQueryApplicationClass() {
return 'PhabricatorPonderApplication'; return 'PhabricatorPonderApplication';
} }

View file

@ -11,36 +11,22 @@ final class PonderQuestionSearchEngine
return 'PhabricatorPonderApplication'; return 'PhabricatorPonderApplication';
} }
public function buildSavedQueryFromRequest(AphrontRequest $request) { public function newQuery() {
$saved = new PhabricatorSavedQuery(); return new PonderQuestionQuery();
$saved->setParameter(
'authorPHIDs',
$this->readUsersFromRequest($request, 'authors'));
$saved->setParameter(
'answererPHIDs',
$this->readUsersFromRequest($request, 'answerers'));
$saved->setParameter('status', $request->getStr('status'));
return $saved;
} }
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { protected function buildQueryFromParameters(array $map) {
$query = id(new PonderQuestionQuery()); $query = $this->newQuery();
$author_phids = $saved->getParameter('authorPHIDs'); if ($map['authorPHIDs']) {
if ($author_phids) { $query->withAuthorPHIDs($map['authorPHIDs']);
$query->withAuthorPHIDs($author_phids);
} }
$answerer_phids = $saved->getParameter('answererPHIDs'); if ($map['answerers']) {
if ($answerer_phids) { $query->withAnswererPHIDs($map['answerers']);
$query->withAnswererPHIDs($answerer_phids);
} }
$status = $saved->getParameter('status'); $status = $map['status'];
if ($status != null) { if ($status != null) {
switch ($status) { switch ($status) {
case 0: case 0:
@ -55,34 +41,21 @@ final class PonderQuestionSearchEngine
return $query; return $query;
} }
public function buildSearchForm( protected function buildCustomSearchFields() {
AphrontFormView $form, return array(
PhabricatorSavedQuery $saved_query) { id(new PhabricatorUsersSearchField())
->setKey('authorPHIDs')
$author_phids = $saved_query->getParameter('authorPHIDs', array()); ->setAliases(array('authors'))
$answerer_phids = $saved_query->getParameter('answererPHIDs', array()); ->setLabel(pht('Authors')),
$status = $saved_query->getParameter( id(new PhabricatorUsersSearchField())
'status', PonderQuestionStatus::STATUS_OPEN); ->setKey('answerers')
->setAliases(array('answerers'))
$form ->setLabel(pht('Answered By')),
->appendControl( id(new PhabricatorSearchSelectField())
id(new AphrontFormTokenizerControl()) ->setLabel(pht('Status'))
->setDatasource(new PhabricatorPeopleDatasource()) ->setKey('status')
->setName('authors') ->setOptions(PonderQuestionStatus::getQuestionStatusMap()),
->setLabel(pht('Authors')) );
->setValue($author_phids))
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorPeopleDatasource())
->setName('answerers')
->setLabel(pht('Answered By'))
->setValue($answerer_phids))
->appendChild(
id(new AphrontFormSelectControl())
->setLabel(pht('Status'))
->setName('status')
->setValue($status)
->setOptions(PonderQuestionStatus::getQuestionStatusMap()));
} }
protected function getURI($path) { protected function getURI($path) {
@ -104,7 +77,6 @@ final class PonderQuestionSearchEngine
} }
public function buildSavedQueryFromBuiltin($query_key) { public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery(); $query = $this->newSavedQuery();
$query->setQueryKey($query_key); $query->setQueryKey($query_key);