From 2252bde81842187cc96b18e8c80acfaf406bedf9 Mon Sep 17 00:00:00 2001 From: Herafia Date: Wed, 15 Jul 2026 11:05:21 +0200 Subject: [PATCH 1/4] fix/pdf group and group technician --- inc/appliance.class.php | 10 ++-------- inc/cartridgeitem.class.php | 5 +---- inc/common.class.php | 25 +++++++++++++++++++++---- inc/computer.class.php | 5 +---- inc/consumableitem.class.php | 5 +---- inc/software.class.php | 8 +++----- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/inc/appliance.class.php b/inc/appliance.class.php index bbee4b1..7cdd9cd 100644 --- a/inc/appliance.class.php +++ b/inc/appliance.class.php @@ -154,10 +154,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item) sprintf( __s('%1$s: %2$s'), '' . __s('Group in charge of the hardware') . '', - Toolbox::stripTags(Dropdown::getDropdownName( - 'glpi_groups', - $item->fields['groups_id_tech'], - )), + Toolbox::stripTags(PluginPdfCommon::getGroupDisplayName($item->fields['groups_id_tech'] ?? [], true)), ), ); @@ -183,10 +180,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item) sprintf( __s('%1$s: %2$s'), '' . __s('Group') . '', - Toolbox::stripTags(Dropdown::getDropdownName( - 'glpi_groups', - $item->fields['groups_id'], - )), + Toolbox::stripTags(PluginPdfCommon::getGroupDisplayName($item->fields['groups_id'] ?? [], true)), ), ); diff --git a/inc/cartridgeitem.class.php b/inc/cartridgeitem.class.php index 63a09db..b1977b9 100644 --- a/inc/cartridgeitem.class.php +++ b/inc/cartridgeitem.class.php @@ -95,10 +95,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, CartridgeItem $cartitem) '' . sprintf( __s('%1$s: %2$s'), __s('Group in charge of the hardware') . '', - Dropdown::getDropdownName( - 'glpi_groups', - $cartitem->fields['groups_id_tech'], - ), + PluginPdfCommon::getGroupDisplayName($cartitem->fields['groups_id_tech'] ?? []), ), ); diff --git a/inc/common.class.php b/inc/common.class.php index a883614..77a4378 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -420,6 +420,26 @@ final public function generatePDF($tab_id, $tabs, $page = 0, $render = true) } } + // This helper accepts both formats: the old one (int) and the new one (array). + //This is for compatibility with other item types that do not use the AssignableItem trait. + public static function getGroupDisplayName(array|int $group_ids, bool $strip_tags = false): string + { + if (!is_array($group_ids)) { + $group_ids = $group_ids > 0 ? [$group_ids] : []; + } + $group_ids = array_filter(array_map('intval', $group_ids), static fn($id) => $id > 0); + if (empty($group_ids)) { + return Dropdown::getDropdownName('glpi_groups', 0); + } + $names = array_map( + static fn($id) => $strip_tags + ? Toolbox::stripTags(Dropdown::getDropdownName('glpi_groups', $id)) + : Dropdown::getDropdownName('glpi_groups', $id), + $group_ids, + ); + return implode(', ', $names); + } + public static function mainTitle(PluginPdfSimplePDF $pdf, $item) { $pdf->setColumnsSize(50, 50); @@ -509,10 +529,7 @@ public static function mainLine(PluginPdfSimplePDF $pdf, $item, $field) '' . sprintf( __s('%1$s: %2$s'), __s('Group in charge of the hardware') . '', - Dropdown::getDropdownName( - 'glpi_groups', - $item->fields['groups_id_tech'], - ), + self::getGroupDisplayName($item->fields['groups_id_tech'] ?? []), ), '' . sprintf( __s('%1$s: %2$s'), diff --git a/inc/computer.class.php b/inc/computer.class.php index c8851cf..57e103e 100644 --- a/inc/computer.class.php +++ b/inc/computer.class.php @@ -89,10 +89,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Computer $computer) '' . sprintf( __('%1$s: %2$s'), __('Group') . '', - Dropdown::getDropdownName( - 'glpi_groups', - $computer->fields['groups_id'], - ), + PluginPdfCommon::getGroupDisplayName($computer->fields['groups_id'] ?? []), ), '' . sprintf(__('%1$s: %2$s'), __('UUID') . '', $computer->fields['uuid']), ); diff --git a/inc/consumableitem.class.php b/inc/consumableitem.class.php index 991a641..9461fcc 100644 --- a/inc/consumableitem.class.php +++ b/inc/consumableitem.class.php @@ -84,10 +84,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, ConsumableItem $consitem '' . sprintf( __s('%1$s: %2$s'), __s('Group in charge of the hardware') . '', - Dropdown::getDropdownName( - 'glpi_groups', - $consitem->fields['groups_id_tech'], - ), + PluginPdfCommon::getGroupDisplayName($consitem->fields['groups_id_tech'] ?? []), ), ); diff --git a/inc/software.class.php b/inc/software.class.php index 21a3526..cbdbd83 100644 --- a/inc/software.class.php +++ b/inc/software.class.php @@ -93,10 +93,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software) '' . sprintf( __s('%1$s: %2$s'), __s('Group in charge of the hardware') . '', - Dropdown::getDropdownName( - 'glpi_groups', - $software->fields['groups_id_tech'], - ), + PluginPdfCommon::getGroupDisplayName( + $software->fields['groups_id_tech'] ?? []), ), '' . sprintf( __s('%1$s: %2$s'), @@ -109,7 +107,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software) '' . sprintf( __s('%1$s: %2$s'), __s('Group') . '', - Dropdown::getDropdownName('glpi_groups', $software->fields['groups_id']), + PluginPdfCommon::getGroupDisplayName($software->fields['groups_id'] ?? []), ), ); From 3b706be42e8d4e4e2dc8ff399f94ef9e67612546 Mon Sep 17 00:00:00 2001 From: Herafia Date: Wed, 15 Jul 2026 11:16:42 +0200 Subject: [PATCH 2/4] CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f42bf7..051c4d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Fix image (field : description) in to pdf - Fix massive action PDF export redirecting to item list instead of generating the PDF +- Fix group and group technician display name ## [4.1.2] - 2026-01-08 From 964945adcc404178c14b8d1f87afd0fc0966b7c8 Mon Sep 17 00:00:00 2001 From: Herafia Date: Wed, 15 Jul 2026 11:23:07 +0200 Subject: [PATCH 3/4] fix --- inc/common.class.php | 4 ++-- inc/software.class.php | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/inc/common.class.php b/inc/common.class.php index 77a4378..129d6e8 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -59,7 +59,7 @@ public function addStandardTab($itemtype, array &$ong, array $options) $withtemplate = $options['withtemplate']; } - if (!is_numeric($itemtype) && ($obj = $dbu->getItemForItemtype($itemtype)) && (method_exists($itemtype, 'displayTabContentForPDF'))) { + if (($obj = $dbu->getItemForItemtype($itemtype)) && (method_exists($itemtype, 'displayTabContentForPDF'))) { $titles = $obj->getTabNameForItem($this->obj, $withtemplate); if (!is_array($titles)) { $titles = [1 => $titles]; @@ -428,7 +428,7 @@ public static function getGroupDisplayName(array|int $group_ids, bool $strip_tag $group_ids = $group_ids > 0 ? [$group_ids] : []; } $group_ids = array_filter(array_map('intval', $group_ids), static fn($id) => $id > 0); - if (empty($group_ids)) { + if ($group_ids === []) { return Dropdown::getDropdownName('glpi_groups', 0); } $names = array_map( diff --git a/inc/software.class.php b/inc/software.class.php index cbdbd83..6432b95 100644 --- a/inc/software.class.php +++ b/inc/software.class.php @@ -94,7 +94,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software) __s('%1$s: %2$s'), __s('Group in charge of the hardware') . '', PluginPdfCommon::getGroupDisplayName( - $software->fields['groups_id_tech'] ?? []), + $software->fields['groups_id_tech'] ?? [], + ), ), '' . sprintf( __s('%1$s: %2$s'), From 6972227bc606484e847795f2f25eba90b637a129 Mon Sep 17 00:00:00 2001 From: Herafia <35998899+Herafia@users.noreply.github.com> Date: Fri, 17 Jul 2026 11:07:13 +0200 Subject: [PATCH 4/4] Update inc/common.class.php Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> --- inc/common.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/inc/common.class.php b/inc/common.class.php index 129d6e8..b48dbe9 100644 --- a/inc/common.class.php +++ b/inc/common.class.php @@ -429,7 +429,8 @@ public static function getGroupDisplayName(array|int $group_ids, bool $strip_tag } $group_ids = array_filter(array_map('intval', $group_ids), static fn($id) => $id > 0); if ($group_ids === []) { - return Dropdown::getDropdownName('glpi_groups', 0); + $name = Dropdown::getDropdownName('glpi_groups', 0); + return $strip_tags ? Toolbox::stripTags($name) : $name; } $names = array_map( static fn($id) => $strip_tags