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 withIsClosed($with_closed) {
37 $this->isClosed
= $with_closed;
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 loadPage() {
61 return $this->loadStandardPage($this->newResultObject());
64 protected function willFilterPage(array $polls) {
65 assert_instances_of($polls, 'PhabricatorSlowvotePoll');
67 $ids = mpull($polls, 'getID');
68 $viewer = $this->getViewer();
70 if ($this->needOptions
) {
71 $options = id(new PhabricatorSlowvoteOption())->loadAllWhere(
75 $options = mgroup($options, 'getPollID');
76 foreach ($polls as $poll) {
77 $poll->attachOptions(idx($options, $poll->getID(), array()));
81 if ($this->needChoices
) {
82 $choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
86 $choices = mgroup($choices, 'getPollID');
87 foreach ($polls as $poll) {
88 $poll->attachChoices(idx($choices, $poll->getID(), array()));
91 // If we need the viewer's choices, we can just fill them from the data
93 if ($this->needViewerChoices
) {
94 foreach ($polls as $poll) {
95 $poll->attachViewerChoices(
98 mgroup($poll->getChoices(), 'getAuthorPHID'),
103 } else if ($this->needViewerChoices
) {
104 $choices = id(new PhabricatorSlowvoteChoice())->loadAllWhere(
105 'pollID IN (%Ld) AND authorPHID = %s',
109 $choices = mgroup($choices, 'getPollID');
110 foreach ($polls as $poll) {
111 $poll->attachViewerChoices(
113 idx($choices, $poll->getID(), array()));
120 protected function buildWhereClauseParts(AphrontDatabaseConnection
$conn) {
121 $where = parent
::buildWhereClauseParts($conn);
123 if ($this->ids
!== null) {
130 if ($this->phids
!== null) {
137 if ($this->authorPHIDs
!== null) {
140 'p.authorPHID IN (%Ls)',
144 if ($this->isClosed
!== null) {
148 (int)$this->isClosed
);
153 protected function buildJoinClauseParts(AphrontDatabaseConnection
$conn) {
154 $joins = parent
::buildJoinClauseParts($conn);
156 if ($this->withVotesByViewer
!== null) {
159 'JOIN %T vv ON vv.pollID = p.id AND vv.authorPHID = %s',
160 id(new PhabricatorSlowvoteChoice())->getTableName(),
161 $this->getViewer()->getPHID());
166 protected function getPrimaryTableAlias() {
170 public function getQueryApplicationClass() {
171 return 'PhabricatorSlowvoteApplication';