[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/phortune/query/ -> PhortuneChargeSearchEngine.php (source)

   1  <?php
   2  
   3  final class PhortuneChargeSearchEngine
   4    extends PhabricatorApplicationSearchEngine {
   5  
   6    private $account;
   7  
   8    public function setAccount(PhortuneAccount $account) {
   9      $this->account = $account;
  10      return $this;
  11    }
  12  
  13    public function getAccount() {
  14      return $this->account;
  15    }
  16  
  17    public function getResultTypeDescription() {
  18      return pht('Phortune Charges');
  19    }
  20  
  21    public function buildSavedQueryFromRequest(AphrontRequest $request) {
  22      $saved = new PhabricatorSavedQuery();
  23  
  24      return $saved;
  25    }
  26  
  27    public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
  28      $query = id(new PhortuneChargeQuery());
  29  
  30      $viewer = $this->requireViewer();
  31  
  32      $account = $this->getAccount();
  33      if ($account) {
  34        $can_edit = PhabricatorPolicyFilter::hasCapability(
  35          $viewer,
  36          $account,
  37          PhabricatorPolicyCapability::CAN_EDIT);
  38        if (!$can_edit) {
  39          throw new Exception(
  40            pht(
  41              'You can not query charges for an account you are not '.
  42              'a member of.'));
  43        }
  44        $query->withAccountPHIDs(array($account->getPHID()));
  45      } else {
  46        $accounts = id(new PhortuneAccountQuery())
  47          ->withMemberPHIDs(array($viewer->getPHID()))
  48          ->execute();
  49        if ($accounts) {
  50          $query->withAccountPHIDs(mpull($accounts, 'getPHID'));
  51        } else {
  52          throw new Exception(pht('You have no accounts!'));
  53        }
  54      }
  55  
  56      return $query;
  57    }
  58  
  59    public function buildSearchForm(
  60      AphrontFormView $form,
  61      PhabricatorSavedQuery $saved_query) {}
  62  
  63    protected function getURI($path) {
  64      $account = $this->getAccount();
  65      if ($account) {
  66        return '/phortune/'.$account->getID().'/charge/';
  67      } else {
  68        return '/phortune/charge/'.$path;
  69      }
  70    }
  71  
  72    public function getBuiltinQueryNames() {
  73      $names = array(
  74        'all' => pht('All Charges'),
  75      );
  76  
  77      return $names;
  78    }
  79  
  80    public function buildSavedQueryFromBuiltin($query_key) {
  81  
  82      $query = $this->newSavedQuery();
  83      $query->setQueryKey($query_key);
  84  
  85      switch ($query_key) {
  86        case 'all':
  87          return $query;
  88      }
  89  
  90      return parent::buildSavedQueryFromBuiltin($query_key);
  91    }
  92  
  93    protected function getRequiredHandlePHIDsForResultList(
  94      array $charges,
  95      PhabricatorSavedQuery $query) {
  96  
  97      $phids = array();
  98      foreach ($charges as $charge) {
  99        $phids[] = $charge->getProviderPHID();
 100        $phids[] = $charge->getCartPHID();
 101        $phids[] = $charge->getMerchantPHID();
 102        $phids[] = $charge->getPaymentMethodPHID();
 103      }
 104  
 105      return $phids;
 106    }
 107  
 108    protected function renderResultList(
 109      array $charges,
 110      PhabricatorSavedQuery $query,
 111      array $handles) {
 112      assert_instances_of($charges, 'PhortuneCharge');
 113  
 114      $viewer = $this->requireViewer();
 115  
 116      $table = id(new PhortuneChargeTableView())
 117        ->setUser($viewer)
 118        ->setCharges($charges)
 119        ->setHandles($handles);
 120  
 121      return id(new PHUIObjectBoxView())
 122        ->setHeaderText(pht('Charges'))
 123        ->appendChild($table);
 124    }
 125  }


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