Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/query/PhabricatorMetaMTAApplicationEmailQuery.php
12256 views
1
<?php
2
3
final class PhabricatorMetaMTAApplicationEmailQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $addresses;
9
private $addressPrefix;
10
private $applicationPHIDs;
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 withAddresses(array $addresses) {
23
$this->addresses = $addresses;
24
return $this;
25
}
26
27
public function withAddressPrefix($prefix) {
28
$this->addressPrefix = $prefix;
29
return $this;
30
}
31
32
public function withApplicationPHIDs(array $phids) {
33
$this->applicationPHIDs = $phids;
34
return $this;
35
}
36
37
protected function loadPage() {
38
return $this->loadStandardPage(new PhabricatorMetaMTAApplicationEmail());
39
}
40
41
protected function willFilterPage(array $app_emails) {
42
$app_emails_map = mgroup($app_emails, 'getApplicationPHID');
43
$applications = id(new PhabricatorApplicationQuery())
44
->setViewer($this->getViewer())
45
->withPHIDs(array_keys($app_emails_map))
46
->execute();
47
$applications = mpull($applications, null, 'getPHID');
48
49
foreach ($app_emails_map as $app_phid => $app_emails_group) {
50
foreach ($app_emails_group as $app_email) {
51
$application = idx($applications, $app_phid);
52
if (!$application) {
53
unset($app_emails[$app_phid]);
54
continue;
55
}
56
$app_email->attachApplication($application);
57
}
58
}
59
return $app_emails;
60
}
61
62
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
63
$where = parent::buildWhereClauseParts($conn);
64
65
if ($this->addresses !== null) {
66
$where[] = qsprintf(
67
$conn,
68
'appemail.address IN (%Ls)',
69
$this->addresses);
70
}
71
72
if ($this->addressPrefix !== null) {
73
$where[] = qsprintf(
74
$conn,
75
'appemail.address LIKE %>',
76
$this->addressPrefix);
77
}
78
79
if ($this->applicationPHIDs !== null) {
80
$where[] = qsprintf(
81
$conn,
82
'appemail.applicationPHID IN (%Ls)',
83
$this->applicationPHIDs);
84
}
85
86
if ($this->phids !== null) {
87
$where[] = qsprintf(
88
$conn,
89
'appemail.phid IN (%Ls)',
90
$this->phids);
91
}
92
93
if ($this->ids !== null) {
94
$where[] = qsprintf(
95
$conn,
96
'appemail.id IN (%Ld)',
97
$this->ids);
98
}
99
100
return $where;
101
}
102
103
protected function getPrimaryTableAlias() {
104
return 'appemail';
105
}
106
107
public function getQueryApplicationClass() {
108
return 'PhabricatorMetaMTAApplication';
109
}
110
111
}
112
113