Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/slowvote/query/PhabricatorSlowvoteQuery.php b/src/applications/slowvote/query/PhabricatorSlowvoteQuery.php
index b7449d06a9..0b7335326c 100644
--- a/src/applications/slowvote/query/PhabricatorSlowvoteQuery.php
+++ b/src/applications/slowvote/query/PhabricatorSlowvoteQuery.php
@@ -1,185 +1,174 @@
<?php
final class PhabricatorSlowvoteQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
private $authorPHIDs;
private $withVotesByViewer;
private $isClosed;
private $needOptions;
private $needChoices;
private $needViewerChoices;
public function withIDs($ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs($phids) {
$this->phids = $phids;
return $this;
}
public function withAuthorPHIDs($author_phids) {
$this->authorPHIDs = $author_phids;
return $this;
}
public function withVotesByViewer($with_vote) {
$this->withVotesByViewer = $with_vote;
return $this;
}
public function withIsClosed($with_closed) {
$this->isClosed = $with_closed;
return $this;
}
public function needOptions($need_options) {
$this->needOptions = $need_options;
return $this;
}
public function needChoices($need_choices) {
$this->needChoices = $need_choices;
return $this;
}
public function needViewerChoices($need_viewer_choices) {
$this->needViewerChoices = $need_viewer_choices;
return $this;
}
+ public function newResultObject() {
+ return new PhabricatorSlowvotePoll();
+ }
+
protected function loadPage() {
- $table = new PhabricatorSlowvotePoll();
- $conn_r = $table->establishConnection('r');
-
- $data = queryfx_all(
- $conn_r,
- 'SELECT p.* FROM %T p %Q %Q %Q %Q',
- $table->getTableName(),
- $this->buildJoinsClause($conn_r),
- $this->buildWhereClause($conn_r),
- $this->buildOrderClause($conn_r),
- $this->buildLimitClause($conn_r));
-
- return $table->loadAllFromArray($data);
+ return $this->loadStandardPage($this->newResultObject());
}
protected function willFilterPage(array $polls) {
assert_instances_of($polls, 'PhabricatorSlowvotePoll');
$ids = mpull($polls, 'getID');
$viewer = $this->getViewer();
if ($this->needOptions) {
$options = id(new PhabricatorSlowvoteOption())->loadAllWhere(
'pollID IN (%Ld)',
$ids);
$options = mgroup($options, 'getPollID');
foreach ($polls as $poll) {
$poll->attachOptions(idx($options, $poll->getID(), array()));
}
}
if ($this->needChoices) {
$choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
'pollID IN (%Ld)',
$ids);
$choices = mgroup($choices, 'getPollID');
foreach ($polls as $poll) {
$poll->attachChoices(idx($choices, $poll->getID(), array()));
}
// If we need the viewer's choices, we can just fill them from the data
// we already loaded.
if ($this->needViewerChoices) {
foreach ($polls as $poll) {
$poll->attachViewerChoices(
$viewer,
idx(
mgroup($poll->getChoices(), 'getAuthorPHID'),
$viewer->getPHID(),
array()));
}
}
} else if ($this->needViewerChoices) {
$choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
'pollID IN (%Ld) AND authorPHID = %s',
$ids,
$viewer->getPHID());
$choices = mgroup($choices, 'getPollID');
foreach ($polls as $poll) {
$poll->attachViewerChoices(
$viewer,
idx($choices, $poll->getID(), array()));
}
}
return $polls;
}
- 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,
'p.id IN (%Ld)',
$this->ids);
}
- if ($this->phids) {
+ if ($this->phids !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'p.phid IN (%Ls)',
$this->phids);
}
- if ($this->authorPHIDs) {
+ if ($this->authorPHIDs !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'p.authorPHID IN (%Ls)',
$this->authorPHIDs);
}
if ($this->isClosed !== null) {
$where[] = qsprintf(
- $conn_r,
+ $conn,
'p.isClosed = %d',
(int)$this->isClosed);
}
-
- $where[] = $this->buildPagingClause($conn_r);
- return $this->formatWhereClause($where);
+ return $where;
}
- private function buildJoinsClause(AphrontDatabaseConnection $conn_r) {
- $joins = array();
+ protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
+ $joins = parent::buildJoinClauseParts($conn);
- if ($this->withVotesByViewer) {
+ if ($this->withVotesByViewer !== null) {
$joins[] = qsprintf(
- $conn_r,
+ $conn,
'JOIN %T vv ON vv.pollID = p.id AND vv.authorPHID = %s',
id(new PhabricatorSlowvoteChoice())->getTableName(),
$this->getViewer()->getPHID());
}
-
- return implode(' ', $joins);
+ return $joins;
}
protected function getPrimaryTableAlias() {
return 'p';
}
public function getQueryApplicationClass() {
return 'PhabricatorSlowvoteApplication';
}
}
diff --git a/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php b/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php
index dc4bff410d..6605bc9ecc 100644
--- a/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php
+++ b/src/applications/slowvote/query/PhabricatorSlowvoteSearchEngine.php
@@ -1,179 +1,166 @@
<?php
final class PhabricatorSlowvoteSearchEngine
extends PhabricatorApplicationSearchEngine {
public function getResultTypeDescription() {
return pht('Slowvotes');
}
public function getApplicationClassName() {
return 'PhabricatorSlowvoteApplication';
}
- public function buildSavedQueryFromRequest(AphrontRequest $request) {
- $saved = new PhabricatorSavedQuery();
- $saved->setParameter(
- 'authorPHIDs',
- $this->readUsersFromRequest($request, 'authors'));
-
- $saved->setParameter('voted', $request->getBool('voted'));
- $saved->setParameter('statuses', $request->getArr('statuses'));
-
- return $saved;
+ public function newQuery() {
+ return new PhabricatorSlowvoteQuery();
}
- public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
- $query = id(new PhabricatorSlowvoteQuery())
- ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
+ protected function buildQueryFromParameters(array $map) {
+ $query = $this->newQuery();
- if ($saved->getParameter('voted')) {
+ if ($map['voted']) {
$query->withVotesByViewer(true);
}
- $statuses = $saved->getParameter('statuses', array());
+ if ($map['authorPHIDs']) {
+ $query->withAuthorPHIDs($map['authorPHIDs']);
+ }
+
+ $statuses = $map['statuses'];
if (count($statuses) == 1) {
$status = head($statuses);
if ($status == 'open') {
$query->withIsClosed(false);
} else {
$query->withIsClosed(true);
}
}
return $query;
}
- public function buildSearchForm(
- AphrontFormView $form,
- PhabricatorSavedQuery $saved_query) {
- $author_phids = $saved_query->getParameter('authorPHIDs', array());
-
- $voted = $saved_query->getParameter('voted', false);
- $statuses = $saved_query->getParameter('statuses', array());
-
- $form
- ->appendControl(
- id(new AphrontFormTokenizerControl())
- ->setDatasource(new PhabricatorPeopleDatasource())
- ->setName('authors')
- ->setLabel(pht('Authors'))
- ->setValue($author_phids))
- ->appendChild(
- id(new AphrontFormCheckboxControl())
- ->addCheckbox(
- 'voted',
- 1,
- pht("Show only polls I've voted in."),
- $voted))
- ->appendChild(
- id(new AphrontFormCheckboxControl())
- ->setLabel(pht('Status'))
- ->addCheckbox(
- 'statuses[]',
- 'open',
- pht('Open'),
- in_array('open', $statuses))
- ->addCheckbox(
- 'statuses[]',
- 'closed',
- pht('Closed'),
- in_array('closed', $statuses)));
+ protected function buildCustomSearchFields() {
+
+ return array(
+ id(new PhabricatorUsersSearchField())
+ ->setKey('authorPHIDs')
+ ->setAliases(array('authors'))
+ ->setLabel(pht('Authors')),
+
+ id(new PhabricatorSearchCheckboxesField())
+ ->setKey('voted')
+ ->setOptions(array(
+ 'voted' => pht("Show only polls I've voted in."),
+ )),
+
+ id(new PhabricatorSearchCheckboxesField())
+ ->setKey('statuses')
+ ->setOptions(array(
+ 'open' => pht('Open'),
+ 'closed' => pht('Closed'),
+ )),
+ );
}
protected function getURI($path) {
return '/vote/'.$path;
}
protected function getBuiltinQueryNames() {
$names = array(
'open' => pht('Open Polls'),
'all' => pht('All Polls'),
);
if ($this->requireViewer()->isLoggedIn()) {
$names['authored'] = pht('Authored');
$names['voted'] = pht('Voted In');
}
return $names;
}
public function buildSavedQueryFromBuiltin($query_key) {
$query = $this->newSavedQuery();
$query->setQueryKey($query_key);
switch ($query_key) {
case 'open':
return $query->setParameter('statuses', array('open'));
case 'all':
return $query;
case 'authored':
return $query->setParameter(
'authorPHIDs',
array($this->requireViewer()->getPHID()));
case 'voted':
- return $query->setParameter('voted', true);
+ return $query->setParameter('voted', array('voted'));
}
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function getRequiredHandlePHIDsForResultList(
array $polls,
PhabricatorSavedQuery $query) {
return mpull($polls, 'getAuthorPHID');
}
protected function renderResultList(
array $polls,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($polls, 'PhabricatorSlowvotePoll');
$viewer = $this->requireViewer();
$list = id(new PHUIObjectItemListView())
->setUser($viewer);
$phids = mpull($polls, 'getAuthorPHID');
foreach ($polls as $poll) {
$date_created = phabricator_datetime($poll->getDateCreated(), $viewer);
if ($poll->getAuthorPHID()) {
$author = $handles[$poll->getAuthorPHID()]->renderLink();
} else {
$author = null;
}
$item = id(new PHUIObjectItemView())
->setUser($viewer)
->setObject($poll)
->setObjectName('V'.$poll->getID())
->setHeader($poll->getQuestion())
->setHref('/V'.$poll->getID())
- ->setDisabled($poll->getIsClosed())
->addIcon('none', $date_created);
+ if ($poll->getIsClosed()) {
+ $item->setStatusIcon('fa-ban grey');
+ $item->setDisabled(true);
+ } else {
+ $item->setStatusIcon('fa-bar-chart');
+ }
+
$description = $poll->getDescription();
if (strlen($description)) {
$item->addAttribute(id(new PhutilUTF8StringTruncator())
->setMaximumGlyphs(120)
->truncateString($poll->getDescription()));
}
if ($author) {
$item->addByline(pht('Author: %s', $author));
}
$list->addItem($item);
}
$result = new PhabricatorApplicationSearchResultView();
$result->setObjectList($list);
$result->setNoDataString(pht('No polls found.'));
return $result;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Mon, Jul 28, 8:59 AM (1 w, 21 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
186618
Default Alt Text
(12 KB)

Event Timeline