Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/conpherence/query/ConpherenceParticipantCountQuery.php
12256 views
1
<?php
2
3
final class ConpherenceParticipantCountQuery
4
extends PhabricatorOffsetPagedQuery {
5
6
private $participantPHIDs;
7
private $unread;
8
9
public function withParticipantPHIDs(array $phids) {
10
$this->participantPHIDs = $phids;
11
return $this;
12
}
13
14
public function withUnread($unread) {
15
$this->unread = $unread;
16
return $this;
17
}
18
19
public function execute() {
20
$thread = new ConpherenceThread();
21
$table = new ConpherenceParticipant();
22
$conn = $table->establishConnection('r');
23
24
$rows = queryfx_all(
25
$conn,
26
'SELECT COUNT(*) as count, participantPHID
27
FROM %T participant JOIN %T thread
28
ON participant.conpherencePHID = thread.phid %Q %Q %Q',
29
$table->getTableName(),
30
$thread->getTableName(),
31
$this->buildWhereClause($conn),
32
$this->buildGroupByClause($conn),
33
$this->buildLimitClause($conn));
34
35
return ipull($rows, 'count', 'participantPHID');
36
}
37
38
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
39
$where = array();
40
41
if ($this->participantPHIDs !== null) {
42
$where[] = qsprintf(
43
$conn,
44
'participant.participantPHID IN (%Ls)',
45
$this->participantPHIDs);
46
}
47
48
if ($this->unread !== null) {
49
if ($this->unread) {
50
$where[] = qsprintf(
51
$conn,
52
'participant.seenMessageCount < thread.messageCount');
53
} else {
54
$where[] = qsprintf(
55
$conn,
56
'participant.seenMessageCount >= thread.messageCount');
57
}
58
}
59
60
return $this->formatWhereClause($conn, $where);
61
}
62
63
private function buildGroupByClause(AphrontDatabaseConnection $conn) {
64
return qsprintf(
65
$conn,
66
'GROUP BY participantPHID');
67
}
68
69
}
70
71