@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+58 -100
+13 -22
src/applications/ponder/query/PonderAnswerQuery.php
··· 36 36 return $this; 37 37 } 38 38 39 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 40 - $where = array(); 39 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 40 + $where = parent::buildWhereClauseParts($conn); 41 41 42 - if ($this->ids) { 42 + if ($this->ids !== null) { 43 43 $where[] = qsprintf( 44 - $conn_r, 44 + $conn, 45 45 'id IN (%Ld)', 46 46 $this->ids); 47 47 } 48 48 49 - if ($this->phids) { 49 + if ($this->phids !== null) { 50 50 $where[] = qsprintf( 51 - $conn_r, 51 + $conn, 52 52 'phid IN (%Ls)', 53 53 $this->phids); 54 54 } 55 55 56 - if ($this->authorPHIDs) { 56 + if ($this->authorPHIDs !== null) { 57 57 $where[] = qsprintf( 58 - $conn_r, 58 + $conn, 59 59 'authorPHID IN (%Ls)', 60 60 $this->authorPHIDs); 61 61 } 62 62 63 - $where[] = $this->buildPagingClause($conn_r); 63 + return $where; 64 + } 64 65 65 - return $this->formatWhereClause($where); 66 + public function newResultObject() { 67 + return new PonderAnswer(); 66 68 } 67 69 68 70 protected function loadPage() { 69 - $answer = new PonderAnswer(); 70 - $conn_r = $answer->establishConnection('r'); 71 - 72 - $data = queryfx_all( 73 - $conn_r, 74 - 'SELECT a.* FROM %T a %Q %Q %Q', 75 - $answer->getTableName(), 76 - $this->buildWhereClause($conn_r), 77 - $this->buildOrderClause($conn_r), 78 - $this->buildLimitClause($conn_r)); 79 - 80 - return $answer->loadAllFromArray($data); 71 + return $this->loadStandardPage(new PonderAnswer()); 81 72 } 82 73 83 74 protected function willFilterPage(array $answers) {
+21 -26
src/applications/ponder/query/PonderQuestionQuery.php
··· 9 9 private $answererPHIDs; 10 10 11 11 private $status = 'status-any'; 12 + 12 13 const STATUS_ANY = 'status-any'; 13 14 const STATUS_OPEN = 'status-open'; 14 15 const STATUS_CLOSED = 'status-closed'; ··· 51 52 return $this; 52 53 } 53 54 54 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 55 - $where = array(); 55 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 56 + $where = parent::buildWhereClauseParts($conn); 56 57 57 - if ($this->ids) { 58 + if ($this->ids !== null) { 58 59 $where[] = qsprintf( 59 - $conn_r, 60 + $conn, 60 61 'q.id IN (%Ld)', 61 62 $this->ids); 62 63 } 63 64 64 - if ($this->phids) { 65 + if ($this->phids !== null) { 65 66 $where[] = qsprintf( 66 - $conn_r, 67 + $conn, 67 68 'q.phid IN (%Ls)', 68 69 $this->phids); 69 70 } 70 71 71 - if ($this->authorPHIDs) { 72 + if ($this->authorPHIDs !== null) { 72 73 $where[] = qsprintf( 73 - $conn_r, 74 + $conn, 74 75 'q.authorPHID IN (%Ls)', 75 76 $this->authorPHIDs); 76 77 } 77 78 78 - if ($this->status) { 79 + if ($this->status !== null) { 79 80 switch ($this->status) { 80 81 case self::STATUS_ANY: 81 82 break; 82 83 case self::STATUS_OPEN: 83 84 $where[] = qsprintf( 84 - $conn_r, 85 + $conn, 85 86 'q.status = %d', 86 87 PonderQuestionStatus::STATUS_OPEN); 87 88 break; 88 89 case self::STATUS_CLOSED: 89 90 $where[] = qsprintf( 90 - $conn_r, 91 + $conn, 91 92 'q.status = %d', 92 93 PonderQuestionStatus::STATUS_CLOSED); 93 94 break; ··· 96 97 } 97 98 } 98 99 99 - $where[] = $this->buildPagingClause($conn_r); 100 + return $where; 101 + } 100 102 101 - return $this->formatWhereClause($where); 103 + public function newResultObject() { 104 + return new PonderQuestion(); 102 105 } 103 106 104 107 protected function loadPage() { 105 - $question = new PonderQuestion(); 106 - $conn_r = $question->establishConnection('r'); 107 - 108 - $data = queryfx_all( 109 - $conn_r, 110 - 'SELECT q.* FROM %T q %Q %Q %Q %Q', 111 - $question->getTableName(), 112 - $this->buildJoinsClause($conn_r), 113 - $this->buildWhereClause($conn_r), 114 - $this->buildOrderClause($conn_r), 115 - $this->buildLimitClause($conn_r)); 116 - 117 - return $question->loadAllFromArray($data); 108 + return $this->loadStandardPage(new PonderQuestion()); 118 109 } 119 110 120 111 protected function willFilterPage(array $questions) { ··· 173 164 } 174 165 175 166 return implode(' ', $joins); 167 + } 168 + 169 + protected function getPrimaryTableAlias() { 170 + return 'q'; 176 171 } 177 172 178 173 public function getQueryApplicationClass() {
+24 -52
src/applications/ponder/query/PonderQuestionSearchEngine.php
··· 11 11 return 'PhabricatorPonderApplication'; 12 12 } 13 13 14 - public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 - $saved = new PhabricatorSavedQuery(); 16 - 17 - $saved->setParameter( 18 - 'authorPHIDs', 19 - $this->readUsersFromRequest($request, 'authors')); 20 - 21 - $saved->setParameter( 22 - 'answererPHIDs', 23 - $this->readUsersFromRequest($request, 'answerers')); 24 - 25 - $saved->setParameter('status', $request->getStr('status')); 26 - 27 - return $saved; 14 + public function newQuery() { 15 + return new PonderQuestionQuery(); 28 16 } 29 17 30 - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 31 - $query = id(new PonderQuestionQuery()); 18 + protected function buildQueryFromParameters(array $map) { 19 + $query = $this->newQuery(); 32 20 33 - $author_phids = $saved->getParameter('authorPHIDs'); 34 - if ($author_phids) { 35 - $query->withAuthorPHIDs($author_phids); 21 + if ($map['authorPHIDs']) { 22 + $query->withAuthorPHIDs($map['authorPHIDs']); 36 23 } 37 24 38 - $answerer_phids = $saved->getParameter('answererPHIDs'); 39 - if ($answerer_phids) { 40 - $query->withAnswererPHIDs($answerer_phids); 25 + if ($map['answerers']) { 26 + $query->withAnswererPHIDs($map['answerers']); 41 27 } 42 28 43 - $status = $saved->getParameter('status'); 29 + $status = $map['status']; 44 30 if ($status != null) { 45 31 switch ($status) { 46 32 case 0: ··· 55 41 return $query; 56 42 } 57 43 58 - public function buildSearchForm( 59 - AphrontFormView $form, 60 - PhabricatorSavedQuery $saved_query) { 61 - 62 - $author_phids = $saved_query->getParameter('authorPHIDs', array()); 63 - $answerer_phids = $saved_query->getParameter('answererPHIDs', array()); 64 - $status = $saved_query->getParameter( 65 - 'status', PonderQuestionStatus::STATUS_OPEN); 66 - 67 - $form 68 - ->appendControl( 69 - id(new AphrontFormTokenizerControl()) 70 - ->setDatasource(new PhabricatorPeopleDatasource()) 71 - ->setName('authors') 72 - ->setLabel(pht('Authors')) 73 - ->setValue($author_phids)) 74 - ->appendControl( 75 - id(new AphrontFormTokenizerControl()) 76 - ->setDatasource(new PhabricatorPeopleDatasource()) 77 - ->setName('answerers') 78 - ->setLabel(pht('Answered By')) 79 - ->setValue($answerer_phids)) 80 - ->appendChild( 81 - id(new AphrontFormSelectControl()) 82 - ->setLabel(pht('Status')) 83 - ->setName('status') 84 - ->setValue($status) 85 - ->setOptions(PonderQuestionStatus::getQuestionStatusMap())); 44 + protected function buildCustomSearchFields() { 45 + return array( 46 + id(new PhabricatorUsersSearchField()) 47 + ->setKey('authorPHIDs') 48 + ->setAliases(array('authors')) 49 + ->setLabel(pht('Authors')), 50 + id(new PhabricatorUsersSearchField()) 51 + ->setKey('answerers') 52 + ->setAliases(array('answerers')) 53 + ->setLabel(pht('Answered By')), 54 + id(new PhabricatorSearchSelectField()) 55 + ->setLabel(pht('Status')) 56 + ->setKey('status') 57 + ->setOptions(PonderQuestionStatus::getQuestionStatusMap()), 58 + ); 86 59 } 87 60 88 61 protected function getURI($path) { ··· 104 77 } 105 78 106 79 public function buildSavedQueryFromBuiltin($query_key) { 107 - 108 80 $query = $this->newSavedQuery(); 109 81 $query->setQueryKey($query_key); 110 82