@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.

at recaptime-dev/main 218 lines 5.5 kB view raw
1<?php 2 3final class PhortuneCartSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 private $merchant; 7 private $account; 8 private $subscription; 9 10 public function canUseInPanelContext() { 11 // These only make sense in an account or merchant context. 12 return false; 13 } 14 15 public function setAccount(PhortuneAccount $account) { 16 $this->account = $account; 17 return $this; 18 } 19 20 public function getAccount() { 21 return $this->account; 22 } 23 24 public function setMerchant(PhortuneMerchant $merchant) { 25 $this->merchant = $merchant; 26 return $this; 27 } 28 29 public function getMerchant() { 30 return $this->merchant; 31 } 32 33 public function setSubscription(PhortuneSubscription $subscription) { 34 $this->subscription = $subscription; 35 return $this; 36 } 37 38 public function getSubscription() { 39 return $this->subscription; 40 } 41 42 public function getResultTypeDescription() { 43 return pht('Phortune Orders'); 44 } 45 46 public function getApplicationClassName() { 47 return PhabricatorPhortuneApplication::class; 48 } 49 50 public function buildSavedQueryFromRequest(AphrontRequest $request) { 51 $saved = new PhabricatorSavedQuery(); 52 53 return $saved; 54 } 55 56 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 57 $query = id(new PhortuneCartQuery()) 58 ->needPurchases(true); 59 60 $viewer = $this->requireViewer(); 61 62 $merchant = $this->getMerchant(); 63 $account = $this->getAccount(); 64 if ($merchant) { 65 $query->withMerchantPHIDs(array($merchant->getPHID())); 66 } else if ($account) { 67 $query->withAccountPHIDs(array($account->getPHID())); 68 } else { 69 $accounts = id(new PhortuneAccountQuery()) 70 ->withMemberPHIDs(array($viewer->getPHID())) 71 ->execute(); 72 if ($accounts) { 73 $query->withAccountPHIDs(mpull($accounts, 'getPHID')); 74 } else { 75 throw new Exception(pht('You have no accounts!')); 76 } 77 } 78 79 $subscription = $this->getSubscription(); 80 if ($subscription) { 81 $query->withSubscriptionPHIDs(array($subscription->getPHID())); 82 } 83 84 if ($saved->getParameter('invoices')) { 85 $query->withInvoices(true); 86 } else { 87 $query->withStatuses( 88 array( 89 PhortuneCart::STATUS_PURCHASING, 90 PhortuneCart::STATUS_CHARGED, 91 PhortuneCart::STATUS_HOLD, 92 PhortuneCart::STATUS_REVIEW, 93 PhortuneCart::STATUS_PURCHASED, 94 )); 95 } 96 97 return $query; 98 } 99 100 public function buildSearchForm( 101 AphrontFormView $form, 102 PhabricatorSavedQuery $saved_query) {} 103 104 protected function getURI($path) { 105 $merchant = $this->getMerchant(); 106 $account = $this->getAccount(); 107 if ($merchant) { 108 return $merchant->getOrderListURI($path); 109 } else if ($account) { 110 return $account->getOrderListURI($path); 111 } else { 112 return '/phortune/order/'.$path; 113 } 114 } 115 116 protected function getBuiltinQueryNames() { 117 $names = array( 118 'all' => pht('Order History'), 119 'invoices' => pht('Unpaid Invoices'), 120 ); 121 122 return $names; 123 } 124 125 public function buildSavedQueryFromBuiltin($query_key) { 126 127 $query = $this->newSavedQuery(); 128 $query->setQueryKey($query_key); 129 130 switch ($query_key) { 131 case 'all': 132 return $query; 133 case 'invoices': 134 return $query->setParameter('invoices', true); 135 } 136 137 return parent::buildSavedQueryFromBuiltin($query_key); 138 } 139 140 protected function getRequiredHandlePHIDsForResultList( 141 array $carts, 142 PhabricatorSavedQuery $query) { 143 $phids = array(); 144 foreach ($carts as $cart) { 145 $phids[] = $cart->getPHID(); 146 $phids[] = $cart->getMerchantPHID(); 147 $phids[] = $cart->getAuthorPHID(); 148 } 149 return $phids; 150 } 151 152 protected function renderResultList( 153 array $carts, 154 PhabricatorSavedQuery $query, 155 array $handles) { 156 assert_instances_of($carts, 'PhortuneCart'); 157 158 $viewer = $this->requireViewer(); 159 160 $rows = array(); 161 foreach ($carts as $cart) { 162 $merchant = $cart->getMerchant(); 163 164 if ($this->getMerchant()) { 165 $href = $this->getApplicationURI( 166 'merchant/'.$merchant->getID().'/cart/'.$cart->getID().'/'); 167 } else { 168 $href = $cart->getDetailURI(); 169 } 170 171 $rows[] = array( 172 $cart->getID(), 173 $handles[$cart->getPHID()]->renderLink(), 174 $handles[$merchant->getPHID()]->renderLink(), 175 $handles[$cart->getAuthorPHID()]->renderLink(), 176 $cart->getTotalPriceAsCurrency()->formatForDisplay(), 177 PhortuneCart::getNameForStatus($cart->getStatus()), 178 phabricator_datetime($cart->getDateModified(), $viewer), 179 ); 180 } 181 182 $table = id(new AphrontTableView($rows)) 183 ->setNoDataString(pht('No orders match the query.')) 184 ->setHeaders( 185 array( 186 pht('ID'), 187 pht('Order'), 188 pht('Merchant'), 189 pht('Authorized By'), 190 pht('Amount'), 191 pht('Status'), 192 pht('Updated'), 193 )) 194 ->setColumnClasses( 195 array( 196 '', 197 'pri', 198 '', 199 '', 200 'wide right', 201 '', 202 'right', 203 )); 204 205 $merchant = $this->getMerchant(); 206 if ($merchant) { 207 $notice = pht('Orders for %s', $merchant->getName()); 208 } else { 209 $notice = pht('Your Orders'); 210 } 211 $table->setNotice($notice); 212 213 $result = new PhabricatorApplicationSearchResultView(); 214 $result->setTable($table); 215 216 return $result; 217 } 218}