[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/tokens/query/ -> PhabricatorTokenGivenQuery.php (source)

   1  <?php
   2  
   3  final class PhabricatorTokenGivenQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $authorPHIDs;
   7    private $objectPHIDs;
   8    private $tokenPHIDs;
   9  
  10    public function withTokenPHIDs(array $token_phids) {
  11      $this->tokenPHIDs = $token_phids;
  12      return $this;
  13    }
  14  
  15    public function withObjectPHIDs(array $object_phids) {
  16      $this->objectPHIDs = $object_phids;
  17      return $this;
  18    }
  19  
  20    public function withAuthorPHIDs(array $author_phids) {
  21      $this->authorPHIDs = $author_phids;
  22      return $this;
  23    }
  24  
  25    protected function loadPage() {
  26      $table = new PhabricatorTokenGiven();
  27      $conn_r = $table->establishConnection('r');
  28  
  29      $rows = queryfx_all(
  30        $conn_r,
  31        'SELECT * FROM %T %Q %Q %Q',
  32        $table->getTableName(),
  33        $this->buildWhereClause($conn_r),
  34        $this->buildOrderClause($conn_r),
  35        $this->buildLimitClause($conn_r));
  36  
  37      return $table->loadAllFromArray($rows);
  38    }
  39  
  40    private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
  41      $where = array();
  42  
  43      if ($this->authorPHIDs) {
  44        $where[] = qsprintf(
  45          $conn_r,
  46          'authorPHID IN (%Ls)',
  47          $this->authorPHIDs);
  48      }
  49  
  50      if ($this->objectPHIDs) {
  51        $where[] = qsprintf(
  52          $conn_r,
  53          'objectPHID IN (%Ls)',
  54          $this->objectPHIDs);
  55      }
  56  
  57      if ($this->tokenPHIDs) {
  58        $where[] = qsprintf(
  59          $conn_r,
  60          'tokenPHID IN (%Ls)',
  61          $this->tokenPHIDs);
  62      }
  63  
  64      $where[] = $this->buildPagingClause($conn_r);
  65  
  66      return $this->formatWhereClause($where);
  67    }
  68  
  69    public function willFilterPage(array $results) {
  70      $object_phids = array_filter(mpull($results, 'getObjectPHID'));
  71      if (!$object_phids) {
  72        return array();
  73      }
  74  
  75      $objects = id(new PhabricatorObjectQuery())
  76        ->setViewer($this->getViewer())
  77        ->withPHIDs($object_phids)
  78        ->execute();
  79  
  80      foreach ($results as $key => $result) {
  81        $phid = $result->getObjectPHID();
  82        if (empty($objects[$phid])) {
  83          unset($results[$key]);
  84        } else {
  85          $result->attachObject($objects[$phid]);
  86        }
  87      }
  88  
  89      return $results;
  90    }
  91  
  92    public function getQueryApplicationClass() {
  93      return 'PhabricatorTokensApplication';
  94    }
  95  
  96  }


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