Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php
12256 views
1
<?php
2
3
final class PhabricatorMetaMTAMailQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $ids;
7
private $phids;
8
private $actorPHIDs;
9
private $recipientPHIDs;
10
private $createdMin;
11
private $createdMax;
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 withActorPHIDs(array $phids) {
24
$this->actorPHIDs = $phids;
25
return $this;
26
}
27
28
public function withRecipientPHIDs(array $phids) {
29
$this->recipientPHIDs = $phids;
30
return $this;
31
}
32
33
public function withDateCreatedBetween($min, $max) {
34
$this->createdMin = $min;
35
$this->createdMax = $max;
36
return $this;
37
}
38
39
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
40
$where = parent::buildWhereClauseParts($conn);
41
42
if ($this->ids !== null) {
43
$where[] = qsprintf(
44
$conn,
45
'mail.id IN (%Ld)',
46
$this->ids);
47
}
48
49
if ($this->phids !== null) {
50
$where[] = qsprintf(
51
$conn,
52
'mail.phid IN (%Ls)',
53
$this->phids);
54
}
55
56
if ($this->actorPHIDs !== null) {
57
$where[] = qsprintf(
58
$conn,
59
'mail.actorPHID IN (%Ls)',
60
$this->actorPHIDs);
61
}
62
63
if ($this->createdMin !== null) {
64
$where[] = qsprintf(
65
$conn,
66
'mail.dateCreated >= %d',
67
$this->createdMin);
68
}
69
70
if ($this->createdMax !== null) {
71
$where[] = qsprintf(
72
$conn,
73
'mail.dateCreated <= %d',
74
$this->createdMax);
75
}
76
77
return $where;
78
}
79
80
protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
81
$joins = parent::buildJoinClauseParts($conn);
82
83
if ($this->shouldJoinRecipients()) {
84
$joins[] = qsprintf(
85
$conn,
86
'JOIN %T recipient
87
ON mail.phid = recipient.src
88
AND recipient.type = %d
89
AND recipient.dst IN (%Ls)',
90
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
91
PhabricatorMetaMTAMailHasRecipientEdgeType::EDGECONST,
92
$this->recipientPHIDs);
93
}
94
95
return $joins;
96
}
97
98
private function shouldJoinRecipients() {
99
if ($this->recipientPHIDs === null) {
100
return false;
101
}
102
103
return true;
104
}
105
106
protected function getPrimaryTableAlias() {
107
return 'mail';
108
}
109
110
public function newResultObject() {
111
return new PhabricatorMetaMTAMail();
112
}
113
114
public function getQueryApplicationClass() {
115
return 'PhabricatorMetaMTAApplication';
116
}
117
118
protected function shouldGroupQueryResultRows() {
119
if ($this->shouldJoinRecipients()) {
120
if (count($this->recipientPHIDs) > 1) {
121
return true;
122
}
123
}
124
125
return parent::shouldGroupQueryResultRows();
126
}
127
128
}
129
130