Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / releeph / query / ReleephProductSearchEngine.php
blobd58ee735f1ec2c916deb8a0bf315bae21db7c8a4
1 <?php
3 final class ReleephProductSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Releeph Products');
10 public function getApplicationClassName() {
11 return 'PhabricatorReleephApplication';
14 public function canUseInPanelContext() {
15 return false;
18 public function buildSavedQueryFromRequest(AphrontRequest $request) {
19 $saved = new PhabricatorSavedQuery();
21 $saved->setParameter('active', $request->getStr('active'));
23 return $saved;
26 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
27 $query = id(new ReleephProductQuery())
28 ->setOrder(ReleephProductQuery::ORDER_NAME);
30 $active = $saved->getParameter('active');
31 $value = idx($this->getActiveValues(), $active);
32 if ($value !== null) {
33 $query->withActive($value);
36 return $query;
39 public function buildSearchForm(
40 AphrontFormView $form,
41 PhabricatorSavedQuery $saved_query) {
43 $form->appendChild(
44 id(new AphrontFormSelectControl())
45 ->setName('active')
46 ->setLabel(pht('Show Products'))
47 ->setValue($saved_query->getParameter('active'))
48 ->setOptions($this->getActiveOptions()));
51 protected function getURI($path) {
52 return '/releeph/project/'.$path;
55 protected function getBuiltinQueryNames() {
56 return array(
57 'active' => pht('Active'),
58 'all' => pht('All'),
62 public function buildSavedQueryFromBuiltin($query_key) {
63 $query = $this->newSavedQuery();
64 $query->setQueryKey($query_key);
66 switch ($query_key) {
67 case 'active':
68 return $query
69 ->setParameter('active', 'active');
70 case 'all':
71 return $query;
74 return parent::buildSavedQueryFromBuiltin($query_key);
77 private function getActiveOptions() {
78 return array(
79 'all' => pht('Active and Inactive Products'),
80 'active' => pht('Active Products'),
81 'inactive' => pht('Inactive Products'),
85 private function getActiveValues() {
86 return array(
87 'all' => null,
88 'active' => 1,
89 'inactive' => 0,
93 protected function renderResultList(
94 array $products,
95 PhabricatorSavedQuery $query,
96 array $handles) {
98 assert_instances_of($products, 'ReleephProject');
99 $viewer = $this->requireViewer();
101 $list = id(new PHUIObjectItemListView())
102 ->setUser($viewer);
104 foreach ($products as $product) {
105 $id = $product->getID();
107 $item = id(new PHUIObjectItemView())
108 ->setHeader($product->getName())
109 ->setHref($this->getApplicationURI("product/{$id}/"));
111 if (!$product->getIsActive()) {
112 $item->setDisabled(true);
113 $item->addIcon('none', pht('Inactive'));
116 $repo = $product->getRepository();
117 $item->addAttribute(
118 phutil_tag(
119 'a',
120 array(
121 'href' => $repo->getURI(),
123 $repo->getMonogram()));
125 $list->addItem($item);
128 $result = new PhabricatorApplicationSearchResultView();
129 $result->setObjectList($list);
131 return $result;