Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
17 changes: 13 additions & 4 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ abstract class PluginPdfCommon extends CommonGLPI

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';

$group_ids = (array) ($item->fields[$field] ?? 0);

return implode(', ', array_filter(array_map(
static fn($group_id) => Toolbox::stripTags(Dropdown::getDropdownName('glpi_groups', $group_id)),
$group_ids,
)));
Comment on lines +46 to +49
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 +521,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),
),
);

$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