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 .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
.phpunit.result.cache
var/
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Dependencies conflicts with core
- Internal server error when generating appliance asset pdf
- Display all groups and groups in charge in asset PDF exports
- Fix warning on the Domains tab of PDF exports
- CI: fix Psalm cache directory, declare a unique composer autoloader suffix

## [4.1.5] - 2026-09-01
Expand Down
10 changes: 2 additions & 8 deletions inc/appliance.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item)
sprintf(
__s('%1$s: %2$s'),
'<b><i>' . __s('Group in charge of the hardware') . '</i></b>',
Toolbox::stripTags(Dropdown::getDropdownName(
'glpi_groups',
$item->fields['groups_id_tech'],
)),
PluginPdfCommon::getGroupNames($item->fields['groups_id_tech']),
),
);

Expand All @@ -183,10 +180,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Appliance $item)
sprintf(
__s('%1$s: %2$s'),
'<b><i>' . __s('Group') . '</i></b>',
Toolbox::stripTags(Dropdown::getDropdownName(
'glpi_groups',
$item->fields['groups_id'],
)),
PluginPdfCommon::getGroupNames($item->fields['groups_id']),
),
);

Expand Down
5 changes: 1 addition & 4 deletions inc/cartridgeitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, CartridgeItem $cartitem)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group in charge of the hardware') . '</i></b>',
Dropdown::getDropdownName(
'glpi_groups',
$cartitem->fields['groups_id_tech'],
),
PluginPdfCommon::getGroupNames($cartitem->fields['groups_id_tech']),
),
);

Expand Down
20 changes: 16 additions & 4 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,21 @@ final public function generatePDF($tab_id, $tabs, $page = 0, $render = true)
}
}

/**
* Get the names of groups, sorted and separated by commas, ready to be displayed in a PDF cell
*
* @param array $groups_ids
*
* @return string
*/
public static function getGroupNames(array $groups_ids): string
{
$names = Dropdown::getDropdownArrayNames('glpi_groups', $groups_ids);
natcasesort($names);

return Toolbox::stripTags(implode(', ', $names));
}

public static function mainTitle(PluginPdfSimplePDF $pdf, $item)
{
$pdf->setColumnsSize(50, 50);
Expand Down Expand Up @@ -520,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::getGroupNames($item->fields['groups_id_tech']),
),
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
Expand Down
5 changes: 1 addition & 4 deletions inc/computer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ 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'],
),
PluginPdfCommon::getGroupNames($computer->fields['groups_id']),
),
'<b><i>' . sprintf(__('%1$s: %2$s'), __('UUID') . '</i></b>', $computer->fields['uuid']),
);
Expand Down
5 changes: 1 addition & 4 deletions inc/consumableitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, ConsumableItem $consitem
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group in charge of the hardware') . '</i></b>',
Dropdown::getDropdownName(
'glpi_groups',
$consitem->fields['groups_id_tech'],
),
PluginPdfCommon::getGroupNames($consitem->fields['groups_id_tech']),
),
);

Expand Down
28 changes: 26 additions & 2 deletions inc/domain_item.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,35 @@ public static function pdfForItem(PluginPdfSimplePDF $pdf, CommonDBTM $item)
__s('Expiration date'),
);

