Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/fund/query/FundBackerQuery.php
12256 views
1
<?php
2
3
final class FundBackerQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $statuses;
9
10
private $initiativePHIDs;
11
private $backerPHIDs;
12
13
public function withIDs(array $ids) {
14
$this->ids = $ids;
15
return $this;
16
}
17
18
public function withPHIDs(array $phids) {
19
$this->phids = $phids;
20
return $this;
21
}
22
23
public function withStatuses(array $statuses) {
24
$this->statuses = $statuses;
25
return $this;
26
}
27
28
public function withInitiativePHIDs(array $phids) {
29
$this->initiativePHIDs = $phids;
30
return $this;
31
}
32
33
public function withBackerPHIDs(array $phids) {
34
$this->backerPHIDs = $phids;
35
return $this;
36
}
37
38
protected function loadPage() {
39
$table = new FundBacker();
40
$conn_r = $table->establishConnection('r');
41
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));
49
50
return $table->loadAllFromArray($rows);
51
}
52
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');
61
62
foreach ($backers as $backer) {
63
$initiative_phid = $backer->getInitiativePHID();
64
$initiative = idx($initiatives, $initiative_phid);
65
$backer->attachInitiative($initiative);
66
}
67
68
return $backers;
69
}
70
71
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
72
$where = array();
73
74
$where[] = $this->buildPagingClause($conn);
75
76
if ($this->ids !== null) {
77
$where[] = qsprintf(
78
$conn,
79
'id IN (%Ld)',
80
$this->ids);
81
}
82
83
if ($this->phids !== null) {
84
$where[] = qsprintf(
85
$conn,
86
'phid IN (%Ls)',
87
$this->phids);
88
}
89
90
if ($this->initiativePHIDs !== null) {
91
$where[] = qsprintf(
92
$conn,
93
'initiativePHID IN (%Ls)',
94
$this->initiativePHIDs);
95
}
96
97
if ($this->backerPHIDs !== null) {
98
$where[] = qsprintf(
99
$conn,
100
'backerPHID IN (%Ls)',
101
$this->backerPHIDs);
102
}
103
104
if ($this->statuses !== null) {
105
$where[] = qsprintf(
106
$conn,
107
'status IN (%Ls)',
108
$this->statuses);
109
}
110
111
return $this->formatWhereClause($conn, $where);
112
}
113
114
public function getQueryApplicationClass() {
115
return 'PhabricatorFundApplication';
116
}
117
118
}
119
120