[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/auth/query/ -> PhabricatorAuthTemporaryTokenQuery.php (source)

   1  <?php
   2  
   3  final class PhabricatorAuthTemporaryTokenQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $objectPHIDs;
   8    private $tokenTypes;
   9    private $expired;
  10    private $tokenCodes;
  11  
  12    public function withIDs(array $ids) {
  13      $this->ids = $ids;
  14      return $this;
  15    }
  16  
  17    public function withObjectPHIDs(array $object_phids) {
  18      $this->objectPHIDs = $object_phids;
  19      return $this;
  20    }
  21  
  22    public function withTokenTypes(array $types) {
  23      $this->tokenTypes = $types;
  24      return $this;
  25    }
  26  
  27    public function withExpired($expired) {
  28      $this->expired = $expired;
  29      return $this;
  30    }
  31  
  32    public function withTokenCodes(array $codes) {
  33      $this->tokenCodes = $codes;
  34      return $this;
  35    }
  36  
  37    protected function loadPage() {
  38      $table = new PhabricatorAuthTemporaryToken();
  39      $conn_r = $table->establishConnection('r');
  40  
  41      $data = queryfx_all(
  42        $conn_r,
  43        'SELECT * FROM %T %Q %Q %Q',
  44        $table->getTableName(),
  45        $this->buildWhereClause($conn_r),
  46        $this->buildOrderClause($conn_r),
  47        $this->buildLimitClause($conn_r));
  48  
  49      return $table->loadAllFromArray($data);
  50    }
  51  
  52    protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
  53      $where = array();
  54  
  55      if ($this->ids !== null) {
  56        $where[] = qsprintf(
  57          $conn_r,
  58          'id IN (%Ld)',
  59          $this->ids);
  60      }
  61  
  62      if ($this->objectPHIDs !== null) {
  63        $where[] = qsprintf(
  64          $conn_r,
  65          'objectPHID IN (%Ls)',
  66          $this->objectPHIDs);
  67      }
  68  
  69      if ($this->tokenTypes !== null) {
  70        $where[] = qsprintf(
  71          $conn_r,
  72          'tokenType IN (%Ls)',
  73          $this->tokenTypes);
  74      }
  75  
  76      if ($this->expired !== null) {
  77        if ($this->expired) {
  78          $where[] = qsprintf(
  79            $conn_r,
  80            'tokenExpires <= %d',
  81            time());
  82        } else {
  83          $where[] = qsprintf(
  84            $conn_r,
  85            'tokenExpires > %d',
  86            time());
  87        }
  88      }
  89  
  90      if ($this->tokenCodes !== null) {
  91        $where[] = qsprintf(
  92          $conn_r,
  93          'tokenCode IN (%Ls)',
  94          $this->tokenCodes);
  95      }
  96  
  97      $where[] = $this->buildPagingClause($conn_r);
  98  
  99      return $this->formatWhereClause($where);
 100    }
 101  
 102    public function getQueryApplicationClass() {
 103      return 'PhabricatorAuthApplication';
 104    }
 105  
 106  }


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