foreach ($result as $data) {
$domains = iterator_to_array($result, false);
$tech_groups = [];
$groups = $DB->request([
'SELECT' => ['glpi_groups_items.items_id', 'glpi_groups.completename'],
'FROM' => Group_Item::getTable(),
'INNER JOIN' => [
'glpi_groups' => [
'FKEY' => [
'glpi_groups_items' => 'groups_id',
'glpi_groups' => 'id',
],
],
],
'WHERE' => [
'glpi_groups_items.itemtype' => Domain::class,
'glpi_groups_items.items_id' => array_column($domains, 'id'),
'glpi_groups_items.type' => Group_Item::GROUP_TYPE_TECH,
],
'ORDER' => 'glpi_groups.completename',
]);
foreach ($groups as $group) {
$tech_groups[$group['items_id']][] = $group['completename'];
}

foreach ($domains as $data) {
$pdf->displayLine(
$data['name'],
Dropdown::getDropdownName('glpi_entities', $data['entities_id']),
Dropdown::getDropdownName('glpi_groups', $data['groups_id_tech']),
Toolbox::stripTags(implode(', ', $tech_groups[$data['id']] ?? [])),
getUserName($data['users_id_tech']),
Dropdown::getDropdownName('glpi_domaintypes', $data['domaintypes_id']),
Dropdown::getDropdownName('glpi_domainrelations', $data['domainrelations_id']),
Expand Down
2 changes: 1 addition & 1 deletion inc/monitor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Monitor $item)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']),
PluginPdfCommon::getGroupNames($item->fields['groups_id']),
),
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
Expand Down
2 changes: 1 addition & 1 deletion inc/networkequipment.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, NetworkEquipment $item)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']),
PluginPdfCommon::getGroupNames($item->fields['groups_id']),
),
'<b><i>' . __s('The MAC address and the IP of the equipment are included in an aggregated network port'),
'<b><i>' . sprintf(
Expand Down
2 changes: 1 addition & 1 deletion inc/peripheral.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Peripheral $item)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']),
PluginPdfCommon::getGroupNames($item->fields['groups_id']),
),
'<b><i>' . sprintf(__s('%1$s: %2$s'), __s('Brand') . '</i></b>', $item->fields['brand']),
);
Expand Down
2 changes: 1 addition & 1 deletion inc/phone.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Phone $item)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $item->fields['groups_id']),
PluginPdfCommon::getGroupNames($item->fields['groups_id']),
),
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
Expand Down
2 changes: 1 addition & 1 deletion inc/printer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public static function pdfMain(PluginPdfSimplePDF $pdf, Printer $printer)
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
__s('Group') . '</i></b>',
Dropdown::getDropdownName('glpi_groups', $printer->fields['groups_id']),
PluginPdfCommon::getGroupNames($printer->fields['groups_id']),
),
'<b><i>' . sprintf(
__s('%1$s: %2$s'),
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'],
),
PluginPdfCommon::getGroupNames($software->fields['groups_id_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']),
PluginPdfCommon::getGroupNames($software->fields['groups_id']),
),
);

Expand Down
11 changes: 11 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<phpunit
bootstrap="tests/bootstrap.php"
colors="true"
testdox="true"
>
<testsuites>
<testsuite name="Tests">
<directory>tests/units</directory>
</testsuite>
</testsuites>
</phpunit>
50 changes: 50 additions & 0 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* -------------------------------------------------------------------------
* LICENSE
*
* This file is part of PDF plugin for GLPI.
*
* PDF is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PDF is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Reports. If not, see <http://www.gnu.org/licenses/>.
*
* @author Nelly Mahu-Lasson, Remi Collet, Teclib
* @copyright Copyright (c) 2009-2022 PDF plugin team
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
* @license AGPL License 3.0 or (at your option) any later version
* @link https://github.com/pluginsGLPI/pdf/
* @link http://www.glpi-project.org/
* @package pdf
* @since 2009
* http://www.gnu.org/licenses/agpl-3.0-standalone.html
* --------------------------------------------------------------------------
*/

require __DIR__ . '/../../../tests/bootstrap.php';

$plugin = new Plugin();
$plugin->checkPluginState('pdf');
$plugin->getFromDBbyDir('pdf');

if (!$plugin->isInstalled('pdf')) {
$plugin->install($plugin->getID());
}

if (!$plugin->isActivated('pdf')) {
$plugin->activate($plugin->getID());
}

require_once __DIR__ . '/fixtures/RecordingSimplePDF.php';
62 changes: 62 additions & 0 deletions tests/fixtures/RecordingSimplePDF.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

/**
* -------------------------------------------------------------------------
* LICENSE
*
* This file is part of PDF plugin for GLPI.
*
* PDF is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PDF is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Reports. If not, see <http://www.gnu.org/licenses/>.
*
* @author Nelly Mahu-Lasson, Remi Collet, Teclib
* @copyright Copyright (c) 2009-2022 PDF plugin team
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
* @license AGPL License 3.0 or (at your option) any later version
* @link https://github.com/pluginsGLPI/pdf/
* @link http://www.glpi-project.org/
* @package pdf
* @since 2009
* http://www.gnu.org/licenses/agpl-3.0-standalone.html
* --------------------------------------------------------------------------
*/

namespace GlpiPlugin\Pdf\Tests;

use PluginPdfSimplePDF;

class RecordingSimplePDF extends PluginPdfSimplePDF
{
/** @var string[] */
public array $cells = [];

public function __construct()
{
parent::__construct();
$this->newPage();
}

public function displayTitle()
{
array_push($this->cells, ...func_get_args());
parent::displayTitle(...func_get_args());
}

public function displayLine()
{
array_push($this->cells, ...func_get_args());
parent::displayLine(...func_get_args());
}
}
Loading
Loading