@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
at recaptime-dev/main 198 lines 4.8 kB view raw
1<?php 2 3final class PhortuneOrderTableView extends AphrontView { 4 5 private $carts; 6 private $noDataString; 7 private $isInvoices; 8 private $isMerchantView; 9 private $accountEmail; 10 11 public function setCarts(array $carts) { 12 $this->carts = $carts; 13 return $this; 14 } 15 16 public function getCarts() { 17 return $this->carts; 18 } 19 20 public function setIsInvoices($is_invoices) { 21 $this->isInvoices = $is_invoices; 22 return $this; 23 } 24 25 public function getIsInvoices() { 26 return $this->isInvoices; 27 } 28 29 public function setNoDataString($no_data_string) { 30 $this->noDataString = $no_data_string; 31 return $this; 32 } 33 34 public function getNoDataString() { 35 return $this->noDataString; 36 } 37 38 public function setIsMerchantView($is_merchant_view) { 39 $this->isMerchantView = $is_merchant_view; 40 return $this; 41 } 42 43 public function getIsMerchantView() { 44 return $this->isMerchantView; 45 } 46 47 public function setAccountEmail(PhortuneAccountEmail $account_email) { 48 $this->accountEmail = $account_email; 49 return $this; 50 } 51 52 public function getAccountEmail() { 53 return $this->accountEmail; 54 } 55 56 public function render() { 57 $carts = $this->getCarts(); 58 $viewer = $this->getUser(); 59 60 $is_invoices = $this->getIsInvoices(); 61 $is_merchant = $this->getIsMerchantView(); 62 $is_external = (bool)$this->getAccountEmail(); 63 64 $email = $this->getAccountEmail(); 65 66 $phids = array(); 67 foreach ($carts as $cart) { 68 $phids[] = $cart->getPHID(); 69 foreach ($cart->getPurchases() as $purchase) { 70 $phids[] = $purchase->getPHID(); 71 } 72 $phids[] = $cart->getMerchantPHID(); 73 } 74 75 $handles = $viewer->loadHandles($phids); 76 77 $rows = array(); 78 $rowc = array(); 79 foreach ($carts as $cart) { 80 if ($is_external) { 81 $cart_link = phutil_tag( 82 'a', 83 array( 84 'href' => $email->getExternalOrderURI($cart), 85 ), 86 $handles[$cart->getPHID()]->getName()); 87 } else { 88 $cart_link = $handles[$cart->getPHID()]->renderLink(); 89 } 90 $purchases = $cart->getPurchases(); 91 92 if (count($purchases) == 1) { 93 $purchase = head($purchases); 94 $purchase_name = $handles[$purchase->getPHID()]->getName(); 95 $purchases = array(); 96 } else { 97 $purchase_name = ''; 98 } 99 100 if ($is_invoices) { 101 if ($is_external) { 102 $merchant_link = $handles[$cart->getMerchantPHID()]->getName(); 103 } else { 104 $merchant_link = $handles[$cart->getMerchantPHID()]->renderLink(); 105 } 106 } else { 107 $merchant_link = null; 108 } 109 110 $rowc[] = ''; 111 $rows[] = array( 112 $cart->getID(), 113 $merchant_link, 114 phutil_tag( 115 'strong', 116 array(), 117 $cart_link), 118 $purchase_name, 119 phutil_tag( 120 'strong', 121 array(), 122 $cart->getTotalPriceAsCurrency()->formatForDisplay()), 123 PhortuneCart::getNameForStatus($cart->getStatus()), 124 phabricator_datetime($cart->getDateModified(), $viewer), 125 phabricator_datetime($cart->getDateCreated(), $viewer), 126 id(new PHUIButtonView()) 127 ->setTag('a') 128 ->setColor('green') 129 ->setHref($cart->getCheckoutURI()) 130 ->setText(pht('Pay Now')) 131 ->setIcon('fa-credit-card'), 132 ); 133 foreach ($purchases as $purchase) { 134 $id = $purchase->getID(); 135 136 $price = $purchase->getTotalPriceAsCurrency()->formatForDisplay(); 137 138 $rowc[] = ''; 139 $rows[] = array( 140 '', 141 '', 142 $handles[$purchase->getPHID()]->renderLink(), 143 $price, 144 '', 145 '', 146 '', 147 '', 148 ); 149 } 150 } 151 152 $table = id(new AphrontTableView($rows)) 153 ->setNoDataString($this->getNoDataString()) 154 ->setRowClasses($rowc) 155 ->setHeaders( 156 array( 157 pht('ID'), 158 pht('Merchant'), 159 $is_invoices ? pht('Invoice') : pht('Order'), 160 pht('Purchase'), 161 pht('Amount'), 162 pht('Status'), 163 pht('Updated'), 164 pht('Invoice Date'), 165 null, 166 )) 167 ->setColumnClasses( 168 array( 169 '', 170 '', 171 '', 172 'wide', 173 'right', 174 '', 175 'right', 176 'right', 177 'action', 178 )) 179 ->setColumnVisibility( 180 array( 181 true, 182 $is_invoices, 183 true, 184 true, 185 true, 186 !$is_invoices, 187 !$is_invoices, 188 $is_invoices, 189 190 // We show "Pay Now" for due invoices, but not if the viewer is the 191 // merchant, since it doesn't make sense for them to pay. 192 ($is_invoices && !$is_merchant && !$is_external), 193 )); 194 195 return $table; 196 } 197 198}