[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/chatlog/query/ -> PhabricatorChatLogQuery.php (source)

   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    public 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    private function buildWhereClause($conn_r) {
  59      $where = array();
  60  
  61      $where[] = $this->buildPagingClause($conn_r);
  62  
  63      if ($this->maximumEpoch) {
  64        $where[] = qsprintf(
  65          $conn_r,
  66          'epoch <= %d',
  67          $this->maximumEpoch);
  68      }
  69  
  70      if ($this->channelIDs) {
  71        $where[] = qsprintf(
  72          $conn_r,
  73          'channelID IN (%Ld)',
  74          $this->channelIDs);
  75      }
  76  
  77      return $this->formatWhereClause($where);
  78    }
  79  
  80    public function getQueryApplicationClass() {
  81      return 'PhabricatorChatLogApplication';
  82    }
  83  
  84  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1