[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phortune/query/ -> PhortunePaymentProviderConfigQuery.php (source)

   1  <?php
   2  
   3  final class PhortunePaymentProviderConfigQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $phids;
   8    private $merchantPHIDs;
   9  
  10    public function withIDs(array $ids) {
  11      $this->ids = $ids;
  12      return $this;
  13    }
  14  
  15    public function withPHIDs(array $phids) {
  16      $this->phids = $phids;
  17      return $this;
  18    }
  19  
  20    public function withMerchantPHIDs(array $phids) {
  21      $this->merchantPHIDs = $phids;
  22      return $this;
  23    }
  24  
  25    protected function loadPage() {
  26      $table = new PhortunePaymentProviderConfig();
  27      $conn = $table->establishConnection('r');
  28  
  29      $rows = queryfx_all(
  30        $conn,
  31        'SELECT * FROM %T %Q %Q %Q',
  32        $table->getTableName(),
  33        $this->buildWhereClause($conn),
  34        $this->buildOrderClause($conn),
  35        $this->buildLimitClause($conn));
  36  
  37      return $table->loadAllFromArray($rows);
  38    }
  39  
  40    protected function willFilterPage(array $provider_configs) {
  41      $merchant_phids = mpull($provider_configs, 'getMerchantPHID');
  42      $merchants = id(new PhortuneMerchantQuery())
  43        ->setViewer($this->getViewer())
  44        ->setParentQuery($this)
  45        ->withPHIDs($merchant_phids)
  46        ->execute();
  47      $merchants = mpull($merchants, null, 'getPHID');
  48  
  49      foreach ($provider_configs as $key => $config) {
  50        $merchant = idx($merchants, $config->getMerchantPHID());
  51        if (!$merchant) {
  52          $this->didRejectResult($config);
  53          unset($provider_configs[$key]);
  54          continue;
  55        }
  56        $config->attachMerchant($merchant);
  57      }
  58  
  59      return $provider_configs;
  60    }
  61  
  62    private function buildWhereClause(AphrontDatabaseConnection $conn) {
  63      $where = array();
  64  
  65      if ($this->ids !== null) {
  66        $where[] = qsprintf(
  67          $conn,
  68          'id IN (%Ld)',
  69          $this->ids);
  70      }
  71  
  72      if ($this->phids !== null) {
  73        $where[] = qsprintf(
  74          $conn,
  75          'phid IN (%Ls)',
  76          $this->phids);
  77      }
  78  
  79      if ($this->merchantPHIDs !== null) {
  80        $where[] = qsprintf(
  81          $conn,
  82          'merchantPHID IN (%Ls)',
  83          $this->merchantPHIDs);
  84      }
  85  
  86      $where[] = $this->buildPagingClause($conn);
  87  
  88      return $this->formatWhereClause($where);
  89    }
  90  
  91    public function getQueryApplicationClass() {
  92      return 'PhabricatorPhortuneApplication';
  93    }
  94  
  95  }


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