From 61058a36580012cdee84afbbe53976d861cf4f3a Mon Sep 17 00:00:00 2001 From: Jean-Yves Gaulier Date: Tue, 27 Nov 2018 19:33:36 +0100 Subject: [PATCH] PHRAS-1326_intl-labels-in-facets_MASTER add "labels" array to facets --- .../Controller/Prod/QueryController.php | 24 +++++++++++++------ lib/classes/databox/field.php | 10 ++++++++ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/lib/Alchemy/Phrasea/Controller/Prod/QueryController.php b/lib/Alchemy/Phrasea/Controller/Prod/QueryController.php index bc8603603b..2ff89422e1 100644 --- a/lib/Alchemy/Phrasea/Controller/Prod/QueryController.php +++ b/lib/Alchemy/Phrasea/Controller/Prod/QueryController.php @@ -327,6 +327,10 @@ class QueryController extends Controller foreach(ElasticsearchOptions::getAggregableTechnicalFields() as $k => $f) { $fieldsInfosByName[$k] = $f; $fieldsInfosByName[$k]['trans_label'] = $this->app->trans($f['label']); + $fieldsInfosByName[$k]['labels'] = []; + foreach($this->app->getAvailableLanguages() as $locale => $lng) { + $fieldsInfosByName[$k]['labels'][$locale] = $this->app->trans($f['label'], [], "messages", $locale); + } } // add databox fields @@ -338,17 +342,22 @@ class QueryController extends Controller foreach ($databox->get_meta_structure() as $field) { $name = $field->get_name(); $fieldsInfos[$sbasId][$name] = [ - 'label' => $field->get_label($this->app['locale']), - 'type' => $field->get_type(), + 'label' => $field->get_label($this->app['locale']), + 'labels' => $field->get_labels(), + 'type' => $field->get_type(), 'business' => $field->isBusiness(), - 'multi' => $field->is_multi(), + 'multi' => $field->is_multi(), ]; + + // infos on the "same" field (by name) on multiple databoxes !!! + // label(s) can be inconsistants : the first databox wins if (!isset($fieldsInfosByName[$name])) { $fieldsInfosByName[$name] = [ - 'label' => $field->get_label($this->app['locale']), - 'type' => $field->get_type(), - 'field' => $field->get_name(), - 'query' => "field." . $field->get_name() . ":%s", + 'label' => $field->get_label($this->app['locale']), + 'labels' => $field->get_labels(), + 'type' => $field->get_type(), + 'field' => $field->get_name(), + 'query' => "field." . $field->get_name() . ":%s", 'trans_label' => $field->get_label($this->app['locale']), ]; $field->get_label($this->app['locale']); @@ -399,6 +408,7 @@ class QueryController extends Controller $f = $fieldsInfosByName[$facetName]; $facet['label'] = $f['trans_label']; + $facet['labels'] = $f['labels']; $facet['type'] = strtoupper($f['type']) . "-AGGREGATE"; $facets[] = $facet; diff --git a/lib/classes/databox/field.php b/lib/classes/databox/field.php index 6a93dbcfa1..cd12bc8682 100644 --- a/lib/classes/databox/field.php +++ b/lib/classes/databox/field.php @@ -440,6 +440,16 @@ class databox_field implements cache_cacheableInterface return isset($this->labels[$code]) && '' !== $this->labels[$code] ? $this->labels[$code] : $this->name; } + /** + * get all localized labels + * + * @return string[] + */ + public function get_labels() + { + return $this->labels; + } + /** * @param string $name * @return databox_field