Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/auth/query/PhabricatorAuthInviteQuery.php
12262 views
1
<?php
2
3
final class PhabricatorAuthInviteQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $emailAddresses;
9
private $verificationCodes;
10
private $authorPHIDs;
11
12
public function withIDs(array $ids) {
13
$this->ids = $ids;
14
return $this;
15
}
16
17
public function withPHIDs(array $phids) {
18
$this->phids = $phids;
19
return $this;
20
}
21
22
public function withEmailAddresses(array $addresses) {
23
$this->emailAddresses = $addresses;
24
return $this;
25
}
26
27
public function withVerificationCodes(array $codes) {
28
$this->verificationCodes = $codes;
29
return $this;
30
}
31
32
public function withAuthorPHIDs(array $phids) {
33
$this->authorPHIDs = $phids;
34
return $this;
35
}
36
37
protected function loadPage() {
38
$table = new PhabricatorAuthInvite();
39
$conn_r = $table->establishConnection('r');
40
41
$data = queryfx_all(
42
$conn_r,
43
'SELECT * FROM %T %Q %Q %Q',
44
$table->getTableName(),
45
$this->buildWhereClause($conn_r),
46
$this->buildOrderClause($conn_r),
47
$this->buildLimitClause($conn_r));
48
49
$invites = $table->loadAllFromArray($data);
50
51
// If the objects were loaded via verification code, set a flag to make
52
// sure the viewer can see them.
53
if ($this->verificationCodes !== null) {
54
foreach ($invites as $invite) {
55
$invite->setViewerHasVerificationCode(true);
56
}
57
}
58
59
return $invites;
60
}
61
62
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
63
$where = array();
64
65
if ($this->ids !== null) {
66
$where[] = qsprintf(
67
$conn,
68
'id IN (%Ld)',
69
$this->ids);
70
}
71
72
if ($this->phids !== null) {
73
$where[] = qsprintf(
74
$conn,
75
'phid IN (%Ls)',
76
$this->phids);
77
}
78
79
if ($this->emailAddresses !== null) {
80
$where[] = qsprintf(
81
$conn,
82
'emailAddress IN (%Ls)',
83
$this->emailAddresses);
84
}
85
86
if ($this->verificationCodes !== null) {
87
$hashes = array();
88
foreach ($this->verificationCodes as $code) {
89
$hashes[] = PhabricatorHash::digestForIndex($code);
90
}
91
92
$where[] = qsprintf(
93
$conn,
94
'verificationHash IN (%Ls)',
95
$hashes);
96
}
97
98
if ($this->authorPHIDs !== null) {
99
$where[] = qsprintf(
100
$conn,
101
'authorPHID IN (%Ls)',
102
$this->authorPHIDs);
103
}
104
105
$where[] = $this->buildPagingClause($conn);
106
107
return $this->formatWhereClause($conn, $where);
108
}
109
110
public function getQueryApplicationClass() {
111
// NOTE: This query is issued by logged-out users, who often will not be
112
// able to see applications. They still need to be able to see invites.
113
return null;
114
}
115
116
}
117
118