Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / fund / query / FundBackerQuery.php
blob2d6e13dfd9d346e538164b272c90d7c48312f469
1 <?php
3 final class FundBackerQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $statuses;
10 private $initiativePHIDs;
11 private $backerPHIDs;
13 public function withIDs(array $ids) {
14 $this->ids = $ids;
15 return $this;
18 public function withPHIDs(array $phids) {
19 $this->phids = $phids;
20 return $this;
23 public function withStatuses(array $statuses) {
24 $this->statuses = $statuses;
25 return $this;
28 public function withInitiativePHIDs(array $phids) {
29 $this->initiativePHIDs = $phids;
30 return $this;
33 public function withBackerPHIDs(array $phids) {
34 $this->backerPHIDs = $phids;
35 return $this;
38 protected function loadPage() {
39 $table = new FundBacker();
40 $conn_r = $table->establishConnection('r');
42 $rows = queryfx_all(
43 $conn_r,
44 'SELECT * FROM %T %Q %Q %Q',
45 $table->getTableName(),
46 $this->buildWhereClause($conn_r),
47 $this->buildOrderClause($conn_r),
48 $this->buildLimitClause($conn_r));
50 return $table->loadAllFromArray($rows);
53 protected function willFilterPage(array $backers) {
54 $initiative_phids = mpull($backers, 'getInitiativePHID');
55 $initiatives = id(new PhabricatorObjectQuery())
56 ->setParentQuery($this)
57 ->setViewer($this->getViewer())
58 ->withPHIDs($initiative_phids)
59 ->execute();
60 $initiatives = mpull($initiatives, null, 'getPHID');
62 foreach ($backers as $backer) {
63 $initiative_phid = $backer->getInitiativePHID();
64 $initiative = idx($initiatives, $initiative_phid);
65 $backer->attachInitiative($initiative);
68 return $backers;
71 protected function buildWhereClause(AphrontDatabaseConnection $conn) {
72 $where = array();
74 $where[] = $this->buildPagingClause($conn);
76 if ($this->ids !== null) {
77 $where[] = qsprintf(
78 $conn,
79 'id IN (%Ld)',
80 $this->ids);
83 if ($this->phids !== null) {
84 $where[] = qsprintf(
85 $conn,
86 'phid IN (%Ls)',
87 $this->phids);
90 if ($this->initiativePHIDs !== null) {
91 $where[] = qsprintf(
92 $conn,
93 'initiativePHID IN (%Ls)',
94 $this->initiativePHIDs);
97 if ($this->backerPHIDs !== null) {
98 $where[] = qsprintf(
99 $conn,
100 'backerPHID IN (%Ls)',
101 $this->backerPHIDs);
104 if ($this->statuses !== null) {
105 $where[] = qsprintf(
106 $conn,
107 'status IN (%Ls)',
108 $this->statuses);
111 return $this->formatWhereClause($conn, $where);
114 public function getQueryApplicationClass() {
115 return 'PhabricatorFundApplication';