Remove product literal strings in "pht()", part 18
[phabricator.git] / src / applications / conduit / query / PhabricatorConduitSearchEngine.php
blob06ba536dfef47d20caabc06f09d145faa02710d6
1 <?php
3 final class PhabricatorConduitSearchEngine
4 extends PhabricatorApplicationSearchEngine {
6 public function getResultTypeDescription() {
7 return pht('Conduit Methods');
10 public function getApplicationClassName() {
11 return 'PhabricatorConduitApplication';
14 public function canUseInPanelContext() {
15 return false;
18 public function getPageSize(PhabricatorSavedQuery $saved) {
19 return PHP_INT_MAX - 1;
22 public function buildSavedQueryFromRequest(AphrontRequest $request) {
23 $saved = new PhabricatorSavedQuery();
25 $saved->setParameter('isStable', $request->getStr('isStable'));
26 $saved->setParameter('isUnstable', $request->getStr('isUnstable'));
27 $saved->setParameter('isDeprecated', $request->getStr('isDeprecated'));
28 $saved->setParameter('nameContains', $request->getStr('nameContains'));
30 return $saved;
33 public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
34 $query = id(new PhabricatorConduitMethodQuery());
36 $query->withIsStable($saved->getParameter('isStable'));
37 $query->withIsUnstable($saved->getParameter('isUnstable'));
38 $query->withIsDeprecated($saved->getParameter('isDeprecated'));
39 $query->withIsInternal(false);
41 $contains = $saved->getParameter('nameContains');
42 if (strlen($contains)) {
43 $query->withNameContains($contains);
46 return $query;
49 public function buildSearchForm(
50 AphrontFormView $form,
51 PhabricatorSavedQuery $saved) {
53 $form
54 ->appendChild(
55 id(new AphrontFormTextControl())
56 ->setLabel(pht('Name Contains'))
57 ->setName('nameContains')
58 ->setValue($saved->getParameter('nameContains')));
60 $is_stable = $saved->getParameter('isStable');
61 $is_unstable = $saved->getParameter('isUnstable');
62 $is_deprecated = $saved->getParameter('isDeprecated');
63 $form
64 ->appendChild(
65 id(new AphrontFormCheckboxControl())
66 ->setLabel('Stability')
67 ->addCheckbox(
68 'isStable',
70 hsprintf(
71 '<strong>%s</strong>: %s',
72 pht('Stable Methods'),
73 pht('Show established API methods with stable interfaces.')),
74 $is_stable)
75 ->addCheckbox(
76 'isUnstable',
78 hsprintf(
79 '<strong>%s</strong>: %s',
80 pht('Unstable Methods'),
81 pht('Show new methods which are subject to change.')),
82 $is_unstable)
83 ->addCheckbox(
84 'isDeprecated',
86 hsprintf(
87 '<strong>%s</strong>: %s',
88 pht('Deprecated Methods'),
89 pht(
90 'Show old methods which will be deleted in a future '.
91 'version of this software.')),
92 $is_deprecated));
95 protected function getURI($path) {
96 return '/conduit/'.$path;
99 protected function getBuiltinQueryNames() {
100 return array(
101 'modern' => pht('Modern Methods'),
102 'all' => pht('All Methods'),
106 public function buildSavedQueryFromBuiltin($query_key) {
107 $query = $this->newSavedQuery();
108 $query->setQueryKey($query_key);
110 switch ($query_key) {
111 case 'modern':
112 return $query
113 ->setParameter('isStable', true)
114 ->setParameter('isUnstable', true);
115 case 'all':
116 return $query
117 ->setParameter('isStable', true)
118 ->setParameter('isUnstable', true)
119 ->setParameter('isDeprecated', true);
122 return parent::buildSavedQueryFromBuiltin($query_key);
125 protected function renderResultList(
126 array $methods,
127 PhabricatorSavedQuery $query,
128 array $handles) {
129 assert_instances_of($methods, 'ConduitAPIMethod');
131 $viewer = $this->requireViewer();
133 $out = array();
135 $last = null;
136 $list = null;
137 foreach ($methods as $method) {
138 $app = $method->getApplicationName();
139 if ($app !== $last) {
140 $last = $app;
141 if ($list) {
142 $out[] = $list;
144 $list = id(new PHUIObjectItemListView());
145 $list->setHeader($app);
147 $app_object = $method->getApplication();
148 if ($app_object) {
149 $app_name = $app_object->getName();
150 } else {
151 $app_name = $app;
155 $method_name = $method->getAPIMethodName();
157 $item = id(new PHUIObjectItemView())
158 ->setHeader($method_name)
159 ->setHref($this->getApplicationURI('method/'.$method_name.'/'))
160 ->addAttribute($method->getMethodSummary());
162 switch ($method->getMethodStatus()) {
163 case ConduitAPIMethod::METHOD_STATUS_STABLE:
164 break;
165 case ConduitAPIMethod::METHOD_STATUS_UNSTABLE:
166 $item->addIcon('fa-warning', pht('Unstable'));
167 $item->setStatusIcon('fa-warning yellow');
168 break;
169 case ConduitAPIMethod::METHOD_STATUS_DEPRECATED:
170 $item->addIcon('fa-warning', pht('Deprecated'));
171 $item->setStatusIcon('fa-warning red');
172 break;
173 case ConduitAPIMethod::METHOD_STATUS_FROZEN:
174 $item->addIcon('fa-archive', pht('Frozen'));
175 $item->setStatusIcon('fa-archive grey');
176 break;
179 $list->addItem($item);
182 if ($list) {
183 $out[] = $list;
186 $result = new PhabricatorApplicationSearchResultView();
187 $result->setContent($out);
189 return $result;