Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/chatlog/query/PhabricatorChatLogQuery.php
13402 views
1
<?php
2
3
final class PhabricatorChatLogQuery
4
extends PhabricatorCursorPagedPolicyAwareQuery {
5
6
private $channelIDs;
7
private $maximumEpoch;
8
9
public function withChannelIDs(array $channel_ids) {
10
$this->channelIDs = $channel_ids;
11
return $this;
12
}
13
14
public function withMaximumEpoch($epoch) {
15
$this->maximumEpoch = $epoch;
16
return $this;
17
}
18
19
protected function loadPage() {
20
$table = new PhabricatorChatLogEvent();
21
$conn_r = $table->establishConnection('r');
22
23
$data = queryfx_all(
24
$conn_r,
25
'SELECT * FROM %T e %Q %Q %Q',
26
$table->getTableName(),
27
$this->buildWhereClause($conn_r),
28
$this->buildOrderClause($conn_r),
29
$this->buildLimitClause($conn_r));
30
31
$logs = $table->loadAllFromArray($data);
32
33
return $logs;
34
}
35
36
protected function willFilterPage(array $events) {
37
$channel_ids = mpull($events, 'getChannelID', 'getChannelID');
38
39
$channels = id(new PhabricatorChatLogChannelQuery())
40
->setViewer($this->getViewer())
41
->withIDs($channel_ids)
42
->execute();
43
$channels = mpull($channels, null, 'getID');
44
45
foreach ($events as $key => $event) {
46
$channel = idx($channels, $event->getChannelID());
47
if (!$channel) {
48
unset($events[$key]);
49
continue;
50
}
51
52
$event->attachChannel($channel);
53
}
54
55
return $events;
56
}
57
58
protected function buildWhereClause(AphrontDatabaseConnection $conn) {
59
$where = array();
60
61
$where[] = $this->buildPagingClause($conn);
62
63
if ($this->maximumEpoch !== null) {
64
$where[] = qsprintf(
65
$conn,
66
'epoch <= %d',
67
$this->maximumEpoch);
68
}
69
70
if ($this->channelIDs !== null) {
71
$where[] = qsprintf(
72
$conn,
73
'channelID IN (%Ld)',
74
$this->channelIDs);
75
}
76
77
return $this->formatWhereClause($conn, $where);
78
}
79
80
public function getQueryApplicationClass() {
81
return 'PhabricatorChatLogApplication';
82
}
83
84
}
85
86