Skip to content

Commit

Permalink
refactor(glpiselectfield): isolate list of supported objects
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Apr 9, 2021
1 parent d7f430f commit 6f6823e
Showing 1 changed file with 58 additions and 52 deletions.
110 changes: 58 additions & 52 deletions inc/field/glpiselectfield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,58 +77,7 @@ public function getDesignSpecializationField(): array {
$label .= _n('GLPI object', 'GLPI objects', 1, 'formcreator');
$label .= '</label>';

$optgroup = [
__("Assets") => [
Computer::class => Computer::getTypeName(2),
Monitor::class => Monitor::getTypeName(2),
Software::class => Software::getTypeName(2),
NetworkEquipment::class => Networkequipment::getTypeName(2),
Peripheral::class => Peripheral::getTypeName(2),
Printer::class => Printer::getTypeName(2),
CartridgeItem::class => CartridgeItem::getTypeName(2),
ConsumableItem::class => ConsumableItem::getTypeName(2),
Phone::class => Phone::getTypeName(2),
Line::class => Line::getTypeName(2),
PassiveDCEquipment::class => PassiveDCEquipment::getTypeName(2),
Appliance::class => Appliance::getTypeName(2),
],
__("Assistance") => [
Ticket::class => Ticket::getTypeName(2),
Problem::class => Problem::getTypeName(2),
TicketRecurrent::class => TicketRecurrent::getTypeName(2)
],
__("Management") => [
Budget::class => Budget::getTypeName(2),
Supplier::class => Supplier::getTypeName(2),
Contact::class => Contact::getTypeName(2),
Contract::class => Contract::getTypeName(2),
Document::class => Document::getTypeName(2),
Project::class => Project::getTypeName(2),
Certificate::class => Certificate::getTypeName(2)
],
__("Tools") => [
Reminder::class => __("Notes"),
RSSFeed::class => __("RSS feed")
],
__("Administration") => [
User::class => User::getTypeName(2),
Group::class => Group::getTypeName(2),
Entity::class => Entity::getTypeName(2),
Profile::class => Profile::getTypeName(2)
],
];
if ((new Plugin())->isActivated('appliances')) {
$optgroup[__("Assets")][PluginAppliancesAppliance::class] = PluginAppliancesAppliance::getTypeName(2) . ' (' . _n('Plugin', 'Plugins', 1) . ')';
}

if ((new Plugin())->isActivated("genericobject")) {
$optgroup[__('Plugin') . " " . __('Objects management', 'genericobject')] = [];
$genericObjectType = new PluginGenericobjectType();
$genericObjectTypes = $genericObjectType->find();
foreach ($genericObjectTypes as $object) {
$optgroup[__('Plugin') . " " . __('Objects management', 'genericobject')][$object["itemtype"]] = $object["itemtype"]::getTypeName();
}
}
$optgroup = $this->getObjects();

$decodedValues = json_decode($this->question->fields['values'], JSON_OBJECT_AS_ARRAY);
if ($decodedValues === null) {
Expand Down Expand Up @@ -269,4 +218,61 @@ public function regex($value): bool {
public function isAnonymousFormCompatible(): bool {
return false;
}

public function getObjects() {
$optgroup = [
__("Assets") => [
Computer::class => Computer::getTypeName(2),
Monitor::class => Monitor::getTypeName(2),
Software::class => Software::getTypeName(2),
NetworkEquipment::class => Networkequipment::getTypeName(2),
Peripheral::class => Peripheral::getTypeName(2),
Printer::class => Printer::getTypeName(2),
CartridgeItem::class => CartridgeItem::getTypeName(2),
ConsumableItem::class => ConsumableItem::getTypeName(2),
Phone::class => Phone::getTypeName(2),
Line::class => Line::getTypeName(2),
PassiveDCEquipment::class => PassiveDCEquipment::getTypeName(2),
Appliance::class => Appliance::getTypeName(2),
],
__("Assistance") => [
Ticket::class => Ticket::getTypeName(2),
Problem::class => Problem::getTypeName(2),
TicketRecurrent::class => TicketRecurrent::getTypeName(2)
],
__("Management") => [
Budget::class => Budget::getTypeName(2),
Supplier::class => Supplier::getTypeName(2),
Contact::class => Contact::getTypeName(2),
Contract::class => Contract::getTypeName(2),
Document::class => Document::getTypeName(2),
Project::class => Project::getTypeName(2),
Certificate::class => Certificate::getTypeName(2)
],
__("Tools") => [
Reminder::class => __("Notes"),
RSSFeed::class => __("RSS feed")
],
__("Administration") => [
User::class => User::getTypeName(2),
Group::class => Group::getTypeName(2),
Entity::class => Entity::getTypeName(2),
Profile::class => Profile::getTypeName(2)
],
];
if ((new Plugin())->isActivated('appliances')) {
$optgroup[__("Assets")][PluginAppliancesAppliance::class] = PluginAppliancesAppliance::getTypeName(2) . ' (' . _n('Plugin', 'Plugins', 1) . ')';
}

if ((new Plugin())->isActivated("genericobject")) {
$optgroup[__('Plugin') . " " . __('Objects management', 'genericobject')] = [];
$genericObjectType = new PluginGenericobjectType();
$genericObjectTypes = $genericObjectType->find();
foreach ($genericObjectTypes as $object) {
$optgroup[__('Plugin') . " " . __('Objects management', 'genericobject')][$object["itemtype"]] = $object["itemtype"]::getTypeName();
}
}

return $optgroup;
}
}

0 comments on commit 6f6823e

Please sign in to comment.