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 = [];