diff --git a/hook.php b/hook.php index 4c48a38..c572721 100644 --- a/hook.php +++ b/hook.php @@ -55,6 +55,7 @@ function plugin_transferticketentity_install() `allow_transfer` BOOLEAN NOT NULL DEFAULT 0, `keep_category` BOOLEAN NOT NULL DEFAULT 0, `itilcategories_id` INT {$default_key_sign}, + `log_type` TINYINT NOT NULL DEFAULT 0, PRIMARY KEY (`id`), FOREIGN KEY (`entities_id`) REFERENCES `glpi_entities` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET={$default_charset} COLLATE={$default_collation} ROW_FORMAT=DYNAMIC;"; @@ -62,6 +63,11 @@ function plugin_transferticketentity_install() $DB->doQuery($query); } + if (!$DB->fieldExists('glpi_plugin_transferticketentity_entities_settings', 'log_type')) { + $DB->doQuery("ALTER TABLE `glpi_plugin_transferticketentity_entities_settings` + ADD COLUMN `log_type` TINYINT NOT NULL DEFAULT 0"); + } + return true; } diff --git a/src/Entity.php b/src/Entity.php index 215f0f5..a07a94f 100644 --- a/src/Entity.php +++ b/src/Entity.php @@ -82,6 +82,7 @@ public function prepareInputForAdd($input) 'allow_transfer', 'keep_category', 'itilcategories_id', + 'log_type', ])); } @@ -95,6 +96,7 @@ public function prepareInputForUpdate($input) 'allow_transfer', 'keep_category', 'itilcategories_id', + 'log_type', ])); } @@ -201,6 +203,7 @@ public function showFormMcv($item) $checkRights->fields['allow_transfer'] = 0; $checkRights->fields['keep_category'] = 0; $checkRights->fields['itilcategories_id'] = 0; + $checkRights->fields['log_type'] = 0; } $target = self::getFormURL(); @@ -215,6 +218,10 @@ public function showFormMcv($item) 'entities_id' => $item->getID(), 'availableCategories' => $availableCategories, 'checkMandatoryCategory' => $checkMandatoryCategory, + 'log_type_options' => [ + 0 => __('Followup', 'transferticketentity'), + 1 => __('Task', 'transferticketentity'), + ], ], ); @@ -264,6 +271,7 @@ public static function checkEntityRight($params) $array['allow_transfer'] = $data['allow_transfer']; $array['keep_category'] = $data['keep_category']; $array['itilcategories_id'] = $data['itilcategories_id']; + $array['log_type'] = $data['log_type'] ?? 0; } return $array; diff --git a/src/Ticket.php b/src/Ticket.php index dae70ea..a504223 100644 --- a/src/Ticket.php +++ b/src/Ticket.php @@ -42,9 +42,10 @@ use Group_Ticket; use Group_User; use Html; -use Planning; use Session; use Ticket_User; +use ITILFollowup; +use Planning; use TicketTask; use TicketTemplateMandatoryField; @@ -633,26 +634,36 @@ public function launchTicketTransfer($params) } } - $groupText = "

$justification"; + $content = __("Transfer to", "transferticketentity") . " $theEntity"; - if (isset($params['group_choice']) - && $params['group_choice'] > 0) { + if (!empty($params['group_choice']) && $params['group_choice'] > 0) { $group = new Group(); - $group->getfromDB($params['group_choice']); - $groupText = __("in the group", "transferticketentity") ." ". $group->getName() ."\n

$justification"; + $group->getFromDB($params['group_choice']); + $content .= " " . __("in the group", "transferticketentity") . " " . $group->getName(); } - // Log the transfer in a task - $task = new TicketTask(); - $task->add([ - 'tickets_id' => $params['id_ticket'], - 'is_private' => true, - 'state' => Planning::INFO, - 'content' => __( - "Transfer to", - "transferticketentity" - ) . " $theEntity " . $groupText - ]); + if (!empty($justification)) { + $content .= "

" . $justification; + } + + // Log the transfer as a followup or task depending on entity configuration + if (($checkEntityRight['log_type'] ?? 0) == 1) { + $task = new TicketTask(); + $task->add([ + 'tickets_id' => $params['id_ticket'], + 'is_private' => true, + 'state' => Planning::INFO, + 'content' => $content, + ]); + } else { + $followup = new ITILFollowup(); + $followup->add([ + 'itemtype' => \Ticket::class, + 'items_id' => $params['id_ticket'], + 'is_private' => true, + 'content' => $content, + ]); + } $ticket = new \Ticket(); $ticket->getFromDB($params['id_ticket']); diff --git a/templates/config.html.twig b/templates/config.html.twig index 4e70990..c3817db 100644 --- a/templates/config.html.twig +++ b/templates/config.html.twig @@ -86,6 +86,22 @@ along with Reports. If not, see . ) }} +
+ +
+ {% do call('Dropdown::showFromArray', [ + 'log_type', + log_type_options, + { + 'multiple': false, + 'value': item.fields['log_type']|default(0), + } + ]) %} +
+
+ {# Bloc catégorie #}