@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Show only recent orders and charges on Phortune account profile page

Summary: Ref T2787. Currently, we show all orders/charges, which won't scale well. Show the 10 most recent and link to full order/charge history.

Test Plan: {F216325}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D10685

+533 -137
+8
src/__phutil_library_map__.php
··· 2571 2571 'PhortuneCartUpdateController' => 'applications/phortune/controller/PhortuneCartUpdateController.php', 2572 2572 'PhortuneCartViewController' => 'applications/phortune/controller/PhortuneCartViewController.php', 2573 2573 'PhortuneCharge' => 'applications/phortune/storage/PhortuneCharge.php', 2574 + 'PhortuneChargeListController' => 'applications/phortune/controller/PhortuneChargeListController.php', 2574 2575 'PhortuneChargePHIDType' => 'applications/phortune/phid/PhortuneChargePHIDType.php', 2575 2576 'PhortuneChargeQuery' => 'applications/phortune/query/PhortuneChargeQuery.php', 2577 + 'PhortuneChargeSearchEngine' => 'applications/phortune/query/PhortuneChargeSearchEngine.php', 2578 + 'PhortuneChargeTableView' => 'applications/phortune/view/PhortuneChargeTableView.php', 2576 2579 'PhortuneConstants' => 'applications/phortune/constants/PhortuneConstants.php', 2577 2580 'PhortuneController' => 'applications/phortune/controller/PhortuneController.php', 2578 2581 'PhortuneCreditCardForm' => 'applications/phortune/view/PhortuneCreditCardForm.php', ··· 2601 2604 'PhortuneMultiplePaymentProvidersException' => 'applications/phortune/exception/PhortuneMultiplePaymentProvidersException.php', 2602 2605 'PhortuneNoPaymentProviderException' => 'applications/phortune/exception/PhortuneNoPaymentProviderException.php', 2603 2606 'PhortuneNotImplementedException' => 'applications/phortune/exception/PhortuneNotImplementedException.php', 2607 + 'PhortuneOrderTableView' => 'applications/phortune/view/PhortuneOrderTableView.php', 2604 2608 'PhortunePayPalPaymentProvider' => 'applications/phortune/provider/PhortunePayPalPaymentProvider.php', 2605 2609 'PhortunePaymentMethod' => 'applications/phortune/storage/PhortunePaymentMethod.php', 2606 2610 'PhortunePaymentMethodCreateController' => 'applications/phortune/controller/PhortunePaymentMethodCreateController.php', ··· 5637 5641 'PhortuneDAO', 5638 5642 'PhabricatorPolicyInterface', 5639 5643 ), 5644 + 'PhortuneChargeListController' => 'PhortuneController', 5640 5645 'PhortuneChargePHIDType' => 'PhabricatorPHIDType', 5641 5646 'PhortuneChargeQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 5647 + 'PhortuneChargeSearchEngine' => 'PhabricatorApplicationSearchEngine', 5648 + 'PhortuneChargeTableView' => 'AphrontView', 5642 5649 'PhortuneController' => 'PhabricatorController', 5643 5650 'PhortuneCurrency' => 'Phobject', 5644 5651 'PhortuneCurrencySerializer' => 'PhabricatorLiskSerializer', ··· 5668 5675 'PhortuneMultiplePaymentProvidersException' => 'Exception', 5669 5676 'PhortuneNoPaymentProviderException' => 'Exception', 5670 5677 'PhortuneNotImplementedException' => 'Exception', 5678 + 'PhortuneOrderTableView' => 'AphrontView', 5671 5679 'PhortunePayPalPaymentProvider' => 'PhortunePaymentProvider', 5672 5680 'PhortunePaymentMethod' => array( 5673 5681 'PhortuneDAO',
+4
src/applications/phortune/application/PhabricatorPhortuneApplication.php
··· 39 39 'card/' => array( 40 40 'new/' => 'PhortunePaymentMethodCreateController', 41 41 ), 42 + 'order/(?:query/(?P<queryKey>[^/]+)/)?' 43 + => 'PhortuneCartListController', 44 + 'charge/(?:query/(?P<queryKey>[^/]+)/)?' 45 + => 'PhortuneChargeListController', 42 46 ), 43 47 'card/(?P<id>\d+)/' => array( 44 48 'edit/' => 'PhortunePaymentMethodEditController',
+2 -2
src/applications/phortune/controller/PhortuneAccountListController.php
··· 83 83 ->setHref($this->getApplicationURI('merchant/')) 84 84 ->setIcon( 85 85 id(new PHUIIconView()) 86 - ->setIconFont('fa-folder-open')) 87 - ->setText(pht('Browse Merchants'))); 86 + ->setIconFont('fa-list')) 87 + ->setText(pht('View All Merchants'))); 88 88 89 89 $merchant_box = id(new PHUIObjectBoxView()) 90 90 ->setHeader($merchant_header)
+47 -65
src/applications/phortune/controller/PhortuneAccountViewController.php
··· 179 179 PhortuneCart::STATUS_REVIEW, 180 180 PhortuneCart::STATUS_PURCHASED, 181 181 )) 182 + ->setLimit(10) 182 183 ->execute(); 183 184 184 185 $phids = array(); ··· 190 191 } 191 192 $handles = $this->loadViewerHandles($phids); 192 193 193 - $rows = array(); 194 - $rowc = array(); 195 - foreach ($carts as $cart) { 196 - $cart_link = $handles[$cart->getPHID()]->renderLink(); 197 - $purchases = $cart->getPurchases(); 198 - 199 - if (count($purchases) == 1) { 200 - $purchase_name = $handles[$purchase->getPHID()]->renderLink(); 201 - $purchases = array(); 202 - } else { 203 - $purchase_name = ''; 204 - } 205 - 206 - $rowc[] = ''; 207 - $rows[] = array( 208 - $cart->getID(), 209 - phutil_tag( 210 - 'strong', 211 - array(), 212 - $cart_link), 213 - $purchase_name, 214 - phutil_tag( 215 - 'strong', 216 - array(), 217 - $cart->getTotalPriceAsCurrency()->formatForDisplay()), 218 - PhortuneCart::getNameForStatus($cart->getStatus()), 219 - phabricator_datetime($cart->getDateModified(), $viewer), 220 - ); 221 - foreach ($purchases as $purchase) { 222 - $id = $purchase->getID(); 223 - 224 - $price = $purchase->getTotalPriceAsCurrency()->formatForDisplay(); 225 - 226 - $rowc[] = ''; 227 - $rows[] = array( 228 - '', 229 - $handles[$purchase->getPHID()]->renderLink(), 230 - $price, 231 - '', 232 - '', 233 - ); 234 - } 235 - } 194 + $orders_uri = $this->getApplicationURI($account->getID().'/order/'); 236 195 237 - $table = id(new AphrontTableView($rows)) 238 - ->setRowClasses($rowc) 239 - ->setHeaders( 240 - array( 241 - pht('ID'), 242 - pht('Order'), 243 - pht('Purchase'), 244 - pht('Amount'), 245 - pht('Status'), 246 - pht('Updated'), 247 - )) 248 - ->setColumnClasses( 249 - array( 250 - '', 251 - '', 252 - 'wide', 253 - 'right', 254 - '', 255 - 'right', 256 - )); 196 + $table = id(new PhortuneOrderTableView()) 197 + ->setUser($viewer) 198 + ->setCarts($carts) 199 + ->setHandles($handles); 257 200 258 201 $header = id(new PHUIHeaderView()) 259 - ->setHeader(pht('Order History')); 202 + ->setHeader(pht('Recent Orders')) 203 + ->addActionLink( 204 + id(new PHUIButtonView()) 205 + ->setTag('a') 206 + ->setIcon( 207 + id(new PHUIIconView()) 208 + ->setIconFont('fa-list')) 209 + ->setHref($orders_uri) 210 + ->setText(pht('View All Orders'))); 260 211 261 212 return id(new PHUIObjectBoxView()) 262 213 ->setHeader($header) ··· 271 222 ->setViewer($viewer) 272 223 ->withAccountPHIDs(array($account->getPHID())) 273 224 ->needCarts(true) 225 + ->setLimit(10) 274 226 ->execute(); 275 227 276 - return $this->buildChargesTable($charges); 228 + $phids = array(); 229 + foreach ($charges as $charge) { 230 + $phids[] = $charge->getProviderPHID(); 231 + $phids[] = $charge->getCartPHID(); 232 + $phids[] = $charge->getMerchantPHID(); 233 + $phids[] = $charge->getPaymentMethodPHID(); 234 + } 235 + 236 + $handles = $this->loadViewerHandles($phids); 237 + 238 + $charges_uri = $this->getApplicationURI($account->getID().'/charge/'); 239 + 240 + $table = id(new PhortuneChargeTableView()) 241 + ->setUser($viewer) 242 + ->setCharges($charges) 243 + ->setHandles($handles); 244 + 245 + $header = id(new PHUIHeaderView()) 246 + ->setHeader(pht('Recent Charges')) 247 + ->addActionLink( 248 + id(new PHUIButtonView()) 249 + ->setTag('a') 250 + ->setIcon( 251 + id(new PHUIIconView()) 252 + ->setIconFont('fa-list')) 253 + ->setHref($charges_uri) 254 + ->setText(pht('View All Charges'))); 255 + 256 + return id(new PHUIObjectBoxView()) 257 + ->setHeader($header) 258 + ->appendChild($table); 277 259 } 278 260 279 261 private function buildAccountHistorySection(PhortuneAccount $account) {
+31
src/applications/phortune/controller/PhortuneCartListController.php
··· 3 3 final class PhortuneCartListController 4 4 extends PhortuneController { 5 5 6 + private $accountID; 6 7 private $merchantID; 7 8 private $queryKey; 8 9 9 10 private $merchant; 11 + private $account; 10 12 11 13 public function willProcessRequest(array $data) { 12 14 $this->merchantID = idx($data, 'merchantID'); 15 + $this->accountID = idx($data, 'accountID'); 13 16 $this->queryKey = idx($data, 'queryKey'); 14 17 } 15 18 ··· 34 37 } 35 38 $this->merchant = $merchant; 36 39 $engine->setMerchant($merchant); 40 + } else if ($this->accountID) { 41 + $account = id(new PhortuneAccountQuery()) 42 + ->setViewer($viewer) 43 + ->withIDs(array($this->accountID)) 44 + ->requireCapabilities( 45 + array( 46 + PhabricatorPolicyCapability::CAN_VIEW, 47 + PhabricatorPolicyCapability::CAN_EDIT, 48 + )) 49 + ->executeOne(); 50 + if (!$account) { 51 + return new Aphront404Response(); 52 + } 53 + $this->account = $account; 54 + $engine->setAccount($account); 55 + } else { 56 + return new Aphront404Response(); 37 57 } 38 58 39 59 $controller = id(new PhabricatorApplicationSearchController($request)) ··· 71 91 $crumbs->addTextCrumb( 72 92 pht('Orders'), 73 93 $this->getApplicationURI("merchant/orders/{$id}/")); 94 + } 95 + 96 + $account = $this->account; 97 + if ($account) { 98 + $id = $account->getID(); 99 + $crumbs->addTextCrumb( 100 + $account->getName(), 101 + $this->getApplicationURI("{$id}/")); 102 + $crumbs->addTextCrumb( 103 + pht('Orders'), 104 + $this->getApplicationURI("{$id}/order/")); 74 105 } 75 106 76 107 return $crumbs;
+19 -2
src/applications/phortune/controller/PhortuneCartViewController.php
··· 135 135 ->needCarts(true) 136 136 ->execute(); 137 137 138 - $charges_table = $this->buildChargesTable($charges, false); 138 + $phids = array(); 139 + foreach ($charges as $charge) { 140 + $phids[] = $charge->getProviderPHID(); 141 + $phids[] = $charge->getCartPHID(); 142 + $phids[] = $charge->getMerchantPHID(); 143 + $phids[] = $charge->getPaymentMethodPHID(); 144 + } 145 + $handles = $this->loadViewerHandles($phids); 146 + 147 + $charges_table = id(new PhortuneChargeTableView()) 148 + ->setUser($viewer) 149 + ->setHandles($handles) 150 + ->setCharges($charges) 151 + ->setShowOrder(false); 152 + 153 + $charges = id(new PHUIObjectBoxView()) 154 + ->setHeaderText(pht('Charges')) 155 + ->appendChild($charges_table); 139 156 140 157 $account = $cart->getAccount(); 141 158 ··· 147 164 array( 148 165 $crumbs, 149 166 $cart_box, 150 - $charges_table, 167 + $charges, 151 168 ), 152 169 array( 153 170 'title' => pht('Cart'),
+81
src/applications/phortune/controller/PhortuneChargeListController.php
··· 1 + <?php 2 + 3 + final class PhortuneChargeListController 4 + extends PhortuneController { 5 + 6 + private $accountID; 7 + private $queryKey; 8 + 9 + private $account; 10 + 11 + public function willProcessRequest(array $data) { 12 + $this->accountID = idx($data, 'accountID'); 13 + $this->queryKey = idx($data, 'queryKey'); 14 + } 15 + 16 + public function processRequest() { 17 + $request = $this->getRequest(); 18 + $viewer = $request->getUser(); 19 + 20 + $engine = new PhortuneChargeSearchEngine(); 21 + 22 + if ($this->accountID) { 23 + $account = id(new PhortuneAccountQuery()) 24 + ->setViewer($viewer) 25 + ->withIDs(array($this->accountID)) 26 + ->requireCapabilities( 27 + array( 28 + PhabricatorPolicyCapability::CAN_VIEW, 29 + PhabricatorPolicyCapability::CAN_EDIT, 30 + )) 31 + ->executeOne(); 32 + if (!$account) { 33 + return new Aphront404Response(); 34 + } 35 + $this->account = $account; 36 + $engine->setAccount($account); 37 + } else { 38 + return new Aphront404Response(); 39 + } 40 + 41 + $controller = id(new PhabricatorApplicationSearchController($request)) 42 + ->setQueryKey($this->queryKey) 43 + ->setSearchEngine($engine) 44 + ->setNavigation($this->buildSideNavView()); 45 + 46 + return $this->delegateToController($controller); 47 + } 48 + 49 + public function buildSideNavView() { 50 + $viewer = $this->getRequest()->getUser(); 51 + 52 + $nav = new AphrontSideNavFilterView(); 53 + $nav->setBaseURI(new PhutilURI($this->getApplicationURI())); 54 + 55 + id(new PhortuneChargeSearchEngine()) 56 + ->setViewer($viewer) 57 + ->addNavigationItems($nav->getMenu()); 58 + 59 + $nav->selectFilter(null); 60 + 61 + return $nav; 62 + } 63 + 64 + public function buildApplicationCrumbs() { 65 + $crumbs = parent::buildApplicationCrumbs(); 66 + 67 + $account = $this->account; 68 + if ($account) { 69 + $id = $account->getID(); 70 + $crumbs->addTextCrumb( 71 + $account->getName(), 72 + $this->getApplicationURI("{$id}/")); 73 + $crumbs->addTextCrumb( 74 + pht('Charges'), 75 + $this->getApplicationURI("{$id}/charge/")); 76 + } 77 + 78 + return $crumbs; 79 + } 80 + 81 + }
-67
src/applications/phortune/controller/PhortuneController.php
··· 2 2 3 3 abstract class PhortuneController extends PhabricatorController { 4 4 5 - protected function buildChargesTable(array $charges, $show_cart = true) { 6 - $request = $this->getRequest(); 7 - $viewer = $request->getUser(); 8 - 9 - $phids = array(); 10 - foreach ($charges as $charge) { 11 - $phids[] = $charge->getProviderPHID(); 12 - $phids[] = $charge->getCartPHID(); 13 - $phids[] = $charge->getMerchantPHID(); 14 - $phids[] = $charge->getPaymentMethodPHID(); 15 - } 16 - 17 - $handles = $this->loadViewerHandles($phids); 18 - 19 - $rows = array(); 20 - foreach ($charges as $charge) { 21 - $rows[] = array( 22 - $charge->getID(), 23 - $handles[$charge->getCartPHID()]->renderLink(), 24 - $handles[$charge->getProviderPHID()]->renderLink(), 25 - $charge->getPaymentMethodPHID() 26 - ? $handles[$charge->getPaymentMethodPHID()]->renderLink() 27 - : null, 28 - $handles[$charge->getMerchantPHID()]->renderLink(), 29 - $charge->getAmountAsCurrency()->formatForDisplay(), 30 - $charge->getStatusForDisplay(), 31 - phabricator_datetime($charge->getDateCreated(), $viewer), 32 - ); 33 - } 34 - 35 - $charge_table = id(new AphrontTableView($rows)) 36 - ->setHeaders( 37 - array( 38 - pht('ID'), 39 - pht('Cart'), 40 - pht('Provider'), 41 - pht('Method'), 42 - pht('Merchant'), 43 - pht('Amount'), 44 - pht('Status'), 45 - pht('Created'), 46 - )) 47 - ->setColumnClasses( 48 - array( 49 - '', 50 - '', 51 - '', 52 - '', 53 - '', 54 - 'wide right', 55 - '', 56 - '', 57 - )) 58 - ->setColumnVisibility( 59 - array( 60 - true, 61 - $show_cart, 62 - )); 63 - 64 - $header = id(new PHUIHeaderView()) 65 - ->setHeader(pht('Charge History')); 66 - 67 - return id(new PHUIObjectBoxView()) 68 - ->setHeader($header) 69 - ->appendChild($charge_table); 70 - } 71 - 72 5 protected function addAccountCrumb( 73 6 $crumbs, 74 7 PhortuneAccount $account,
+27 -1
src/applications/phortune/query/PhortuneCartSearchEngine.php
··· 4 4 extends PhabricatorApplicationSearchEngine { 5 5 6 6 private $merchant; 7 + private $account; 8 + 9 + public function setAccount(PhortuneAccount $account) { 10 + $this->account = $account; 11 + return $this; 12 + } 13 + 14 + public function getAccount() { 15 + return $this->account; 16 + } 7 17 8 18 public function setMerchant(PhortuneMerchant $merchant) { 9 19 $this->merchant = $merchant; ··· 39 49 $viewer = $this->requireViewer(); 40 50 41 51 $merchant = $this->getMerchant(); 52 + $account = $this->getAccount(); 42 53 if ($merchant) { 43 54 $can_edit = PhabricatorPolicyFilter::hasCapability( 44 55 $viewer, ··· 49 60 pht('You can not query orders for a merchant you do not control.')); 50 61 } 51 62 $query->withMerchantPHIDs(array($merchant->getPHID())); 63 + } else if ($account) { 64 + $can_edit = PhabricatorPolicyFilter::hasCapability( 65 + $viewer, 66 + $account, 67 + PhabricatorPolicyCapability::CAN_EDIT); 68 + if (!$can_edit) { 69 + throw new Exception( 70 + pht( 71 + 'You can not query orders for an account you are not '. 72 + 'a member of.')); 73 + } 74 + $query->withAccountPHIDs(array($account->getPHID())); 52 75 } else { 53 76 $accounts = id(new PhortuneAccountQuery()) 54 - ->withMemberPHIDs($viewer->getPHID()) 77 + ->withMemberPHIDs(array($viewer->getPHID())) 55 78 ->execute(); 56 79 if ($accounts) { 57 80 $query->withAccountPHIDs(mpull($accounts, 'getPHID')); ··· 69 92 70 93 protected function getURI($path) { 71 94 $merchant = $this->getMerchant(); 95 + $account = $this->getAccount(); 72 96 if ($merchant) { 73 97 return '/phortune/merchant/'.$merchant->getID().'/order/'.$path; 98 + } else if ($account) { 99 + return '/phortune/'.$account->getID().'/order/'; 74 100 } else { 75 101 return '/phortune/order/'.$path; 76 102 }
+125
src/applications/phortune/query/PhortuneChargeSearchEngine.php
··· 1 + <?php 2 + 3 + final class PhortuneChargeSearchEngine 4 + extends PhabricatorApplicationSearchEngine { 5 + 6 + private $account; 7 + 8 + public function setAccount(PhortuneAccount $account) { 9 + $this->account = $account; 10 + return $this; 11 + } 12 + 13 + public function getAccount() { 14 + return $this->account; 15 + } 16 + 17 + public function getResultTypeDescription() { 18 + return pht('Phortune Charges'); 19 + } 20 + 21 + public function buildSavedQueryFromRequest(AphrontRequest $request) { 22 + $saved = new PhabricatorSavedQuery(); 23 + 24 + return $saved; 25 + } 26 + 27 + public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 28 + $query = id(new PhortuneChargeQuery()); 29 + 30 + $viewer = $this->requireViewer(); 31 + 32 + $account = $this->getAccount(); 33 + if ($account) { 34 + $can_edit = PhabricatorPolicyFilter::hasCapability( 35 + $viewer, 36 + $account, 37 + PhabricatorPolicyCapability::CAN_EDIT); 38 + if (!$can_edit) { 39 + throw new Exception( 40 + pht( 41 + 'You can not query charges for an account you are not '. 42 + 'a member of.')); 43 + } 44 + $query->withAccountPHIDs(array($account->getPHID())); 45 + } else { 46 + $accounts = id(new PhortuneAccountQuery()) 47 + ->withMemberPHIDs(array($viewer->getPHID())) 48 + ->execute(); 49 + if ($accounts) { 50 + $query->withAccountPHIDs(mpull($accounts, 'getPHID')); 51 + } else { 52 + throw new Exception(pht('You have no accounts!')); 53 + } 54 + } 55 + 56 + return $query; 57 + } 58 + 59 + public function buildSearchForm( 60 + AphrontFormView $form, 61 + PhabricatorSavedQuery $saved_query) {} 62 + 63 + protected function getURI($path) { 64 + $account = $this->getAccount(); 65 + if ($account) { 66 + return '/phortune/'.$account->getID().'/charge/'; 67 + } else { 68 + return '/phortune/charge/'.$path; 69 + } 70 + } 71 + 72 + public function getBuiltinQueryNames() { 73 + $names = array( 74 + 'all' => pht('All Charges'), 75 + ); 76 + 77 + return $names; 78 + } 79 + 80 + public function buildSavedQueryFromBuiltin($query_key) { 81 + 82 + $query = $this->newSavedQuery(); 83 + $query->setQueryKey($query_key); 84 + 85 + switch ($query_key) { 86 + case 'all': 87 + return $query; 88 + } 89 + 90 + return parent::buildSavedQueryFromBuiltin($query_key); 91 + } 92 + 93 + protected function getRequiredHandlePHIDsForResultList( 94 + array $charges, 95 + PhabricatorSavedQuery $query) { 96 + 97 + $phids = array(); 98 + foreach ($charges as $charge) { 99 + $phids[] = $charge->getProviderPHID(); 100 + $phids[] = $charge->getCartPHID(); 101 + $phids[] = $charge->getMerchantPHID(); 102 + $phids[] = $charge->getPaymentMethodPHID(); 103 + } 104 + 105 + return $phids; 106 + } 107 + 108 + protected function renderResultList( 109 + array $charges, 110 + PhabricatorSavedQuery $query, 111 + array $handles) { 112 + assert_instances_of($charges, 'PhortuneCharge'); 113 + 114 + $viewer = $this->requireViewer(); 115 + 116 + $table = id(new PhortuneChargeTableView()) 117 + ->setUser($viewer) 118 + ->setCharges($charges) 119 + ->setHandles($handles); 120 + 121 + return id(new PHUIObjectBoxView()) 122 + ->setHeaderText(pht('Charges')) 123 + ->appendChild($table); 124 + } 125 + }
+89
src/applications/phortune/view/PhortuneChargeTableView.php
··· 1 + <?php 2 + 3 + final class PhortuneChargeTableView extends AphrontView { 4 + 5 + private $charges; 6 + private $handles; 7 + private $showOrder; 8 + 9 + public function setShowOrder($show_order) { 10 + $this->showOrder = $show_order; 11 + return $this; 12 + } 13 + 14 + public function getShowOrder() { 15 + return $this->showOrder; 16 + } 17 + 18 + public function setHandles(array $handles) { 19 + $this->handles = $handles; 20 + return $this; 21 + } 22 + 23 + public function getHandles() { 24 + return $this->handles; 25 + } 26 + 27 + public function setCharges(array $charges) { 28 + $this->charges = $charges; 29 + return $this; 30 + } 31 + 32 + public function getCharges() { 33 + return $this->charges; 34 + } 35 + 36 + public function render() { 37 + $charges = $this->getCharges(); 38 + $handles = $this->getHandles(); 39 + $viewer = $this->getUser(); 40 + 41 + $rows = array(); 42 + foreach ($charges as $charge) { 43 + $rows[] = array( 44 + $charge->getID(), 45 + $handles[$charge->getCartPHID()]->renderLink(), 46 + $handles[$charge->getProviderPHID()]->renderLink(), 47 + $charge->getPaymentMethodPHID() 48 + ? $handles[$charge->getPaymentMethodPHID()]->renderLink() 49 + : null, 50 + $handles[$charge->getMerchantPHID()]->renderLink(), 51 + $charge->getAmountAsCurrency()->formatForDisplay(), 52 + $charge->getStatusForDisplay(), 53 + phabricator_datetime($charge->getDateCreated(), $viewer), 54 + ); 55 + } 56 + 57 + $table = id(new AphrontTableView($rows)) 58 + ->setHeaders( 59 + array( 60 + pht('ID'), 61 + pht('Cart'), 62 + pht('Provider'), 63 + pht('Method'), 64 + pht('Merchant'), 65 + pht('Amount'), 66 + pht('Status'), 67 + pht('Created'), 68 + )) 69 + ->setColumnClasses( 70 + array( 71 + '', 72 + '', 73 + '', 74 + '', 75 + '', 76 + 'wide right', 77 + '', 78 + '', 79 + )) 80 + ->setColumnVisibility( 81 + array( 82 + true, 83 + $this->getShowOrder(), 84 + )); 85 + 86 + return $table; 87 + } 88 + 89 + }
+100
src/applications/phortune/view/PhortuneOrderTableView.php
··· 1 + <?php 2 + 3 + final class PhortuneOrderTableView extends AphrontView { 4 + 5 + private $carts; 6 + private $handles; 7 + 8 + public function setHandles(array $handles) { 9 + $this->handles = $handles; 10 + return $this; 11 + } 12 + 13 + public function getHandles() { 14 + return $this->handles; 15 + } 16 + 17 + public function setCarts(array $carts) { 18 + $this->carts = $carts; 19 + return $this; 20 + } 21 + 22 + public function getCarts() { 23 + return $this->carts; 24 + } 25 + 26 + public function render() { 27 + $carts = $this->getCarts(); 28 + $handles = $this->getHandles(); 29 + $viewer = $this->getUser(); 30 + 31 + $rows = array(); 32 + $rowc = array(); 33 + foreach ($carts as $cart) { 34 + $cart_link = $handles[$cart->getPHID()]->renderLink(); 35 + $purchases = $cart->getPurchases(); 36 + 37 + if (count($purchases) == 1) { 38 + $purchase = head($purchases); 39 + $purchase_name = $handles[$purchase->getPHID()]->renderLink(); 40 + $purchases = array(); 41 + } else { 42 + $purchase_name = ''; 43 + } 44 + 45 + $rowc[] = ''; 46 + $rows[] = array( 47 + $cart->getID(), 48 + phutil_tag( 49 + 'strong', 50 + array(), 51 + $cart_link), 52 + $purchase_name, 53 + phutil_tag( 54 + 'strong', 55 + array(), 56 + $cart->getTotalPriceAsCurrency()->formatForDisplay()), 57 + PhortuneCart::getNameForStatus($cart->getStatus()), 58 + phabricator_datetime($cart->getDateModified(), $viewer), 59 + ); 60 + foreach ($purchases as $purchase) { 61 + $id = $purchase->getID(); 62 + 63 + $price = $purchase->getTotalPriceAsCurrency()->formatForDisplay(); 64 + 65 + $rowc[] = ''; 66 + $rows[] = array( 67 + '', 68 + $handles[$purchase->getPHID()]->renderLink(), 69 + $price, 70 + '', 71 + '', 72 + ); 73 + } 74 + } 75 + 76 + $table = id(new AphrontTableView($rows)) 77 + ->setRowClasses($rowc) 78 + ->setHeaders( 79 + array( 80 + pht('ID'), 81 + pht('Order'), 82 + pht('Purchase'), 83 + pht('Amount'), 84 + pht('Status'), 85 + pht('Updated'), 86 + )) 87 + ->setColumnClasses( 88 + array( 89 + '', 90 + '', 91 + 'wide', 92 + 'right', 93 + '', 94 + 'right', 95 + )); 96 + 97 + return $table; 98 + } 99 + 100 + }