[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhortunePaymentMethodQuery 4 extends PhabricatorCursorPagedPolicyAwareQuery { 5 6 private $ids; 7 private $phids; 8 private $accountPHIDs; 9 private $merchantPHIDs; 10 private $statuses; 11 12 public function withIDs(array $ids) { 13 $this->ids = $ids; 14 return $this; 15 } 16 17 public function withPHIDs(array $phids) { 18 $this->phids = $phids; 19 return $this; 20 } 21 22 public function withAccountPHIDs(array $phids) { 23 $this->accountPHIDs = $phids; 24 return $this; 25 } 26 27 public function withMerchantPHIDs(array $phids) { 28 $this->merchantPHIDs = $phids; 29 return $this; 30 } 31 32 public function withStatuses(array $statuses) { 33 $this->statuses = $statuses; 34 return $this; 35 } 36 37 protected function loadPage() { 38 $table = new PhortunePaymentMethod(); 39 $conn = $table->establishConnection('r'); 40 41 $rows = queryfx_all( 42 $conn, 43 'SELECT * FROM %T %Q %Q %Q', 44 $table->getTableName(), 45 $this->buildWhereClause($conn), 46 $this->buildOrderClause($conn), 47 $this->buildLimitClause($conn)); 48 49 return $table->loadAllFromArray($rows); 50 } 51 52 protected function willFilterPage(array $methods) { 53 $accounts = id(new PhortuneAccountQuery()) 54 ->setViewer($this->getViewer()) 55 ->withPHIDs(mpull($methods, 'getAccountPHID')) 56 ->execute(); 57 $accounts = mpull($accounts, null, 'getPHID'); 58 59 foreach ($methods as $key => $method) { 60 $account = idx($accounts, $method->getAccountPHID()); 61 if (!$account) { 62 unset($methods[$key]); 63 continue; 64 } 65 $method->attachAccount($account); 66 } 67 68 $merchants = id(new PhortuneMerchantQuery()) 69 ->setViewer($this->getViewer()) 70 ->withPHIDs(mpull($methods, 'getMerchantPHID')) 71 ->execute(); 72 $merchants = mpull($merchants, null, 'getPHID'); 73 74 foreach ($methods as $key => $method) { 75 $merchant = idx($merchants, $method->getMerchantPHID()); 76 if (!$merchant) { 77 unset($methods[$key]); 78 continue; 79 } 80 $method->attachMerchant($merchant); 81 } 82 83 $provider_configs = id(new PhortunePaymentProviderConfigQuery()) 84 ->setViewer($this->getViewer()) 85 ->withPHIDs(mpull($methods, 'getProviderPHID')) 86 ->execute(); 87 $provider_configs = mpull($provider_configs, null, 'getPHID'); 88 89 foreach ($methods as $key => $method) { 90 $provider_config = idx($provider_configs, $method->getProviderPHID()); 91 if (!$provider_config) { 92 unset($methods[$key]); 93 continue; 94 } 95 $method->attachProviderConfig($provider_config); 96 } 97 98 return $methods; 99 } 100 101 private function buildWhereClause(AphrontDatabaseConnection $conn) { 102 $where = array(); 103 104 if ($this->ids !== null) { 105 $where[] = qsprintf( 106 $conn, 107 'id IN (%Ld)', 108 $this->ids); 109 } 110 111 if ($this->phids !== null) { 112 $where[] = qsprintf( 113 $conn, 114 'phid IN (%Ls)', 115 $this->phids); 116 } 117 118 if ($this->accountPHIDs !== null) { 119 $where[] = qsprintf( 120 $conn, 121 'accountPHID IN (%Ls)', 122 $this->accountPHIDs); 123 } 124 125 if ($this->merchantPHIDs !== null) { 126 $where[] = qsprintf( 127 $conn, 128 'merchantPHID IN (%Ls)', 129 $this->merchantPHIDs); 130 } 131 132 if ($this->statuses !== null) { 133 $where[] = qsprintf( 134 $conn, 135 'status IN (%Ls)', 136 $this->statuses); 137 } 138 139 $where[] = $this->buildPagingClause($conn); 140 141 return $this->formatWhereClause($where); 142 } 143 144 public function getQueryApplicationClass() { 145 return 'PhabricatorPhortuneApplication'; 146 } 147 148 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |