[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhabricatorAuthProviderConfigQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $phids;
   8    private $providerClasses;
   9  
  10    const STATUS_ALL = 'status:all';
  11    const STATUS_ENABLED = 'status:enabled';
  12  
  13    private $status = self::STATUS_ALL;
  14  
  15    public function withPHIDs(array $phids) {
  16      $this->phids = $phids;
  17      return $this;
  18    }
  19  
  20    public function withIDs(array $ids) {
  21      $this->ids = $ids;
  22      return $this;
  23    }
  24  
  25    public function withStatus($status) {
  26      $this->status = $status;
  27      return $this;
  28    }
  29  
  30    public function withProviderClasses(array $classes) {
  31      $this->providerClasses = $classes;
  32      return $this;
  33    }
  34  
  35    public static function getStatusOptions() {
  36      return array(
  37        self::STATUS_ALL      => pht('All Providers'),
  38        self::STATUS_ENABLED  => pht('Enabled Providers'),
  39      );
  40    }
  41  
  42    protected function loadPage() {
  43      $table = new PhabricatorAuthProviderConfig();
  44      $conn_r = $table->establishConnection('r');
  45  
  46      $data = queryfx_all(
  47        $conn_r,
  48        'SELECT * FROM %T %Q %Q %Q',
  49        $table->getTableName(),
  50        $this->buildWhereClause($conn_r),
  51        $this->buildOrderClause($conn_r),
  52        $this->buildLimitClause($conn_r));
  53  
  54      return $table->loadAllFromArray($data);
  55    }
  56  
  57    protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
  58      $where = array();
  59  
  60      if ($this->ids) {
  61        $where[] = qsprintf(
  62          $conn_r,
  63          'id IN (%Ld)',
  64          $this->ids);
  65      }
  66  
  67      if ($this->phids) {
  68        $where[] = qsprintf(
  69          $conn_r,
  70          'phid IN (%Ls)',
  71          $this->phids);
  72      }
  73  
  74      if ($this->providerClasses) {
  75        $where[] = qsprintf(
  76          $conn_r,
  77          'providerClass IN (%Ls)',
  78          $this->providerClasses);
  79      }
  80  
  81      $status = $this->status;
  82      switch ($status) {
  83        case self::STATUS_ALL:
  84          break;
  85        case self::STATUS_ENABLED:
  86          $where[] = qsprintf(
  87            $conn_r,
  88            'isEnabled = 1');
  89          break;
  90        default:
  91          throw new Exception("Unknown status '{$status}'!");
  92      }
  93  
  94      $where[] = $this->buildPagingClause($conn_r);
  95  
  96      return $this->formatWhereClause($where);
  97    }
  98  
  99    public function getQueryApplicationClass() {
 100      return 'PhabricatorAuthApplication';
 101    }
 102  
 103  }


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