Skip to content
Open
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 PDF export for assignable asset groups by properly handling multiple groups

## [4.1.2] - 2026-01-08

Expand Down
31 changes: 27 additions & 4 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,39 @@
* --------------------------------------------------------------------------
*/

use Glpi\Features\AssignableItem;

abstract class PluginPdfCommon extends CommonGLPI
{
protected $obj = null;
protected $pdf = null;

public static $rightname = 'plugin_pdf';

protected static function getGroupName(CommonDBTM $item, int $group_type = Group_Item::GROUP_TYPE_NORMAL): string
{
$field = $group_type === Group_Item::GROUP_TYPE_TECH ? 'groups_id_tech' : 'groups_id';

if (!Toolbox::hasTrait($item::class, AssignableItem::class)) {
return Toolbox::stripTags(Dropdown::getDropdownName('glpi_groups', $item->fields[$field]));
}

$group_item = new Group_Item();
$groups = $group_item->getItemsAssociatedTo($item::class, (int) $item->fields['id']);

$group_ids = [];
foreach ($groups as $group) {
if ((int) $group->fields['type'] === $group_type) {
$group_ids[] = (int) $group->fields['groups_id'];
}
}
Comment thread
Mary-Clb marked this conversation as resolved.
Outdated

return implode(', ', array_filter(array_map(
static fn($group_id) => Toolbox::stripTags(Dropdown::getDropdownName('glpi_groups', $group_id)),
$group_ids,
)));
Comment on lines +49 to +52

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There’s something I’m not fully grasping in this PR.

In GLPI, an object can be assigned to a group using a one-to-one relationship (i.e., the object contains a groups_id or groups_id_tech column, for example in glpi_itilcategories).

Objects can also be assigned to multiple groups through an intermediate relation table, glpi_groups_items (cf: glpi_computers).

These objects rely on that relation table when they use the AssignableItem trait.

Here (unless I’m mistaken), we are only handling the first case.

}

/**
* Constructor, should intialize $this->obj property
**/
Expand Down Expand Up @@ -509,10 +535,7 @@ public static function mainLine(PluginPdfSimplePDF $pdf, $item, $field)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group in charge of the hardware') . '</i></b>',
Dropdown::getDropdownName(
'glpi_groups',
$item->fields['groups_id_tech'],
),
self::getGroupName($item, Group_Item::GROUP_TYPE_TECH),
),
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
Expand Down
19 changes: 14 additions & 5 deletions inc/computer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,21 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Computer $computer)
'<b><i>' . sprintf(
__('%1$s: %2$s'),
__('Group') . '</i></b>',
Dropdown::getDropdownName(
'glpi_groups',
$computer->fields['groups_id'],
),
self::getGroupName($computer),
),
'<b><i>' . sprintf(
__('%1$s: %2$s'),
__('Group in charge of the hardware') . '</i></b>',
self::getGroupName($computer, Group_Item::GROUP_TYPE_TECH),
),
);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a duplicate "Group in charge of the hardware" field on the Computer PDF. PluginPdfCommon::mainLine($pdf, $computer, 'group-model') (called at inc/computer.class.php:67, unchanged by this PR) already renders "Group in charge of the hardware" paired with "Model" via the group-model case in common.class.php:538-553. The line added here renders the same tech-group value again, paired with "Group", where the pre-PR code only paired "Group" with "UUID". The result is that the tech group appears twice in the generated PDF, and "UUID" is pushed into an extra half-empty row.

Suggested change
);
$pdf->displayLine(
'<b><i>' . sprintf(
__('%1$s: %2$s'),
__('Group') . '</i></b>',
self::getGroupName($computer),
),
'<b><i>' . sprintf(
__('%1$s: %2$s'),
__('UUID') . '</i></b>',
$computer->fields['uuid'],
),
);


$pdf->displayLine(
'<b><i>' . sprintf(
__('%1$s: %2$s'),
__('UUID') . '</i></b>',
$computer->fields['uuid'],
),
'<b><i>' . sprintf(__('%1$s: %2$s'), __('UUID') . '</i></b>', $computer->fields['uuid']),
);

$pdf->displayLine(
Expand Down
6 changes: 1 addition & 5 deletions inc/monitor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Monitor $item)
PluginPdfCommon::mainLine($pdf, $item, 'user-management');

$pdf->displayLine(
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']),
),
'<b><i>' . sprintf(__s('%1$s: %2$s'), __s('Group') . '</i></b>', self::getGroupName($item)),
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Size') . '</i></b>',
Expand Down
6 changes: 1 addition & 5 deletions inc/networkequipment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, NetworkEquipment $item)
);

$pdf->displayLine(
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']),
),
'<b><i>' . sprintf(__s('%1$s: %2$s'), __s('Group') . '</i></b>', self::getGroupName($item)),
'<b><i>' . __s('The MAC address and the IP of the equipment are included in an aggregated network port'),
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
Expand Down
6 changes: 1 addition & 5 deletions inc/peripheral.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Peripheral $item)
PluginPdfCommon::mainLine($pdf, $item, 'user-management');

$pdf->displayLine(
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']),
),
'<b><i>' . sprintf(__s('%1$s: %2$s'), __s('Group') . '</i></b>', self::getGroupName($item)),
'<b><i>' . sprintf(__s('%1$s: %2$s'), __s('Brand') . '</i></b>', $item->fields['brand']),
);

Expand Down
12 changes: 2 additions & 10 deletions inc/phone.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,16 +64,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Phone $item)


$pdf->displayLine(
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']),
),
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('UUID') . '</i></b>',
$item->fields['uuid'],
),
'<b><i>' . sprintf(__s('%1$s: %2$s'), __s('Group') . '</i></b>', self::getGroupName($item)),
'<b><i>' . sprintf(__s('%1$s: %2$s'), __s('UUID') . '</i></b>', $item->fields['uuid']),
);

$pdf->displayLine(
Expand Down
12 changes: 2 additions & 10 deletions inc/printer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,8 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Printer $printer)
);

$pdf->displayLine(
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $printer->fields['groups_id']),
),
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('UUID') . '</i></b>',
$printer->fields['uuid'],
),
'<b><i>' . sprintf(__s('%1$s: %2$s'), __s('Group') . '</i></b>', self::getGroupName($printer)),
'<b><i>' . sprintf(__s('%1$s: %2$s'), __s('UUID') . '</i></b>', $printer->fields['uuid']),
);


Expand Down
7 changes: 2 additions & 5 deletions inc/software.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group in charge of the hardware') . '</i></b>',
Dropdown::getDropdownName(
'glpi_groups',
$software->fields['groups_id_tech'],
),
self::getGroupName($software, Group_Item::GROUP_TYPE_TECH),
),
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
Expand All @@ -109,7 +106,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Software $software)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $software->fields['groups_id']),
self::getGroupName($software),
),
);

Expand Down