-
Notifications
You must be signed in to change notification settings - Fork 12
FIX / PDF export for assignable asset groups #63
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 7 commits
63a67af
c5a4367
c6ee945
9d121a6
8561d73
64516c8
be909f2
1e1b4f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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']; | ||
| } | ||
| } | ||
|
|
||
| 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 Objects can also be assigned to multiple groups through an intermediate relation table, These objects rely on that relation table when they use the Here (unless I’m mistaken), we are only handling the first case. |
||
| } | ||
|
|
||
| /** | ||
| * Constructor, should intialize $this->obj property | ||
| **/ | ||
|
|
@@ -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'), | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you try this?: