From 6287f1b349b8750c0907c4c23b1fc575dae7dd85 Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Fri, 15 Sep 2023 11:36:40 +0200 Subject: [PATCH] fix(category): translation feature of dropdowns not handled --- inc/category.class.php | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/inc/category.class.php b/inc/category.class.php index 1fbdff3dc..f1708f411 100644 --- a/inc/category.class.php +++ b/inc/category.class.php @@ -130,9 +130,7 @@ public static function getCategoryTree(): array { ]); $request = [ 'SELECT' => [ - 'id', - 'name', - 'comment', + self::getTableField('id'), "$categoryFk as parent", 'level', new QueryExpression( @@ -140,8 +138,43 @@ public static function getCategoryTree(): array { ), ], 'FROM' => $cat_table, + 'LEFT JOIN' => [], 'ORDER' => ["level DESC", "name DESC"], ]; + $translation_table = DropdownTranslation::getTable(); + if (Session::haveTranslations(self::getType(), 'name')) { + $request['LEFT JOIN']["$translation_table as namet"] = [ + 'FKEY' => [ + $cat_table => 'id', + 'namet' => 'items_id', + ['AND' => [ + 'namet.language' => $_SESSION['glpilanguage'], + 'namet.itemtype' => self::getType(), + 'namet.field' => 'name', + ]], + ], + ]; + $request['SELECT'][] = 'namet.value as name'; + } else { + $request['SELECT'][] = 'name'; + $request['SELECT'][] = 'comment'; + } + if (Session::haveTranslations(self::getType(), 'comment')) { + $request['LEFT JOIN']["$translation_table as commentt"] = [ + 'FKEY' => [ + $cat_table => 'id', + 'commentt' => 'items_id', + ['AND' => [ + 'namet.language' => $_SESSION['glpilanguage'], + 'namet.itemtype' => self::getType(), + 'namet.field' => 'comment', + ]], + ], + ]; + $request['SELECT'][] = 'commentt.value as comment'; + } else { + $request['SELECT'][] = 'comment'; + } $result = $DB->request($request); $categories = [];