[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/fund/query/ -> FundBackerSearchEngine.php (source)

   1  <?php
   2  
   3  final class FundBackerSearchEngine
   4    extends PhabricatorApplicationSearchEngine {
   5  
   6    private $initiative;
   7  
   8    public function setInitiative(FundInitiative $initiative) {
   9      $this->initiative = $initiative;
  10      return $this;
  11    }
  12  
  13    public function getInitiative() {
  14      return $this->initiative;
  15    }
  16  
  17    public function getResultTypeDescription() {
  18      return pht('Fund Backers');
  19    }
  20  
  21    public function getApplicationClassName() {
  22      return 'PhabricatorFundApplication';
  23    }
  24  
  25    public function buildSavedQueryFromRequest(AphrontRequest $request) {
  26      $saved = new PhabricatorSavedQuery();
  27  
  28      $saved->setParameter(
  29        'backerPHIDs',
  30        $this->readUsersFromRequest($request, 'backers'));
  31  
  32      return $saved;
  33    }
  34  
  35    public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
  36      $query = id(new FundBackerQuery());
  37  
  38      $query->withStatuses(array(FundBacker::STATUS_PURCHASED));
  39  
  40      if ($this->getInitiative()) {
  41        $query->withInitiativePHIDs(
  42          array(
  43            $this->getInitiative()->getPHID(),
  44          ));
  45      }
  46  
  47      $backer_phids = $saved->getParameter('backerPHIDs');
  48      if ($backer_phids) {
  49        $query->withBackerPHIDs($backer_phids);
  50      }
  51  
  52      return $query;
  53    }
  54  
  55    public function buildSearchForm(
  56      AphrontFormView $form,
  57      PhabricatorSavedQuery $saved) {
  58  
  59  
  60      $backer_phids = $saved->getParameter('backerPHIDs', array());
  61  
  62      $all_phids = array_mergev(
  63        array(
  64          $backer_phids,
  65        ));
  66  
  67      $handles = id(new PhabricatorHandleQuery())
  68        ->setViewer($this->requireViewer())
  69        ->withPHIDs($all_phids)
  70        ->execute();
  71  
  72      $form
  73        ->appendChild(
  74          id(new AphrontFormTokenizerControl())
  75            ->setLabel(pht('Backers'))
  76            ->setName('backers')
  77            ->setDatasource(new PhabricatorPeopleDatasource())
  78            ->setValue(array_select_keys($handles, $backer_phids)));
  79    }
  80  
  81    protected function getURI($path) {
  82      if ($this->getInitiative()) {
  83        return '/fund/backers/'.$this->getInitiative()->getID().'/'.$path;
  84      } else {
  85        return '/fund/backers/'.$path;
  86      }
  87    }
  88  
  89    public function getBuiltinQueryNames() {
  90      $names = array();
  91      $names['all'] = pht('All Backers');
  92  
  93      return $names;
  94    }
  95  
  96    public function buildSavedQueryFromBuiltin($query_key) {
  97      $query = $this->newSavedQuery();
  98      $query->setQueryKey($query_key);
  99  
 100      switch ($query_key) {
 101        case 'all':
 102          return $query;
 103      }
 104  
 105      return parent::buildSavedQueryFromBuiltin($query_key);
 106    }
 107  
 108    protected function getRequiredHandlePHIDsForResultList(
 109      array $backers,
 110      PhabricatorSavedQuery $query) {
 111  
 112      $phids = array();
 113      foreach ($backers as $backer) {
 114        $phids[] = $backer->getBackerPHID();
 115        $phids[] = $backer->getInitiativePHID();
 116      }
 117  
 118      return $phids;
 119    }
 120  
 121    protected function renderResultList(
 122      array $backers,
 123      PhabricatorSavedQuery $query,
 124      array $handles) {
 125      assert_instances_of($backers, 'FundBacker');
 126  
 127      $viewer = $this->requireViewer();
 128  
 129      $rows = array();
 130      foreach ($backers as $backer) {
 131        $rows[] = array(
 132          $handles[$backer->getInitiativePHID()]->renderLink(),
 133          $handles[$backer->getBackerPHID()]->renderLink(),
 134          $backer->getAmountAsCurrency()->formatForDisplay(),
 135          phabricator_datetime($backer->getDateCreated(), $viewer),
 136        );
 137      }
 138  
 139      $table = id(new AphrontTableView($rows))
 140        ->setHeaders(
 141          array(
 142            pht('Initiative'),
 143            pht('Backer'),
 144            pht('Amount'),
 145            pht('Date'),
 146          ))
 147        ->setColumnClasses(
 148          array(
 149            null,
 150            null,
 151            'wide right',
 152            'right',
 153          ));
 154  
 155      return id(new PHUIObjectBoxView())
 156        ->setHeaderText(pht('Backers'))
 157        ->appendChild($table);
 158    }
 159  
 160  }


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