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() {
18 public function buildSavedQueryFromRequest(AphrontRequest
$request) {
19 $saved = new PhabricatorSavedQuery();
21 $saved->setParameter('active', $request->getStr('active'));
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);
39 public function buildSearchForm(
40 AphrontFormView
$form,
41 PhabricatorSavedQuery
$saved_query) {
44 id(new AphrontFormSelectControl())
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() {
57 'active' => pht('Active'),
62 public function buildSavedQueryFromBuiltin($query_key) {
63 $query = $this->newSavedQuery();
64 $query->setQueryKey($query_key);
69 ->setParameter('active', 'active');
74 return parent
::buildSavedQueryFromBuiltin($query_key);
77 private function getActiveOptions() {
79 'all' => pht('Active and Inactive Products'),
80 'active' => pht('Active Products'),
81 'inactive' => pht('Inactive Products'),
85 private function getActiveValues() {
93 protected function renderResultList(
95 PhabricatorSavedQuery
$query,
98 assert_instances_of($products, 'ReleephProject');
99 $viewer = $this->requireViewer();
101 $list = id(new PHUIObjectItemListView())
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();
121 'href' => $repo->getURI(),
123 $repo->getMonogram()));
125 $list->addItem($item);
128 $result = new PhabricatorApplicationSearchResultView();
129 $result->setObjectList($list);