Files
GLPI-Plugin-SOC-Case-Manage…/inc/caseticket.class.php
2025-05-31 14:43:12 +02:00

177 lines
5.3 KiB
PHP

<?php
/**
* SOC Case-Ticket relation class
*/
class PluginSocCaseTicket extends CommonDBRelation {
// From CommonDBRelation
static public $itemtype_1 = 'PluginSocCase';
static public $items_id_1 = 'plugin_soc_cases_id';
static public $itemtype_2 = 'Ticket';
static public $items_id_2 = 'tickets_id';
/**
* Get tickets for a case
*
* @param integer $cases_id
* @return DBmysqlIterator
*/
static function getTicketsForCase($cases_id) {
global $DB;
$iterator = $DB->request([
'SELECT' => [
'glpi_tickets.*',
'glpi_plugin_soc_case_tickets.id AS link_id'
],
'FROM' => 'glpi_plugin_soc_case_tickets',
'LEFT JOIN' => [
'glpi_tickets' => [
'FKEY' => [
'glpi_plugin_soc_case_tickets' => 'tickets_id',
'glpi_tickets' => 'id'
]
]
],
'WHERE' => [
'glpi_plugin_soc_case_tickets.plugin_soc_cases_id' => $cases_id
],
'ORDER' => [
'glpi_tickets.date_creation DESC'
]
]);
return $iterator;
}
/**
* Get cases for a ticket
*
* @param integer $tickets_id
* @return DBmysqlIterator
*/
static function getCasesForTicket($tickets_id) {
global $DB;
$iterator = $DB->request([
'SELECT' => [
'glpi_plugin_soc_cases.*',
'glpi_plugin_soc_case_tickets.id AS link_id'
],
'FROM' => 'glpi_plugin_soc_case_tickets',
'LEFT JOIN' => [
'glpi_plugin_soc_cases' => [
'FKEY' => [
'glpi_plugin_soc_case_tickets' => 'plugin_soc_cases_id',
'glpi_plugin_soc_cases' => 'id'
]
]
],
'WHERE' => [
'glpi_plugin_soc_case_tickets.tickets_id' => $tickets_id
],
'ORDER' => [
'glpi_plugin_soc_cases.date_creation DESC'
]
]);
return $iterator;
}
/**
* Show cases for a ticket
*
* @param Ticket $ticket
* @return void
*/
function showForTicket(Ticket $ticket) {
global $DB;
$ticket_id = $ticket->getID();
if (!$ticket->can($ticket_id, READ)) {
return false;
}
$cases = self::getCasesForTicket($ticket_id);
$nb = count($cases);
echo "<div class='spaced'>";
if ($nb > 0) {
echo "<table class='tab_cadre_fixehov'>";
$header = "<tr>";
$header .= "<th>" . __('Name') . "</th>";
$header .= "<th>" . __('Status') . "</th>";
$header .= "<th>" . __('Severity', 'soc') . "</th>";
$header .= "<th>" . __('Creation date') . "</th>";
$header .= "</tr>";
echo $header;
foreach ($cases as $data) {
$case = new PluginSocCase();
$case->getFromDB($data['id']);
echo "<tr class='tab_bg_1'>";
echo "<td><a href='".Plugin::getWebDir('soc')."/front/case.form.php?id=".$data['id']."'>".$data['name']."</a></td>";
echo "<td><span class='soc-status soc-status-".$data['status']."'>".$case->getStatusOptions()[$data['status']]."</span></td>";
echo "<td><span class='soc-severity soc-severity-".$data['severity']."'>".$case->getSeverityOptions()[$data['severity']]."</span></td>";
echo "<td>".Html::convDateTime($data['date_creation'])."</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "<p class='center'>".__('No SOC case associated with this ticket', 'soc')."</p>";
}
// If user has rights to create cases
if (Session::haveRight('plugin_soc_case', CREATE)) {
echo "<div class='center'>";
echo "<a href='".Plugin::getWebDir('soc')."/front/case.form.php?tickets_id=".$ticket_id."' class='submit'>";
echo __('Create SOC case from this ticket', 'soc');
echo "</a>";
echo "</div>";
}
echo "</div>";
}
/**
* Show form for linking a ticket to a case
*
* @param integer $cases_id
* @param array $options
* @return void
*/
function showFormForCase($cases_id, $options = []) {
global $CFG_GLPI;
$case = new PluginSocCase();
$case->getFromDB($cases_id);
echo "<form method='post' action='".Plugin::getWebDir('soc')."/front/case.form.php'>";
echo "<div class='spaced'>";
echo "<table class='tab_cadre_fixe'>";
echo "<tr class='tab_bg_2'><th colspan='2'>".__('Link a ticket to this case', 'soc')."</th></tr>";
echo "<tr class='tab_bg_1'><td class='right'>".__('Ticket')."</td>";
echo "<td class='left'>";
Ticket::dropdown(['name' => 'tickets_id', 'entity' => $case->fields['entities_id']]);
echo "</td></tr>";
echo "<tr class='tab_bg_1'>";
echo "<td class='center' colspan='2'>";
echo "<input type='hidden' name='plugin_soc_cases_id' value='$cases_id'>";
echo "<input type='submit' name='add_ticket' value=\""._sx('button', 'Add')."\" class='submit'>";
echo "</td></tr>";
echo "</table>";
echo "</div>";
Html::closeForm();
}
}