[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/countdown/query/ -> PhabricatorCountdownSearchEngine.php (source)

   1  <?php
   2  
   3  final class PhabricatorCountdownSearchEngine
   4    extends PhabricatorApplicationSearchEngine {
   5  
   6    public function getResultTypeDescription() {
   7      return pht('Countdowns');
   8    }
   9  
  10    public function getApplicationClassName() {
  11      return 'PhabricatorCountdownApplication';
  12    }
  13  
  14    public function buildSavedQueryFromRequest(AphrontRequest $request) {
  15      $saved = new PhabricatorSavedQuery();
  16      $saved->setParameter(
  17        'authorPHIDs',
  18        $this->readUsersFromRequest($request, 'authors'));
  19  
  20      $saved->setParameter('upcoming', $request->getBool('upcoming'));
  21  
  22      return $saved;
  23    }
  24  
  25    public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
  26      $query = id(new PhabricatorCountdownQuery());
  27  
  28      $author_phids = $saved->getParameter('authorPHIDs', array());
  29      if ($author_phids) {
  30        $query->withAuthorPHIDs($author_phids);
  31      }
  32  
  33      if ($saved->getParameter('upcoming')) {
  34        $query->withUpcoming(true);
  35      }
  36  
  37      return $query;
  38    }
  39  
  40    public function buildSearchForm(
  41      AphrontFormView $form,
  42      PhabricatorSavedQuery $saved_query) {
  43      $phids = $saved_query->getParameter('authorPHIDs', array());
  44      $author_handles = id(new PhabricatorHandleQuery())
  45        ->setViewer($this->requireViewer())
  46        ->withPHIDs($phids)
  47        ->execute();
  48  
  49      $upcoming = $saved_query->getParameter('upcoming');
  50  
  51      $form
  52        ->appendChild(
  53          id(new AphrontFormTokenizerControl())
  54            ->setDatasource(new PhabricatorPeopleDatasource())
  55            ->setName('authors')
  56            ->setLabel(pht('Authors'))
  57            ->setValue($author_handles))
  58        ->appendChild(
  59          id(new AphrontFormCheckboxControl())
  60            ->addCheckbox(
  61              'upcoming',
  62              1,
  63              pht('Show only countdowns that are still counting down.'),
  64              $upcoming));
  65    }
  66  
  67    protected function getURI($path) {
  68      return '/countdown/'.$path;
  69    }
  70  
  71    public function getBuiltinQueryNames() {
  72      $names = array(
  73        'upcoming' => pht('Upcoming'),
  74        'all' => pht('All'),
  75      );
  76  
  77      if ($this->requireViewer()->getPHID()) {
  78        $names['authored'] = pht('Authored');
  79      }
  80  
  81      return $names;
  82    }
  83  
  84    public function buildSavedQueryFromBuiltin($query_key) {
  85      $query = $this->newSavedQuery();
  86      $query->setQueryKey($query_key);
  87  
  88      switch ($query_key) {
  89        case 'all':
  90          return $query;
  91        case 'authored':
  92          return $query->setParameter(
  93            'authorPHIDs',
  94            array($this->requireViewer()->getPHID()));
  95        case 'upcoming':
  96          return $query->setParameter('upcoming', true);
  97      }
  98  
  99      return parent::buildSavedQueryFromBuiltin($query_key);
 100    }
 101  
 102    protected function getRequiredHandlePHIDsForResultList(
 103      array $countdowns,
 104      PhabricatorSavedQuery $query) {
 105  
 106      return mpull($countdowns, 'getAuthorPHID');
 107    }
 108  
 109    protected function renderResultList(
 110      array $countdowns,
 111      PhabricatorSavedQuery $query,
 112      array $handles) {
 113  
 114      assert_instances_of($countdowns, 'PhabricatorCountdown');
 115  
 116      $viewer = $this->requireViewer();
 117  
 118      $list = new PHUIObjectItemListView();
 119      $list->setUser($viewer);
 120      foreach ($countdowns as $countdown) {
 121        $id = $countdown->getID();
 122  
 123        $item = id(new PHUIObjectItemView())
 124          ->setObjectName("C{$id}")
 125          ->setHeader($countdown->getTitle())
 126          ->setHref($this->getApplicationURI("{$id}/"))
 127          ->addByline(
 128            pht(
 129              'Created by %s',
 130              $handles[$countdown->getAuthorPHID()]->renderLink()));
 131  
 132        $epoch = $countdown->getEpoch();
 133        if ($epoch >= time()) {
 134          $item->addIcon(
 135            'none',
 136            pht('Ends %s', phabricator_datetime($epoch, $viewer)));
 137        } else {
 138          $item->addIcon(
 139            'delete',
 140            pht('Ended %s', phabricator_datetime($epoch, $viewer)));
 141          $item->setDisabled(true);
 142        }
 143  
 144        $list->addItem($item);
 145      }
 146  
 147      return $list;
 148    }
 149  
 150  }


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