[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/oauthserver/query/ -> PhabricatorOAuthClientAuthorizationQuery.php (source)

   1  <?php
   2  
   3  final class PhabricatorOAuthClientAuthorizationQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $phids;
   7    private $userPHIDs;
   8    private $clientPHIDs;
   9  
  10    public function witHPHIDs(array $phids) {
  11      $this->phids = $phids;
  12      return $this;
  13    }
  14  
  15    public function withUserPHIDs(array $phids) {
  16      $this->userPHIDs = $phids;
  17      return $this;
  18    }
  19  
  20    public function withClientPHIDs(array $phids) {
  21      $this->clientPHIDs = $phids;
  22      return $this;
  23    }
  24  
  25    public function loadPage() {
  26      $table  = new PhabricatorOAuthClientAuthorization();
  27      $conn_r = $table->establishConnection('r');
  28  
  29      $data = queryfx_all(
  30        $conn_r,
  31        'SELECT * FROM %T auth %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($data);
  38    }
  39  
  40    public function willFilterPage(array $authorizations) {
  41      $client_phids = mpull($authorizations, 'getClientPHID');
  42  
  43      $clients = id(new PhabricatorOAuthServerClientQuery())
  44        ->setViewer($this->getViewer())
  45        ->setParentQuery($this)
  46        ->withPHIDs($client_phids)
  47        ->execute();
  48      $clients = mpull($clients, null, 'getPHID');
  49  
  50      foreach ($authorizations as $key => $authorization) {
  51        $client = idx($clients, $authorization->getClientPHID());
  52        if (!$client) {
  53          unset($authorizations[$key]);
  54          continue;
  55        }
  56        $authorization->attachClient($client);
  57      }
  58  
  59      return $authorizations;
  60    }
  61  
  62    private function buildWhereClause($conn_r) {
  63      $where = array();
  64  
  65      if ($this->phids) {
  66        $where[] = qsprintf(
  67          $conn_r,
  68          'phid IN (%Ls)',
  69          $this->phids);
  70      }
  71  
  72      if ($this->userPHIDs) {
  73        $where[] = qsprintf(
  74          $conn_r,
  75          'userPHID IN (%Ls)',
  76          $this->userPHIDs);
  77      }
  78  
  79      if ($this->clientPHIDs) {
  80        $where[] = qsprintf(
  81          $conn_r,
  82          'clientPHID IN (%Ls)',
  83          $this->clientPHIDs);
  84      }
  85  
  86      $where[] = $this->buildPagingClause($conn_r);
  87  
  88      return $this->formatWhereClause($where);
  89    }
  90  
  91    public function getQueryApplicationClass() {
  92      return 'PhabricatorOAuthServerApplication';
  93    }
  94  
  95  }


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