[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/releeph/query/ -> ReleephProductSearchEngine.php (source)

   1  <?php
   2  
   3  final class ReleephProductSearchEngine
   4    extends PhabricatorApplicationSearchEngine {
   5  
   6    public function getResultTypeDescription() {
   7      return pht('Releeph Products');
   8    }
   9  
  10    public function getApplicationClassName() {
  11      return 'PhabricatorReleephApplication';
  12    }
  13  
  14    public function buildSavedQueryFromRequest(AphrontRequest $request) {
  15      $saved = new PhabricatorSavedQuery();
  16  
  17      $saved->setParameter('active', $request->getStr('active'));
  18  
  19      return $saved;
  20    }
  21  
  22    public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
  23      $query = id(new ReleephProductQuery())
  24        ->setOrder(ReleephProductQuery::ORDER_NAME)
  25        ->needArcanistProjects(true);
  26  
  27      $active = $saved->getParameter('active');
  28      $value = idx($this->getActiveValues(), $active);
  29      if ($value !== null) {
  30        $query->withActive($value);
  31      }
  32  
  33      return $query;
  34    }
  35  
  36    public function buildSearchForm(
  37      AphrontFormView $form,
  38      PhabricatorSavedQuery $saved_query) {
  39  
  40      $form->appendChild(
  41        id(new AphrontFormSelectControl())
  42          ->setName('active')
  43          ->setLabel(pht('Show Products'))
  44          ->setValue($saved_query->getParameter('active'))
  45          ->setOptions($this->getActiveOptions()));
  46    }
  47  
  48    protected function getURI($path) {
  49      return '/releeph/project/'.$path;
  50    }
  51  
  52    public function getBuiltinQueryNames() {
  53      return array(
  54        'active' => pht('Active'),
  55        'all' => pht('All'),
  56      );
  57    }
  58  
  59    public function buildSavedQueryFromBuiltin($query_key) {
  60      $query = $this->newSavedQuery();
  61      $query->setQueryKey($query_key);
  62  
  63      switch ($query_key) {
  64        case 'active':
  65          return $query
  66            ->setParameter('active', 'active');
  67        case 'all':
  68          return $query;
  69      }
  70  
  71      return parent::buildSavedQueryFromBuiltin($query_key);
  72    }
  73  
  74    private function getActiveOptions() {
  75      return array(
  76        'all'       => pht('Active and Inactive Products'),
  77        'active'    => pht('Active Prodcuts'),
  78        'inactive'  => pht('Inactive Products'),
  79      );
  80    }
  81  
  82    private function getActiveValues() {
  83      return array(
  84        'all' => null,
  85        'active' => 1,
  86        'inactive' => 0,
  87      );
  88    }
  89  
  90    protected function renderResultList(
  91      array $products,
  92      PhabricatorSavedQuery $query,
  93      array $handles) {
  94  
  95      assert_instances_of($products, 'ReleephProject');
  96      $viewer = $this->requireViewer();
  97  
  98      $list = id(new PHUIObjectItemListView())
  99        ->setUser($viewer);
 100  
 101      foreach ($products as $product) {
 102        $id = $product->getID();
 103  
 104        $item = id(new PHUIObjectItemView())
 105          ->setHeader($product->getName())
 106          ->setHref($this->getApplicationURI("product/{$id}/"));
 107  
 108        if (!$product->getIsActive()) {
 109          $item->setDisabled(true);
 110          $item->addIcon('none', pht('Inactive'));
 111        }
 112  
 113        $repo = $product->getRepository();
 114        $item->addAttribute(
 115          phutil_tag(
 116            'a',
 117            array(
 118              'href' => '/diffusion/'.$repo->getCallsign().'/',
 119            ),
 120            'r'.$repo->getCallsign()));
 121  
 122        $arc = $product->getArcanistProject();
 123        if ($arc) {
 124          $item->addAttribute($arc->getName());
 125        }
 126  
 127        $list->addItem($item);
 128      }
 129  
 130      return $list;
 131    }
 132  
 133  }


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