コード例 #1
0
 private function buildPaymentMethodsSection(PhortuneAccount $account)
 {
     $request = $this->getRequest();
     $viewer = $request->getUser();
     $can_edit = PhabricatorPolicyFilter::hasCapability($viewer, $account, PhabricatorPolicyCapability::CAN_EDIT);
     $id = $account->getID();
     $header = id(new PHUIHeaderView())->setHeader(pht('Payment Methods'))->addActionLink(id(new PHUIButtonView())->setTag('a')->setHref($this->getApplicationURI($id . '/card/new/'))->setText(pht('Add Payment Method'))->setIcon(id(new PHUIIconView())->setIconFont('fa-plus')));
     $list = id(new PHUIObjectItemListView())->setUser($viewer)->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());
         $item->setImageURI($provider->getPaymentMethodIcon());
         $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);
 }