Path: blob/master/src/applications/chatlog/query/PhabricatorChatLogQuery.php
13402 views
<?php12final class PhabricatorChatLogQuery3extends PhabricatorCursorPagedPolicyAwareQuery {45private $channelIDs;6private $maximumEpoch;78public function withChannelIDs(array $channel_ids) {9$this->channelIDs = $channel_ids;10return $this;11}1213public function withMaximumEpoch($epoch) {14$this->maximumEpoch = $epoch;15return $this;16}1718protected function loadPage() {19$table = new PhabricatorChatLogEvent();20$conn_r = $table->establishConnection('r');2122$data = queryfx_all(23$conn_r,24'SELECT * FROM %T e %Q %Q %Q',25$table->getTableName(),26$this->buildWhereClause($conn_r),27$this->buildOrderClause($conn_r),28$this->buildLimitClause($conn_r));2930$logs = $table->loadAllFromArray($data);3132return $logs;33}3435protected function willFilterPage(array $events) {36$channel_ids = mpull($events, 'getChannelID', 'getChannelID');3738$channels = id(new PhabricatorChatLogChannelQuery())39->setViewer($this->getViewer())40->withIDs($channel_ids)41->execute();42$channels = mpull($channels, null, 'getID');4344foreach ($events as $key => $event) {45$channel = idx($channels, $event->getChannelID());46if (!$channel) {47unset($events[$key]);48continue;49}5051$event->attachChannel($channel);52}5354return $events;55}5657protected function buildWhereClause(AphrontDatabaseConnection $conn) {58$where = array();5960$where[] = $this->buildPagingClause($conn);6162if ($this->maximumEpoch !== null) {63$where[] = qsprintf(64$conn,65'epoch <= %d',66$this->maximumEpoch);67}6869if ($this->channelIDs !== null) {70$where[] = qsprintf(71$conn,72'channelID IN (%Ld)',73$this->channelIDs);74}7576return $this->formatWhereClause($conn, $where);77}7879public function getQueryApplicationClass() {80return 'PhabricatorChatLogApplication';81}8283}848586