3 final class PhabricatorSlowvoteQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery
{
9 private $withVotesByViewer;
14 private $needViewerChoices;
16 public function withIDs($ids) {
21 public function withPHIDs($phids) {
22 $this->phids
= $phids;
26 public function withAuthorPHIDs($author_phids) {
27 $this->authorPHIDs
= $author_phids;
31 public function withVotesByViewer($with_vote) {
32 $this->withVotesByViewer
= $with_vote;
36 public function withStatuses(array $statuses) {
37 $this->statuses
= $statuses;
41 public function needOptions($need_options) {
42 $this->needOptions
= $need_options;
46 public function needChoices($need_choices) {
47 $this->needChoices
= $need_choices;
51 public function needViewerChoices($need_viewer_choices) {
52 $this->needViewerChoices
= $need_viewer_choices;
56 public function newResultObject() {
57 return new PhabricatorSlowvotePoll();
60 protected function willFilterPage(array $polls) {
61 assert_instances_of($polls, 'PhabricatorSlowvotePoll');
63 $ids = mpull($polls, 'getID');
64 $viewer = $this->getViewer();
66 if ($this->needOptions
) {
67 $options = id(new PhabricatorSlowvoteOption())->loadAllWhere(
71 $options = mgroup($options, 'getPollID');
72 foreach ($polls as $poll) {
73 $poll->attachOptions(idx($options, $poll->getID(), array()));
77 if ($this->needChoices
) {
78 $choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
82 $choices = mgroup($choices, 'getPollID');
83 foreach ($polls as $poll) {
84 $poll->attachChoices(idx($choices, $poll->getID(), array()));
87 // If we need the viewer's choices, we can just fill them from the data
89 if ($this->needViewerChoices
) {
90 foreach ($polls as $poll) {
91 $poll->attachViewerChoices(
94 mgroup($poll->getChoices(), 'getAuthorPHID'),
99 } else if ($this->needViewerChoices
) {
100 $choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
101 'pollID IN (%Ld) AND authorPHID = %s',
105 $choices = mgroup($choices, 'getPollID');
106 foreach ($polls as $poll) {
107 $poll->attachViewerChoices(
109 idx($choices, $poll->getID(), array()));
116 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
117 $where = parent
::buildWhereClauseParts($conn);
119 if ($this->ids
!== null) {
126 if ($this->phids
!== null) {
133 if ($this->authorPHIDs
!== null) {
136 'p.authorPHID IN (%Ls)',
140 if ($this->statuses
!== null) {
150 protected function buildJoinClauseParts(AphrontDatabaseConnection
$conn) {
151 $joins = parent
::buildJoinClauseParts($conn);
153 if ($this->withVotesByViewer
!== null) {
156 'JOIN %T vv ON vv.pollID = p.id AND vv.authorPHID = %s',
157 id(new PhabricatorSlowvoteChoice())->getTableName(),
158 $this->getViewer()->getPHID());
163 protected function getPrimaryTableAlias() {
167 public function getQueryApplicationClass() {
168 return 'PhabricatorSlowvoteApplication';