[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

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

   1  <?php
   2  
   3  final class PhortuneChargeQuery
   4    extends PhabricatorCursorPagedPolicyAwareQuery {
   5  
   6    private $ids;
   7    private $phids;
   8    private $accountPHIDs;
   9    private $cartPHIDs;
  10    private $statuses;
  11  
  12    private $needCarts;
  13  
  14    public function withIDs(array $ids) {
  15      $this->ids = $ids;
  16      return $this;
  17    }
  18  
  19    public function withPHIDs(array $phids) {
  20      $this->phids = $phids;
  21      return $this;
  22    }
  23  
  24    public function withAccountPHIDs(array $account_phids) {
  25      $this->accountPHIDs = $account_phids;
  26      return $this;
  27    }
  28  
  29    public function withCartPHIDs(array $cart_phids) {
  30      $this->cartPHIDs = $cart_phids;
  31      return $this;
  32    }
  33  
  34    public function withStatuses(array $statuses) {
  35      $this->statuses = $statuses;
  36      return $this;
  37    }
  38  
  39    public function needCarts($need_carts) {
  40      $this->needCarts = $need_carts;
  41      return $this;
  42    }
  43  
  44    protected function loadPage() {
  45      $table = new PhortuneCharge();
  46      $conn = $table->establishConnection('r');
  47  
  48      $rows = queryfx_all(
  49        $conn,
  50        'SELECT charge.* FROM %T charge %Q %Q %Q',
  51        $table->getTableName(),
  52        $this->buildWhereClause($conn),
  53        $this->buildOrderClause($conn),
  54        $this->buildLimitClause($conn));
  55  
  56      return $table->loadAllFromArray($rows);
  57    }
  58  
  59    protected function willFilterPage(array $charges) {
  60      $accounts = id(new PhortuneAccountQuery())
  61        ->setViewer($this->getViewer())
  62        ->setParentQuery($this)
  63        ->withPHIDs(mpull($charges, 'getAccountPHID'))
  64        ->execute();
  65      $accounts = mpull($accounts, null, 'getPHID');
  66  
  67      foreach ($charges as $key => $charge) {
  68        $account = idx($accounts, $charge->getAccountPHID());
  69        if (!$account) {
  70          unset($charges[$key]);
  71          continue;
  72        }
  73        $charge->attachAccount($account);
  74      }
  75  
  76      return $charges;
  77    }
  78  
  79    protected function didFilterPage(array $charges) {
  80      if ($this->needCarts) {
  81        $carts = id(new PhortuneCartQuery())
  82          ->setViewer($this->getViewer())
  83          ->setParentQuery($this)
  84          ->withPHIDs(mpull($charges, 'getCartPHID'))
  85          ->execute();
  86        $carts = mpull($carts, null, 'getPHID');
  87  
  88        foreach ($charges as $charge) {
  89          $cart = idx($carts, $charge->getCartPHID());
  90          $charge->attachCart($cart);
  91        }
  92      }
  93  
  94      return $charges;
  95    }
  96  
  97    private function buildWhereClause(AphrontDatabaseConnection $conn) {
  98      $where = array();
  99  
 100      $where[] = $this->buildPagingClause($conn);
 101  
 102      if ($this->ids !== null) {
 103        $where[] = qsprintf(
 104          $conn,
 105          'charge.id IN (%Ld)',
 106          $this->ids);
 107      }
 108  
 109      if ($this->phids !== null) {
 110        $where[] = qsprintf(
 111          $conn,
 112          'charge.phid IN (%Ls)',
 113          $this->phids);
 114      }
 115  
 116      if ($this->accountPHIDs !== null) {
 117        $where[] = qsprintf(
 118          $conn,
 119          'charge.accountPHID IN (%Ls)',
 120          $this->accountPHIDs);
 121      }
 122  
 123      if ($this->cartPHIDs !== null) {
 124        $where[] = qsprintf(
 125          $conn,
 126          'charge.cartPHID IN (%Ls)',
 127          $this->cartPHIDs);
 128      }
 129  
 130      if ($this->statuses !== null) {
 131        $where[] = qsprintf(
 132          $conn,
 133          'charge.status IN (%Ls)',
 134          $this->statuses);
 135      }
 136  
 137      return $this->formatWhereClause($where);
 138    }
 139  
 140    public function getQueryApplicationClass() {
 141      return 'PhabricatorPhortuneApplication';
 142    }
 143  
 144  }


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