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 f7cdcb1 commit ac02f86
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 36 deletions.
79 changes: 43 additions & 36 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,49 +332,56 @@ function plugin_formcreator_hook_add_ticket(CommonDBTM $item) {
'users_id' => 0,
];
}

$validationStatus = PluginFormcreatorCommon::getTicketStatusForIssue($item);

$issue = new PluginFormcreatorIssue();
$issue->add([
'original_id' => $item->getID(),
'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' => $requester['users_id'],
'validator_id' => '0',
'comment' => addslashes($item->fields['content']),
'original_id' => $item->getID(),
'sub_itemtype' => 'Ticket',
'name' => addslashes($item->fields['name']),
'status' => $validationStatus['status'],
'date_creation' => $item->fields['date'],
'date_mod' => $item->fields['date_mod'],
'entities_id' => $item->fields['entities_id'],
'is_recursive' => '0',
'requester_id' => $requester['users_id'],
'users_id_validator' => $validationStatus['user'],
'comment' => addslashes($item->fields['content']),
]);
}

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();

$validationStatus = PluginFormcreatorCommon::getTicketStatusForIssue($item);

$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' => $validationStatus['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'],
'users_id_validator' => $validationStatus['user'],
'comment' => addslashes($item->fields['content']),
]);
}

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

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

/**
* Get the status to set for an issue matching a ticket
* @param Ticket $item
* @return integer
*/
public static function getTicketStatusForIssue(Ticket $item) {
$ticketValidation = new TicketValidation();
$ticketValidation->getFromDBByCrit([
'tickets_id' => $item->getID(),
]);
$status = $item->fields['status'];
$user = 0;
if (!$ticketValidation->isNewItem()) {
$user = $ticketValidation->fields['users_id_validate'];
$status = 103;
switch ($ticketValidation->fields['status']) {
case TicketValidation::WAITING:
$status = 101;
break;
case TicketValidation::REFUSED:
$status = 102;
break;
}
}

return ['status' => $status, 'user' => $user];
}
}

0 comments on commit ac02f86

Please sign in to comment.