@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 Slowvote Search

Summary: Updates slowvote search forms and results. Note I can't seem to get the Joins clause to fire anymore, is there a modern equiv?

Test Plan: Search on polls by state, votes, author, projects.

Reviewers: btrahan, epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D13666

+57 -81
+20 -31
src/applications/slowvote/query/PhabricatorSlowvoteQuery.php
··· 53 53 return $this; 54 54 } 55 55 56 - protected function loadPage() { 57 - $table = new PhabricatorSlowvotePoll(); 58 - $conn_r = $table->establishConnection('r'); 59 - 60 - $data = queryfx_all( 61 - $conn_r, 62 - 'SELECT p.* FROM %T p %Q %Q %Q %Q', 63 - $table->getTableName(), 64 - $this->buildJoinsClause($conn_r), 65 - $this->buildWhereClause($conn_r), 66 - $this->buildOrderClause($conn_r), 67 - $this->buildLimitClause($conn_r)); 56 + public function newResultObject() { 57 + return new PhabricatorSlowvotePoll(); 58 + } 68 59 69 - return $table->loadAllFromArray($data); 60 + protected function loadPage() { 61 + return $this->loadStandardPage($this->newResultObject()); 70 62 } 71 63 72 64 protected function willFilterPage(array $polls) { ··· 125 117 return $polls; 126 118 } 127 119 128 - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { 129 - $where = array(); 120 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 121 + $where = parent::buildWhereClauseParts($conn); 130 122 131 - if ($this->ids) { 123 + if ($this->ids !== null) { 132 124 $where[] = qsprintf( 133 - $conn_r, 125 + $conn, 134 126 'p.id IN (%Ld)', 135 127 $this->ids); 136 128 } 137 129 138 - if ($this->phids) { 130 + if ($this->phids !== null) { 139 131 $where[] = qsprintf( 140 - $conn_r, 132 + $conn, 141 133 'p.phid IN (%Ls)', 142 134 $this->phids); 143 135 } 144 136 145 - if ($this->authorPHIDs) { 137 + if ($this->authorPHIDs !== null) { 146 138 $where[] = qsprintf( 147 - $conn_r, 139 + $conn, 148 140 'p.authorPHID IN (%Ls)', 149 141 $this->authorPHIDs); 150 142 } 151 143 152 144 if ($this->isClosed !== null) { 153 145 $where[] = qsprintf( 154 - $conn_r, 146 + $conn, 155 147 'p.isClosed = %d', 156 148 (int)$this->isClosed); 157 149 } 158 - 159 - $where[] = $this->buildPagingClause($conn_r); 160 - return $this->formatWhereClause($where); 150 + return $where; 161 151 } 162 152 163 - private function buildJoinsClause(AphrontDatabaseConnection $conn_r) { 164 - $joins = array(); 153 + protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 154 + $joins = parent::buildJoinClauseParts($conn); 165 155 166 - if ($this->withVotesByViewer) { 156 + if ($this->withVotesByViewer !== null) { 167 157 $joins[] = qsprintf( 168 - $conn_r, 158 + $conn, 169 159 'JOIN %T vv ON vv.pollID = p.id AND vv.authorPHID = %s', 170 160 id(new PhabricatorSlowvoteChoice())->getTableName(), 171 161 $this->getViewer()->getPHID()); 172 162 } 173 - 174 - return implode(' ', $joins); 163 + return $joins; 175 164 } 176 165 177 166 protected function getPrimaryTableAlias() {
+37 -50
src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php
··· 11 11 return 'PhabricatorSlowvoteApplication'; 12 12 } 13 13 14 - public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 - $saved = new PhabricatorSavedQuery(); 16 - $saved->setParameter( 17 - 'authorPHIDs', 18 - $this->readUsersFromRequest($request, 'authors')); 19 - 20 - $saved->setParameter('voted', $request->getBool('voted')); 21 - $saved->setParameter('statuses', $request->getArr('statuses')); 22 - 23 - return $saved; 14 + public function newQuery() { 15 + return new PhabricatorSlowvoteQuery(); 24 16 } 25 17 26 - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 27 - $query = id(new PhabricatorSlowvoteQuery()) 28 - ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())); 18 + protected function buildQueryFromParameters(array $map) { 19 + $query = $this->newQuery(); 29 20 30 - if ($saved->getParameter('voted')) { 21 + if ($map['voted']) { 31 22 $query->withVotesByViewer(true); 32 23 } 33 24 34 - $statuses = $saved->getParameter('statuses', array()); 25 + if ($map['authorPHIDs']) { 26 + $query->withAuthorPHIDs($map['authorPHIDs']); 27 + } 28 + 29 + $statuses = $map['statuses']; 35 30 if (count($statuses) == 1) { 36 31 $status = head($statuses); 37 32 if ($status == 'open') { ··· 44 39 return $query; 45 40 } 46 41 47 - public function buildSearchForm( 48 - AphrontFormView $form, 49 - PhabricatorSavedQuery $saved_query) { 50 - $author_phids = $saved_query->getParameter('authorPHIDs', array()); 42 + protected function buildCustomSearchFields() { 51 43 52 - $voted = $saved_query->getParameter('voted', false); 53 - $statuses = $saved_query->getParameter('statuses', array()); 44 + return array( 45 + id(new PhabricatorUsersSearchField()) 46 + ->setKey('authorPHIDs') 47 + ->setAliases(array('authors')) 48 + ->setLabel(pht('Authors')), 54 49 55 - $form 56 - ->appendControl( 57 - id(new AphrontFormTokenizerControl()) 58 - ->setDatasource(new PhabricatorPeopleDatasource()) 59 - ->setName('authors') 60 - ->setLabel(pht('Authors')) 61 - ->setValue($author_phids)) 62 - ->appendChild( 63 - id(new AphrontFormCheckboxControl()) 64 - ->addCheckbox( 65 - 'voted', 66 - 1, 67 - pht("Show only polls I've voted in."), 68 - $voted)) 69 - ->appendChild( 70 - id(new AphrontFormCheckboxControl()) 71 - ->setLabel(pht('Status')) 72 - ->addCheckbox( 73 - 'statuses[]', 74 - 'open', 75 - pht('Open'), 76 - in_array('open', $statuses)) 77 - ->addCheckbox( 78 - 'statuses[]', 79 - 'closed', 80 - pht('Closed'), 81 - in_array('closed', $statuses))); 50 + id(new PhabricatorSearchCheckboxesField()) 51 + ->setKey('voted') 52 + ->setOptions(array( 53 + 'voted' => pht("Show only polls I've voted in."), 54 + )), 55 + 56 + id(new PhabricatorSearchCheckboxesField()) 57 + ->setKey('statuses') 58 + ->setOptions(array( 59 + 'open' => pht('Open'), 60 + 'closed' => pht('Closed'), 61 + )), 62 + ); 82 63 } 83 64 84 65 protected function getURI($path) { ··· 113 94 'authorPHIDs', 114 95 array($this->requireViewer()->getPHID())); 115 96 case 'voted': 116 - return $query->setParameter('voted', true); 97 + return $query->setParameter('voted', array('voted')); 117 98 } 118 99 119 100 return parent::buildSavedQueryFromBuiltin($query_key); ··· 152 133 ->setObjectName('V'.$poll->getID()) 153 134 ->setHeader($poll->getQuestion()) 154 135 ->setHref('/V'.$poll->getID()) 155 - ->setDisabled($poll->getIsClosed()) 156 136 ->addIcon('none', $date_created); 137 + 138 + if ($poll->getIsClosed()) { 139 + $item->setStatusIcon('fa-ban grey'); 140 + $item->setDisabled(true); 141 + } else { 142 + $item->setStatusIcon('fa-bar-chart'); 143 + } 157 144 158 145 $description = $poll->getDescription(); 159 146 if (strlen($description)) {