1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-16 03:42:41 +01:00
phorge-phorge/src/applications/phortune/controller/PhortuneAccountViewController.php

275 lines
7.7 KiB
PHP
Raw Normal View History

2013-03-28 17:10:34 +01:00
<?php
final class PhortuneAccountViewController extends PhortuneController {
private $accountID;
public function willProcessRequest(array $data) {
$this->accountID = $data['accountID'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
// TODO: Currently, you must be able to edit an account to view the detail
// page, because the account must be broadly visible so merchants can
// process orders but merchants should not be able to see all the details
// of an account. Ideally this page should be visible to merchants, too,
// just with less information.
$can_edit = true;
2013-03-28 17:10:34 +01:00
$account = id(new PhortuneAccountQuery())
->setViewer($user)
->withIDs(array($this->accountID))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
2013-03-28 17:10:34 +01:00
->executeOne();
if (!$account) {
return new Aphront404Response();
}
$title = $account->getName();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(
$account->getName(),
$request->getRequestURI());
2013-03-28 17:10:34 +01:00
$header = id(new PHUIHeaderView())
2013-03-28 17:10:34 +01:00
->setHeader($title);
$edit_uri = $this->getApplicationURI('account/edit/'.$account->getID().'/');
2013-03-28 17:10:34 +01:00
$actions = id(new PhabricatorActionListView())
->setUser($user)
->setObjectURI($request->getRequestURI())
2013-03-28 17:10:34 +01:00
->addAction(
id(new PhabricatorActionView())
->setName(pht('Edit Account'))
->setIcon('fa-pencil')
->setHref($edit_uri)
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
2013-03-28 17:10:34 +01:00
$properties = id(new PHUIPropertyListView())
2013-03-28 17:10:34 +01:00
->setObject($account)
->setUser($user);
$this->loadHandles($account->getMemberPHIDs());
$properties->addProperty(
pht('Members'),
$this->renderHandlesForPHIDs($account->getMemberPHIDs()));
$properties->setActionList($actions);
2013-03-28 17:10:34 +01:00
$payment_methods = $this->buildPaymentMethodsSection($account);
$purchase_history = $this->buildPurchaseHistorySection($account);
$charge_history = $this->buildChargeHistorySection($account);
Transactions - deploy buildTransactionTimeline to remaining applications Summary: Ref T4712. Specifically... - Differential - needed getApplicationTransactionViewObject() implemented - Audit - needed getApplicationTransactionViewObject() implemented - Repository - one object needed PhabricatorApplicationTransactionInterface implemented - setShouldTerminate(true) - Ponder - BONUS BUG FIX - leaving a comment on an answer had a bad redirect URI - both PonderQuestion and PonderAnswer needed PhabricatorApplicationTransactionInterface implemented - setShouldTerminate(true) on both "history" controllers - left a "TODO" on buildAnswers on the question view controller, which is non-standard and should be re-written eventually - Phortune - BONUS BUG FIX - fix new user "createNewAccount" code to not fatal - PhortuneAccount, PhortuneMerchant, and PhortuneCart needed PhabricatorApplicationTransactionInterface implemented - setShouldTerminate(true) on Account view, merchant view, and cart view controller - Fund - Legalpad - Nuance - NuanceSource needed PhabricatorApplicationTransactionInterface implemented - Releeph (this product is kind of a mess...) - HACKQUEST - had to manually create an arcanist project to even be able to make a "product" and get started...! - BONUS BUG FIX - make sure to "setName" on product edit - ReleephProject (should be ReleepProduct...?), ReleephBranch, and ReleepRequest needed PhabricatorApplicationTransactionInterface implemented - Harbormaster - HarbormasterBuildable, HarbormasterBuild, HarbormasterBuildPlan, and HarbormasterBuildStep all needed PhabricatorApplicationTransactionInterface implemented - setShouldTerminate(true) all over the place Test Plan: foreach application, viewed the timeline(s) and made sure they still rendered Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T4712 Differential Revision: https://secure.phabricator.com/D10925
2014-12-04 00:35:47 +01:00
$timeline = $this->buildTransactionTimeline(
$account,
new PhortuneAccountTransactionQuery());
$timeline->setShouldTerminate(true);
2013-03-28 17:10:34 +01:00
$object_box = id(new PHUIObjectBoxView())
->setHeader($header)
->addPropertyList($properties);
2013-03-28 17:10:34 +01:00
return $this->buildApplicationPage(
array(
$crumbs,
$object_box,
2013-03-28 17:10:34 +01:00
$payment_methods,
$purchase_history,
$charge_history,
Transactions - deploy buildTransactionTimeline to remaining applications Summary: Ref T4712. Specifically... - Differential - needed getApplicationTransactionViewObject() implemented - Audit - needed getApplicationTransactionViewObject() implemented - Repository - one object needed PhabricatorApplicationTransactionInterface implemented - setShouldTerminate(true) - Ponder - BONUS BUG FIX - leaving a comment on an answer had a bad redirect URI - both PonderQuestion and PonderAnswer needed PhabricatorApplicationTransactionInterface implemented - setShouldTerminate(true) on both "history" controllers - left a "TODO" on buildAnswers on the question view controller, which is non-standard and should be re-written eventually - Phortune - BONUS BUG FIX - fix new user "createNewAccount" code to not fatal - PhortuneAccount, PhortuneMerchant, and PhortuneCart needed PhabricatorApplicationTransactionInterface implemented - setShouldTerminate(true) on Account view, merchant view, and cart view controller - Fund - Legalpad - Nuance - NuanceSource needed PhabricatorApplicationTransactionInterface implemented - Releeph (this product is kind of a mess...) - HACKQUEST - had to manually create an arcanist project to even be able to make a "product" and get started...! - BONUS BUG FIX - make sure to "setName" on product edit - ReleephProject (should be ReleepProduct...?), ReleephBranch, and ReleepRequest needed PhabricatorApplicationTransactionInterface implemented - Harbormaster - HarbormasterBuildable, HarbormasterBuild, HarbormasterBuildPlan, and HarbormasterBuildStep all needed PhabricatorApplicationTransactionInterface implemented - setShouldTerminate(true) all over the place Test Plan: foreach application, viewed the timeline(s) and made sure they still rendered Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T4712 Differential Revision: https://secure.phabricator.com/D10925
2014-12-04 00:35:47 +01:00
$timeline,
2013-03-28 17:10:34 +01:00
),
array(
'title' => $title,
));
}
private function buildPaymentMethodsSection(PhortuneAccount $account) {
$request = $this->getRequest();
$viewer = $request->getUser();
$can_edit = PhabricatorPolicyFilter::hasCapability(
$viewer,
$account,
PhabricatorPolicyCapability::CAN_EDIT);
2013-03-28 17:10:34 +01:00
$id = $account->getID();
$header = id(new PHUIHeaderView())
->setHeader(pht('Payment Methods'));
2013-03-28 17:10:34 +01:00
$list = id(new PHUIObjectItemListView())
->setUser($viewer)
2013-03-28 17:10:34 +01:00
->setNoDataString(
pht('No payment methods associated with this account.'));
$methods = id(new PhortunePaymentMethodQuery())
->setViewer($viewer)
->withAccountPHIDs(array($account->getPHID()))
->execute();
if ($methods) {
$this->loadHandles(mpull($methods, 'getAuthorPHID'));
}
foreach ($methods as $method) {
$id = $method->getID();
$item = new PHUIObjectItemView();
$item->setHeader($method->getFullDisplayName());
switch ($method->getStatus()) {
case PhortunePaymentMethod::STATUS_ACTIVE:
$item->setBarColor('green');
$disable_uri = $this->getApplicationURI('card/'.$id.'/disable/');
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-times')
->setHref($disable_uri)
->setDisabled(!$can_edit)
->setWorkflow(true));
break;
case PhortunePaymentMethod::STATUS_DISABLED:
$item->setDisabled(true);
break;
}
$provider = $method->buildPaymentProvider();
$item->addAttribute($provider->getPaymentMethodProviderDescription());
$edit_uri = $this->getApplicationURI('card/'.$id.'/edit/');
$item->addAction(
id(new PHUIListItemView())
->setIcon('fa-pencil')
->setHref($edit_uri)
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
$list->addItem($item);
}
return id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($list);
2013-03-28 17:10:34 +01:00
}
private function buildPurchaseHistorySection(PhortuneAccount $account) {
$request = $this->getRequest();
$viewer = $request->getUser();
$carts = id(new PhortuneCartQuery())
->setViewer($viewer)
->withAccountPHIDs(array($account->getPHID()))
->needPurchases(true)
->withStatuses(
array(
PhortuneCart::STATUS_PURCHASING,
PhortuneCart::STATUS_CHARGED,
PhortuneCart::STATUS_HOLD,
PhortuneCart::STATUS_REVIEW,
PhortuneCart::STATUS_PURCHASED,
))
->setLimit(10)
->execute();
$phids = array();
foreach ($carts as $cart) {
$phids[] = $cart->getPHID();
foreach ($cart->getPurchases() as $purchase) {
$phids[] = $purchase->getPHID();
}
}
$handles = $this->loadViewerHandles($phids);
$orders_uri = $this->getApplicationURI($account->getID().'/order/');
$table = id(new PhortuneOrderTableView())
->setUser($viewer)
->setCarts($carts)
->setHandles($handles);
$header = id(new PHUIHeaderView())
->setHeader(pht('Recent Orders'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setIcon(
id(new PHUIIconView())
->setIconFont('fa-list'))
->setHref($orders_uri)
->setText(pht('View All Orders')));
return id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($table);
}
private function buildChargeHistorySection(PhortuneAccount $account) {
$request = $this->getRequest();
$viewer = $request->getUser();
$charges = id(new PhortuneChargeQuery())
->setViewer($viewer)
->withAccountPHIDs(array($account->getPHID()))
->needCarts(true)
->setLimit(10)
->execute();
$phids = array();
foreach ($charges as $charge) {
$phids[] = $charge->getProviderPHID();
$phids[] = $charge->getCartPHID();
$phids[] = $charge->getMerchantPHID();
$phids[] = $charge->getPaymentMethodPHID();
}
$handles = $this->loadViewerHandles($phids);
$charges_uri = $this->getApplicationURI($account->getID().'/charge/');
$table = id(new PhortuneChargeTableView())
->setUser($viewer)
->setCharges($charges)
->setHandles($handles);
$header = id(new PHUIHeaderView())
->setHeader(pht('Recent Charges'))
->addActionLink(
id(new PHUIButtonView())
->setTag('a')
->setIcon(
id(new PHUIIconView())
->setIconFont('fa-list'))
->setHref($charges_uri)
->setText(pht('View All Charges')));
return id(new PHUIObjectBoxView())
->setHeader($header)
->appendChild($table);
}
protected function buildApplicationCrumbs() {
$crumbs = parent::buildApplicationCrumbs();
$crumbs->addAction(
id(new PHUIListItemView())
->setIcon('fa-exchange')
->setHref($this->getApplicationURI('account/'))
->setName(pht('Switch Accounts')));
return $crumbs;
}
2013-03-28 17:10:34 +01:00
}