mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 12:30: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:
parent
690463b037
commit
a9e8e03524
3 changed files with 58 additions and 100 deletions
|
@ -36,48 +36,39 @@ final class PonderAnswerQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||
$where = parent::buildWhereClauseParts($conn);
|
||||
|
||||
if ($this->ids) {
|
||||
if ($this->ids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids) {
|
||||
if ($this->phids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->authorPHIDs) {
|
||||
if ($this->authorPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'authorPHID IN (%Ls)',
|
||||
$this->authorPHIDs);
|
||||
}
|
||||
|
||||
$where[] = $this->buildPagingClause($conn_r);
|
||||
return $where;
|
||||
}
|
||||
|
||||
return $this->formatWhereClause($where);
|
||||
public function newResultObject() {
|
||||
return new PonderAnswer();
|
||||
}
|
||||
|
||||
protected function loadPage() {
|
||||
$answer = 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);
|
||||
return $this->loadStandardPage(new PonderAnswer());
|
||||
}
|
||||
|
||||
protected function willFilterPage(array $answers) {
|
||||
|
|
|
@ -9,6 +9,7 @@ final class PonderQuestionQuery
|
|||
private $answererPHIDs;
|
||||
|
||||
private $status = 'status-any';
|
||||
|
||||
const STATUS_ANY = 'status-any';
|
||||
const STATUS_OPEN = 'status-open';
|
||||
const STATUS_CLOSED = 'status-closed';
|
||||
|
@ -51,43 +52,43 @@ final class PonderQuestionQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
|
||||
$where = array();
|
||||
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
||||
$where = parent::buildWhereClauseParts($conn);
|
||||
|
||||
if ($this->ids) {
|
||||
if ($this->ids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'q.id IN (%Ld)',
|
||||
$this->ids);
|
||||
}
|
||||
|
||||
if ($this->phids) {
|
||||
if ($this->phids !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'q.phid IN (%Ls)',
|
||||
$this->phids);
|
||||
}
|
||||
|
||||
if ($this->authorPHIDs) {
|
||||
if ($this->authorPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'q.authorPHID IN (%Ls)',
|
||||
$this->authorPHIDs);
|
||||
}
|
||||
|
||||
if ($this->status) {
|
||||
if ($this->status !== null) {
|
||||
switch ($this->status) {
|
||||
case self::STATUS_ANY:
|
||||
break;
|
||||
case self::STATUS_OPEN:
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'q.status = %d',
|
||||
PonderQuestionStatus::STATUS_OPEN);
|
||||
break;
|
||||
case self::STATUS_CLOSED:
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
$conn,
|
||||
'q.status = %d',
|
||||
PonderQuestionStatus::STATUS_CLOSED);
|
||||
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() {
|
||||
$question = 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);
|
||||
return $this->loadStandardPage(new PonderQuestion());
|
||||
}
|
||||
|
||||
protected function willFilterPage(array $questions) {
|
||||
|
@ -175,6 +166,10 @@ final class PonderQuestionQuery
|
|||
return implode(' ', $joins);
|
||||
}
|
||||
|
||||
protected function getPrimaryTableAlias() {
|
||||
return 'q';
|
||||
}
|
||||
|
||||
public function getQueryApplicationClass() {
|
||||
return 'PhabricatorPonderApplication';
|
||||
}
|
||||
|
|
|
@ -11,36 +11,22 @@ final class PonderQuestionSearchEngine
|
|||
return 'PhabricatorPonderApplication';
|
||||
}
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$saved = new PhabricatorSavedQuery();
|
||||
|
||||
$saved->setParameter(
|
||||
'authorPHIDs',
|
||||
$this->readUsersFromRequest($request, 'authors'));
|
||||
|
||||
$saved->setParameter(
|
||||
'answererPHIDs',
|
||||
$this->readUsersFromRequest($request, 'answerers'));
|
||||
|
||||
$saved->setParameter('status', $request->getStr('status'));
|
||||
|
||||
return $saved;
|
||||
public function newQuery() {
|
||||
return new PonderQuestionQuery();
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new PonderQuestionQuery());
|
||||
protected function buildQueryFromParameters(array $map) {
|
||||
$query = $this->newQuery();
|
||||
|
||||
$author_phids = $saved->getParameter('authorPHIDs');
|
||||
if ($author_phids) {
|
||||
$query->withAuthorPHIDs($author_phids);
|
||||
if ($map['authorPHIDs']) {
|
||||
$query->withAuthorPHIDs($map['authorPHIDs']);
|
||||
}
|
||||
|
||||
$answerer_phids = $saved->getParameter('answererPHIDs');
|
||||
if ($answerer_phids) {
|
||||
$query->withAnswererPHIDs($answerer_phids);
|
||||
if ($map['answerers']) {
|
||||
$query->withAnswererPHIDs($map['answerers']);
|
||||
}
|
||||
|
||||
$status = $saved->getParameter('status');
|
||||
$status = $map['status'];
|
||||
if ($status != null) {
|
||||
switch ($status) {
|
||||
case 0:
|
||||
|
@ -55,34 +41,21 @@ final class PonderQuestionSearchEngine
|
|||
return $query;
|
||||
}
|
||||
|
||||
public function buildSearchForm(
|
||||
AphrontFormView $form,
|
||||
PhabricatorSavedQuery $saved_query) {
|
||||
|
||||
$author_phids = $saved_query->getParameter('authorPHIDs', array());
|
||||
$answerer_phids = $saved_query->getParameter('answererPHIDs', array());
|
||||
$status = $saved_query->getParameter(
|
||||
'status', PonderQuestionStatus::STATUS_OPEN);
|
||||
|
||||
$form
|
||||
->appendControl(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setDatasource(new PhabricatorPeopleDatasource())
|
||||
->setName('authors')
|
||||
->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 buildCustomSearchFields() {
|
||||
return array(
|
||||
id(new PhabricatorUsersSearchField())
|
||||
->setKey('authorPHIDs')
|
||||
->setAliases(array('authors'))
|
||||
->setLabel(pht('Authors')),
|
||||
id(new PhabricatorUsersSearchField())
|
||||
->setKey('answerers')
|
||||
->setAliases(array('answerers'))
|
||||
->setLabel(pht('Answered By')),
|
||||
id(new PhabricatorSearchSelectField())
|
||||
->setLabel(pht('Status'))
|
||||
->setKey('status')
|
||||
->setOptions(PonderQuestionStatus::getQuestionStatusMap()),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
|
@ -104,7 +77,6 @@ final class PonderQuestionSearchEngine
|
|||
}
|
||||
|
||||
public function buildSavedQueryFromBuiltin($query_key) {
|
||||
|
||||
$query = $this->newSavedQuery();
|
||||
$query->setQueryKey($query_key);
|
||||
|
||||
|
|
Loading…
Reference in a new issue