Page MenuHomePhabricator

D11576.id27867.diff
No OneTemporary

D11576.id27867.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -2815,6 +2815,7 @@
'PhortuneSubscriptionQuery' => 'applications/phortune/query/PhortuneSubscriptionQuery.php',
'PhortuneSubscriptionSearchEngine' => 'applications/phortune/query/PhortuneSubscriptionSearchEngine.php',
'PhortuneSubscriptionTableView' => 'applications/phortune/view/PhortuneSubscriptionTableView.php',
+ 'PhortuneSubscriptionViewController' => 'applications/phortune/controller/PhortuneSubscriptionViewController.php',
'PhortuneTestPaymentProvider' => 'applications/phortune/provider/PhortuneTestPaymentProvider.php',
'PhortuneWePayPaymentProvider' => 'applications/phortune/provider/PhortuneWePayPaymentProvider.php',
'PhragmentBrowseController' => 'applications/phragment/controller/PhragmentBrowseController.php',
@@ -6168,6 +6169,7 @@
'PhortuneSubscriptionQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhortuneSubscriptionSearchEngine' => 'PhabricatorApplicationSearchEngine',
'PhortuneSubscriptionTableView' => 'AphrontView',
+ 'PhortuneSubscriptionViewController' => 'PhortuneController',
'PhortuneTestPaymentProvider' => 'PhortunePaymentProvider',
'PhortuneWePayPaymentProvider' => 'PhortunePaymentProvider',
'PhragmentBrowseController' => 'PhragmentController',
diff --git a/src/applications/phortune/application/PhabricatorPhortuneApplication.php b/src/applications/phortune/application/PhabricatorPhortuneApplication.php
--- a/src/applications/phortune/application/PhabricatorPhortuneApplication.php
+++ b/src/applications/phortune/application/PhabricatorPhortuneApplication.php
@@ -23,7 +23,7 @@
}
public function getTitleGlyph() {
- return "\xE2\x9C\x98";
+ return "\xE2\x97\x87";
}
public function getApplicationGroup() {
@@ -45,8 +45,12 @@
),
'order/(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhortuneCartListController',
- 'subscription/(?:query/(?P<queryKey>[^/]+)/)?'
- => 'PhortuneSubscriptionListController',
+ 'subscription/' => array(
+ '(?:query/(?P<queryKey>[^/]+)/)?'
+ => 'PhortuneSubscriptionListController',
+ 'view/(?P<id>\d+)/'
+ => 'PhortuneSubscriptionViewController',
+ ),
'charge/(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhortuneChargeListController',
),
@@ -81,8 +85,12 @@
'edit/(?:(?P<id>\d+)/)?' => 'PhortuneMerchantEditController',
'orders/(?P<merchantID>\d+)/(?:query/(?P<queryKey>[^/]+)/)?'
=> 'PhortuneCartListController',
- 'subscription/(?P<merchantID>\d+)/(?:query/(?P<queryKey>[^/]+)/)?'
- => 'PhortuneSubscriptionListController',
+ '(?P<merchantID>\d+)/subscription/' => array(
+ '(?:query/(?P<queryKey>[^/]+)/)?'
+ => 'PhortuneSubscriptionListController',
+ 'view/(?P<id>\d+)/'
+ => 'PhortuneSubscriptionViewController',
+ ),
'(?P<id>\d+)/' => 'PhortuneMerchantViewController',
),
),
diff --git a/src/applications/phortune/controller/PhortuneAccountViewController.php b/src/applications/phortune/controller/PhortuneAccountViewController.php
--- a/src/applications/phortune/controller/PhortuneAccountViewController.php
+++ b/src/applications/phortune/controller/PhortuneAccountViewController.php
@@ -35,9 +35,7 @@
$title = $account->getName();
$crumbs = $this->buildApplicationCrumbs();
- $crumbs->addTextCrumb(
- $account->getName(),
- $request->getRequestURI());
+ $this->addAccountCrumb($crumbs, $account, $link = false);
$header = id(new PHUIHeaderView())
->setHeader($title);
diff --git a/src/applications/phortune/controller/PhortuneController.php b/src/applications/phortune/controller/PhortuneController.php
--- a/src/applications/phortune/controller/PhortuneController.php
+++ b/src/applications/phortune/controller/PhortuneController.php
@@ -7,7 +7,7 @@
PhortuneAccount $account,
$link = true) {
- $name = pht('Account');
+ $name = $account->getName();
$href = null;
if ($link) {
@@ -18,6 +18,26 @@
}
}
+ protected function addMerchantCrumb(
+ $crumbs,
+ PhortuneMerchant $merchant,
+ $link = true) {
+
+ $name = $merchant->getName();
+ $href = null;
+
+ $crumbs->addTextCrumb(
+ pht('Merchants'),
+ $this->getApplicationURI('merchant/'));
+
+ if ($link) {
+ $href = $this->getApplicationURI('merchant/'.$merchant->getID().'/');
+ $crumbs->addTextCrumb($name, $href);
+ } else {
+ $crumbs->addTextCrumb($name);
+ }
+ }
+
private function loadEnabledProvidersForMerchant(PhortuneMerchant $merchant) {
$viewer = $this->getRequest()->getUser();
diff --git a/src/applications/phortune/controller/PhortuneMerchantViewController.php b/src/applications/phortune/controller/PhortuneMerchantViewController.php
--- a/src/applications/phortune/controller/PhortuneMerchantViewController.php
+++ b/src/applications/phortune/controller/PhortuneMerchantViewController.php
@@ -190,7 +190,7 @@
id(new PhabricatorActionView())
->setName(pht('View Subscriptions'))
->setIcon('fa-moon-o')
- ->setHref($this->getApplicationURI("merchant/subscription/{$id}/"))
+ ->setHref($this->getApplicationURI("merchant/{$id}/subscription/"))
->setDisabled(!$can_edit)
->setWorkflow(!$can_edit));
diff --git a/src/applications/phortune/controller/PhortuneSubscriptionListController.php b/src/applications/phortune/controller/PhortuneSubscriptionListController.php
--- a/src/applications/phortune/controller/PhortuneSubscriptionListController.php
+++ b/src/applications/phortune/controller/PhortuneSubscriptionListController.php
@@ -85,9 +85,7 @@
$merchant = $this->merchant;
if ($merchant) {
$id = $merchant->getID();
- $crumbs->addTextCrumb(
- $merchant->getName(),
- $this->getApplicationURI("merchant/{$id}/"));
+ $this->addMerchantCrumb($crumbs, $merchant);
$crumbs->addTextCrumb(
pht('Subscriptions'),
$this->getApplicationURI("merchant/subscriptions/{$id}/"));
@@ -96,9 +94,7 @@
$account = $this->account;
if ($account) {
$id = $account->getID();
- $crumbs->addTextCrumb(
- $account->getName(),
- $this->getApplicationURI("{$id}/"));
+ $this->addAccountCrumb($crumbs, $account);
$crumbs->addTextCrumb(
pht('Subscriptions'),
$this->getApplicationURI("{$id}/subscription/"));
diff --git a/src/applications/phortune/controller/PhortuneSubscriptionViewController.php b/src/applications/phortune/controller/PhortuneSubscriptionViewController.php
new file mode 100644
--- /dev/null
+++ b/src/applications/phortune/controller/PhortuneSubscriptionViewController.php
@@ -0,0 +1,59 @@
+<?php
+
+final class PhortuneSubscriptionViewController extends PhortuneController {
+
+ public function handleRequest(AphrontRequest $request) {
+ $viewer = $this->getViewer();
+
+ $subscription = id(new PhortuneSubscriptionQuery())
+ ->setViewer($viewer)
+ ->withIDs(array($request->getURIData('id')))
+ ->needTriggers(true)
+ ->executeOne();
+ if (!$subscription) {
+ return new Aphront404Response();
+ }
+
+ $is_merchant = (bool)$request->getURIData('merchantID');
+
+ $title = pht('Subscription: %s', $subscription->getSubscriptionName());
+
+ $header = id(new PHUIHeaderView())
+ ->setHeader($subscription->getSubscriptionName());
+
+ $actions = id(new PhabricatorActionListView())
+ ->setUser($viewer)
+ ->setObjectURI($request->getRequestURI());
+
+ $crumbs = $this->buildApplicationCrumbs();
+ if ($is_merchant) {
+ $this->addMerchantCrumb($crumbs, $subscription->getMerchant());
+ } else {
+ $this->addAccountCrumb($crumbs, $subscription->getAccount());
+ }
+ $crumbs->addTextCrumb(pht('Subscription %d', $subscription->getID()));
+
+ $properties = id(new PHUIPropertyListView())
+ ->setUser($viewer)
+ ->setActionList($actions);
+
+ $next_invoice = $subscription->getTrigger()->getNextEventPrediction();
+ $properties->addProperty(
+ pht('Next Invoice'),
+ phabricator_datetime($next_invoice, $viewer));
+
+ $object_box = id(new PHUIObjectBoxView())
+ ->setHeader($header)
+ ->addPropertyList($properties);
+
+ return $this->buildApplicationPage(
+ array(
+ $crumbs,
+ $object_box,
+ ),
+ array(
+ 'title' => $title,
+ ));
+ }
+
+}
diff --git a/src/applications/phortune/query/PhortuneSubscriptionQuery.php b/src/applications/phortune/query/PhortuneSubscriptionQuery.php
--- a/src/applications/phortune/query/PhortuneSubscriptionQuery.php
+++ b/src/applications/phortune/query/PhortuneSubscriptionQuery.php
@@ -9,6 +9,8 @@
private $merchantPHIDs;
private $statuses;
+ private $needTriggers;
+
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
@@ -34,6 +36,11 @@
return $this;
}
+ public function needTriggers($need_triggers) {
+ $this->needTriggers = $need_triggers;
+ return $this;
+ }
+
protected function loadPage() {
$table = new PhortuneSubscription();
$conn = $table->establishConnection('r');
@@ -102,6 +109,24 @@
$subscription->attachImplementation($implementation);
}
+ if ($this->needTriggers) {
+ $trigger_phids = mpull($subscriptions, 'getTriggerPHID');
+ $triggers = id(new PhabricatorWorkerTriggerQuery())
+ ->setViewer($this->getViewer())
+ ->withPHIDs($trigger_phids)
+ ->needEvents(true)
+ ->execute();
+ $triggers = mpull($triggers, null, 'getPHID');
+ foreach ($subscriptions as $key => $subscription) {
+ $trigger = idx($triggers, $subscription->getTriggerPHID());
+ if (!$trigger) {
+ unset($subscriptions[$key]);
+ continue;
+ }
+ $subscription->attachTrigger($trigger);
+ }
+ }
+
return $subscriptions;
}
diff --git a/src/applications/phortune/query/PhortuneSubscriptionSearchEngine.php b/src/applications/phortune/query/PhortuneSubscriptionSearchEngine.php
--- a/src/applications/phortune/query/PhortuneSubscriptionSearchEngine.php
+++ b/src/applications/phortune/query/PhortuneSubscriptionSearchEngine.php
@@ -144,6 +144,7 @@
$merchant = $this->getMerchant();
if ($merchant) {
$header = pht('Subscriptions for %s', $merchant->getName());
+ $table->setIsMerchantView(true);
} else {
$header = pht('Your Subscriptions');
}
diff --git a/src/applications/phortune/storage/PhortuneAccount.php b/src/applications/phortune/storage/PhortuneAccount.php
--- a/src/applications/phortune/storage/PhortuneAccount.php
+++ b/src/applications/phortune/storage/PhortuneAccount.php
@@ -32,7 +32,7 @@
$xactions = array();
$xactions[] = id(new PhortuneAccountTransaction())
->setTransactionType(PhortuneAccountTransaction::TYPE_NAME)
- ->setNewValue(pht('Personal Account'));
+ ->setNewValue(pht('Default Account'));
$xactions[] = id(new PhortuneAccountTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
diff --git a/src/applications/phortune/storage/PhortuneSubscription.php b/src/applications/phortune/storage/PhortuneSubscription.php
--- a/src/applications/phortune/storage/PhortuneSubscription.php
+++ b/src/applications/phortune/storage/PhortuneSubscription.php
@@ -153,6 +153,7 @@
),
));
+ $trigger->setPHID($trigger_phid);
$trigger->setAction($trigger_action);
$trigger->save();
}
@@ -165,6 +166,19 @@
return $this->getImplementation()->getName($this);
}
+ public function getURI() {
+ $account_id = $this->getAccount()->getID();
+ $id = $this->getID();
+
+ return "/phortune/{$account_id}/subscription/view/{$id}/";
+ }
+
+ public function getMerchantURI() {
+ $merchant_id = $this->getMerchant()->getID();
+ $id = $this->getID();
+ return "/phortune/merchant/{$merchant_id}/subscription/view/{$id}/";
+ }
+
/* -( PhabricatorPolicyInterface )----------------------------------------- */
diff --git a/src/applications/phortune/view/PhortuneSubscriptionTableView.php b/src/applications/phortune/view/PhortuneSubscriptionTableView.php
--- a/src/applications/phortune/view/PhortuneSubscriptionTableView.php
+++ b/src/applications/phortune/view/PhortuneSubscriptionTableView.php
@@ -4,6 +4,7 @@
private $subscriptions;
private $handles;
+ private $isMerchantView;
public function setHandles(array $handles) {
$this->handles = $handles;
@@ -23,6 +24,15 @@
return $this->subscriptions;
}
+ public function setIsMerchantView($is_merchant_view) {
+ $this->isMerchantView = $is_merchant_view;
+ return $this;
+ }
+
+ public function getIsMerchantView() {
+ return $this->isMerchantView;
+ }
+
public function render() {
$subscriptions = $this->getSubscriptions();
$handles = $this->getHandles();
@@ -31,9 +41,21 @@
$rows = array();
$rowc = array();
foreach ($subscriptions as $subscription) {
+ if ($this->getIsMerchantView()) {
+ $uri = $subscription->getMerchantURI();
+ } else {
+ $uri = $subscription->getURI();
+ }
+
$subscription_link = $handles[$subscription->getPHID()]->renderLink();
$rows[] = array(
$subscription->getID(),
+ phutil_tag(
+ 'a',
+ array(
+ 'href' => $uri,
+ ),
+ $subscription->getSubscriptionName()),
phabricator_datetime($subscription->getDateCreated(), $viewer),
);
}
@@ -42,11 +64,13 @@
->setHeaders(
array(
pht('ID'),
+ pht('Name'),
pht('Created'),
))
->setColumnClasses(
array(
'',
+ 'wide',
'right',
));

File Metadata

Mime Type
text/plain
Expires
Sat, Dec 21, 6:48 PM (15 h, 45 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6915325
Default Alt Text
D11576.id27867.diff (13 KB)

Event Timeline