Remove product literal strings in "pht()", part 18
[phabricator.git] / src / applications / phortune / view / PhortuneOrderTableView.php
blobd7868f8d491da20846b37a352df9b110cbe1ecf8
1 <?php
3 final class PhortuneOrderTableView extends AphrontView {
5 private $carts;
6 private $noDataString;
7 private $isInvoices;
8 private $isMerchantView;
9 private $accountEmail;
11 public function setCarts(array $carts) {
12 $this->carts = $carts;
13 return $this;
16 public function getCarts() {
17 return $this->carts;
20 public function setIsInvoices($is_invoices) {
21 $this->isInvoices = $is_invoices;
22 return $this;
25 public function getIsInvoices() {
26 return $this->isInvoices;
29 public function setNoDataString($no_data_string) {
30 $this->noDataString = $no_data_string;
31 return $this;
34 public function getNoDataString() {
35 return $this->noDataString;
38 public function setIsMerchantView($is_merchant_view) {
39 $this->isMerchantView = $is_merchant_view;
40 return $this;
43 public function getIsMerchantView() {
44 return $this->isMerchantView;
47 public function setAccountEmail(PhortuneAccountEmail $account_email) {
48 $this->accountEmail = $account_email;
49 return $this;
52 public function getAccountEmail() {
53 return $this->accountEmail;
56 public function render() {
57 $carts = $this->getCarts();
58 $viewer = $this->getUser();
60 $is_invoices = $this->getIsInvoices();
61 $is_merchant = $this->getIsMerchantView();
62 $is_external = (bool)$this->getAccountEmail();
64 $email = $this->getAccountEmail();
66 $phids = array();
67 foreach ($carts as $cart) {
68 $phids[] = $cart->getPHID();
69 foreach ($cart->getPurchases() as $purchase) {
70 $phids[] = $purchase->getPHID();
72 $phids[] = $cart->getMerchantPHID();
75 $handles = $viewer->loadHandles($phids);
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),
86 $handles[$cart->getPHID()]->getName());
87 } else {
88 $cart_link = $handles[$cart->getPHID()]->renderLink();
90 $purchases = $cart->getPurchases();
92 if (count($purchases) == 1) {
93 $purchase = head($purchases);
94 $purchase_name = $handles[$purchase->getPHID()]->getName();
95 $purchases = array();
96 } else {
97 $purchase_name = '';
100 if ($is_invoices) {
101 if ($is_external) {
102 $merchant_link = $handles[$cart->getMerchantPHID()]->getName();
103 } else {
104 $merchant_link = $handles[$cart->getMerchantPHID()]->renderLink();
106 } else {
107 $merchant_link = null;
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'),
133 foreach ($purchases as $purchase) {
134 $id = $purchase->getID();
136 $price = $purchase->getTotalPriceAsCurrency()->formatForDisplay();
138 $rowc[] = '';
139 $rows[] = array(
142 $handles[$purchase->getPHID()]->renderLink(),
143 $price,
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,
167 ->setColumnClasses(
168 array(
172 'wide',
173 'right',
175 'right',
176 'right',
177 'action',
179 ->setColumnVisibility(
180 array(
181 true,
182 $is_invoices,
183 true,
184 true,
185 true,
186 !$is_invoices,
187 !$is_invoices,
188 $is_invoices,
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),
195 return $table;