[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phortune/controller/ -> PhortuneCartListController.php (source)

   1  <?php
   2  
   3  final class PhortuneCartListController
   4    extends PhortuneController {
   5  
   6    private $accountID;
   7    private $merchantID;
   8    private $queryKey;
   9  
  10    private $merchant;
  11    private $account;
  12  
  13    public function willProcessRequest(array $data) {
  14      $this->merchantID = idx($data, 'merchantID');
  15      $this->accountID = idx($data, 'accountID');
  16      $this->queryKey = idx($data, 'queryKey');
  17    }
  18  
  19    public function processRequest() {
  20      $request = $this->getRequest();
  21      $viewer = $request->getUser();
  22  
  23      $engine = new PhortuneCartSearchEngine();
  24  
  25      if ($this->merchantID) {
  26        $merchant = id(new PhortuneMerchantQuery())
  27          ->setViewer($viewer)
  28          ->withIDs(array($this->merchantID))
  29          ->requireCapabilities(
  30            array(
  31              PhabricatorPolicyCapability::CAN_VIEW,
  32              PhabricatorPolicyCapability::CAN_EDIT,
  33            ))
  34          ->executeOne();
  35        if (!$merchant) {
  36          return new Aphront404Response();
  37        }
  38        $this->merchant = $merchant;
  39        $engine->setMerchant($merchant);
  40      } else if ($this->accountID) {
  41        $account = id(new PhortuneAccountQuery())
  42          ->setViewer($viewer)
  43          ->withIDs(array($this->accountID))
  44          ->requireCapabilities(
  45            array(
  46              PhabricatorPolicyCapability::CAN_VIEW,
  47              PhabricatorPolicyCapability::CAN_EDIT,
  48            ))
  49          ->executeOne();
  50        if (!$account) {
  51          return new Aphront404Response();
  52        }
  53        $this->account = $account;
  54        $engine->setAccount($account);
  55      } else {
  56        return new Aphront404Response();
  57      }
  58  
  59      $controller = id(new PhabricatorApplicationSearchController())
  60        ->setQueryKey($this->queryKey)
  61        ->setSearchEngine($engine)
  62        ->setNavigation($this->buildSideNavView());
  63  
  64      return $this->delegateToController($controller);
  65    }
  66  
  67    public function buildSideNavView() {
  68      $viewer = $this->getRequest()->getUser();
  69  
  70      $nav = new AphrontSideNavFilterView();
  71      $nav->setBaseURI(new PhutilURI($this->getApplicationURI()));
  72  
  73      id(new PhortuneCartSearchEngine())
  74        ->setViewer($viewer)
  75        ->addNavigationItems($nav->getMenu());
  76  
  77      $nav->selectFilter(null);
  78  
  79      return $nav;
  80    }
  81  
  82    public function buildApplicationCrumbs() {
  83      $crumbs = parent::buildApplicationCrumbs();
  84  
  85      $merchant = $this->merchant;
  86      if ($merchant) {
  87        $id = $merchant->getID();
  88        $crumbs->addTextCrumb(
  89          $merchant->getName(),
  90          $this->getApplicationURI("merchant/{$id}/"));
  91        $crumbs->addTextCrumb(
  92          pht('Orders'),
  93          $this->getApplicationURI("merchant/orders/{$id}/"));
  94      }
  95  
  96      $account = $this->account;
  97      if ($account) {
  98        $id = $account->getID();
  99        $crumbs->addTextCrumb(
 100          $account->getName(),
 101          $this->getApplicationURI("{$id}/"));
 102        $crumbs->addTextCrumb(
 103          pht('Orders'),
 104          $this->getApplicationURI("{$id}/order/"));
 105      }
 106  
 107      return $crumbs;
 108    }
 109  
 110  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1