Skip to content

Commit

Permalink
fix(issue): take ticket valdiation status into account
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry committed May 19, 2020
1 parent b5f0212 commit 5d9cb07
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 26 deletions.
55 changes: 29 additions & 26 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,12 +332,13 @@ function plugin_formcreator_hook_add_ticket(CommonDBTM $item) {
'users_id' => 0,
];
}

$issue = new PluginFormcreatorIssue();
$issue->add([
'original_id' => $item->getID(),
'sub_itemtype' => 'Ticket',
'name' => addslashes($item->fields['name']),
'status' => $item->fields['status'],
'status' => PluginFOrmcreatorCommon::getTicketStatusForIssue($item),
'date_creation' => $item->fields['date'],
'date_mod' => $item->fields['date_mod'],
'entities_id' => $item->fields['entities_id'],
Expand All @@ -349,32 +350,34 @@ function plugin_formcreator_hook_add_ticket(CommonDBTM $item) {
}

function plugin_formcreator_hook_update_ticket(CommonDBTM $item) {
if ($item instanceof Ticket) {
$id = $item->getID();

$issue = new PluginFormcreatorIssue();
$issue->getFromDBByCrit([
'AND' => [
'sub_itemtype' => Ticket::class,
'original_id' => $id
]
]);
$issue->update([
'id' => $issue->getID(),
'original_id' => $id,
'display_id' => "t_$id",
'sub_itemtype' => 'Ticket',
'name' => addslashes($item->fields['name']),
'status' => $item->fields['status'],
'date_creation' => $item->fields['date'],
'date_mod' => $item->fields['date_mod'],
'entities_id' => $item->fields['entities_id'],
'is_recursive' => '0',
'requester_id' => $item->fields['users_id_recipient'],
'validator_id' => '0',
'comment' => addslashes($item->fields['content']),
]);
if (!($item instanceof Ticket)) {
return;
}

$id = $item->getID();

$issue = new PluginFormcreatorIssue();
$issue->getFromDBByCrit([
'AND' => [
'sub_itemtype' => Ticket::class,
'original_id' => $id
]
]);
$issue->update([
'id' => $issue->getID(),
'original_id' => $id,
'display_id' => "t_$id",
'sub_itemtype' => 'Ticket',
'name' => addslashes($item->fields['name']),
'status' => PluginFOrmcreatorCommon::getTicketStatusForIssue($item),
'date_creation' => $item->fields['date'],
'date_mod' => $item->fields['date_mod'],
'entities_id' => $item->fields['entities_id'],
'is_recursive' => '0',
'requester_id' => $item->fields['users_id_recipient'],
'validator_id' => '0',
'comment' => addslashes($item->fields['content']),
]);
}

function plugin_formcreator_hook_delete_ticket(CommonDBTM $item) {
Expand Down
21 changes: 21 additions & 0 deletions inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,4 +210,25 @@ public static function cancelMyTicket($id) {

return $ticket->delete($ticket->fields);
}

public static function getTicketStatusForIssue(Ticket $item) {
$ticketValidation = new TicketValidation();
$ticketValidation->getFromDBByCrit([
'tickets_id' => $item->getID(),
]);
$status = $item->fields['status'];
if (!$ticketValidation->isNewItem()) {
$status = 103;
switch ($ticketValidation->fields['status']) {
case TicketValidation::WAITING:
$status = 101;
break;
case TicketValidation::REFUSED:
$status = 102;
break;
}
}

return $status;
}
}

0 comments on commit 5d9cb07

Please sign in to comment.