@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 126 lines 3.3 kB view raw
1<?php 2 3final class PhortuneAccountOverviewController 4 extends PhortuneAccountProfileController { 5 6 protected function shouldRequireAccountEditCapability() { 7 return false; 8 } 9 10 protected function handleAccountRequest(AphrontRequest $request) { 11 $account = $this->getAccount(); 12 $title = $account->getName(); 13 14 $viewer = $this->getViewer(); 15 16 $invoices = id(new PhortuneCartQuery()) 17 ->setViewer($viewer) 18 ->withAccountPHIDs(array($account->getPHID())) 19 ->needPurchases(true) 20 ->withInvoices(true) 21 ->execute(); 22 23 $crumbs = $this->buildApplicationCrumbs(); 24 $crumbs->setBorder(true); 25 26 $header = $this->buildHeaderView(); 27 28 $authority = $this->newAccountAuthorityView(); 29 $status = $this->buildStatusView($account, $invoices); 30 $invoices = $this->buildInvoicesSection($account, $invoices); 31 $purchase_history = $this->newRecentOrdersView($account, 10); 32 33 $view = id(new PHUITwoColumnView()) 34 ->setHeader($header) 35 ->setFooter( 36 array( 37 $authority, 38 $status, 39 $invoices, 40 $purchase_history, 41 )); 42 43 $navigation = $this->buildSideNavView('overview'); 44 45 return $this->newPage() 46 ->setTitle($title) 47 ->setCrumbs($crumbs) 48 ->setNavigation($navigation) 49 ->appendChild($view); 50 } 51 52 private function buildStatusView(PhortuneAccount $account, $invoices) { 53 $status_items = $this->getStatusItemsForAccount($account, $invoices); 54 $view = array(); 55 foreach ($status_items as $item) { 56 $view[] = id(new PHUIInfoView()) 57 ->setSeverity(idx($item, 'severity')) 58 ->appendChild(idx($item, 'note')); 59 } 60 return $view; 61 } 62 63 private function buildInvoicesSection( 64 PhortuneAccount $account, 65 array $carts) { 66 67 $viewer = $this->getViewer(); 68 69 $table = id(new PhortuneOrderTableView()) 70 ->setNoDataString(pht('You have no unpaid invoices.')) 71 ->setIsInvoices(true) 72 ->setUser($viewer) 73 ->setCarts($carts); 74 75 $header = id(new PHUIHeaderView()) 76 ->setHeader(pht('Invoices Due')); 77 78 return id(new PHUIObjectBoxView()) 79 ->setHeader($header) 80 ->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) 81 ->setTable($table); 82 } 83 84 protected function buildApplicationCrumbs() { 85 $crumbs = parent::buildApplicationCrumbs(); 86 87 $crumbs->addAction( 88 id(new PHUIListItemView()) 89 ->setIcon('fa-exchange') 90 ->setHref($this->getApplicationURI('account/')) 91 ->setName(pht('Switch Accounts'))); 92 93 return $crumbs; 94 } 95 96 private function getStatusItemsForAccount( 97 PhortuneAccount $account, 98 array $invoices) { 99 $viewer = $this->getViewer(); 100 101 assert_instances_of($invoices, 'PhortuneCart'); 102 $items = array(); 103 104 $methods = id(new PhortunePaymentMethodQuery()) 105 ->setViewer($viewer) 106 ->withAccountPHIDs(array($account->getPHID())) 107 ->withStatuses( 108 array( 109 PhortunePaymentMethod::STATUS_ACTIVE, 110 )) 111 ->execute(); 112 113 if ($invoices) { 114 $items[] = array( 115 'severity' => PHUIInfoView::SEVERITY_ERROR, 116 'note' => pht('You have %d unpaid invoice(s).', count($invoices)), 117 ); 118 } 119 120 // TODO: If a payment method has expired or is expiring soon, we should 121 // add a status check for it. 122 123 return $items; 124 } 125 126}