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

177 lines
5.3 KiB
PHP

<?php
/**
* SOC Case-Change relation class
*/
class PluginSocCaseChange extends CommonDBRelation {
// From CommonDBRelation
static public $itemtype_1 = 'PluginSocCase';
static public $items_id_1 = 'plugin_soc_cases_id';
static public $itemtype_2 = 'Change';
static public $items_id_2 = 'changes_id';
/**
* Get changes for a case
*
* @param integer $cases_id
* @return DBmysqlIterator
*/
static function getChangesForCase($cases_id) {
global $DB;
$iterator = $DB->request([
'SELECT' => [
'glpi_changes.*',
'glpi_plugin_soc_case_changes.id AS link_id'
],
'FROM' => 'glpi_plugin_soc_case_changes',
'LEFT JOIN' => [
'glpi_changes' => [
'FKEY' => [
'glpi_plugin_soc_case_changes' => 'changes_id',
'glpi_changes' => 'id'
]
]
],
'WHERE' => [
'glpi_plugin_soc_case_changes.plugin_soc_cases_id' => $cases_id
],
'ORDER' => [
'glpi_changes.date_creation DESC'
]
]);
return $iterator;
}
/**
* Get cases for a change
*
* @param integer $changes_id
* @return DBmysqlIterator
*/
static function getCasesForChange($changes_id) {
global $DB;
$iterator = $DB->request([
'SELECT' => [
'glpi_plugin_soc_cases.*',
'glpi_plugin_soc_case_changes.id AS link_id'
],
'FROM' => 'glpi_plugin_soc_case_changes',
'LEFT JOIN' => [
'glpi_plugin_soc_cases' => [
'FKEY' => [
'glpi_plugin_soc_case_changes' => 'plugin_soc_cases_id',
'glpi_plugin_soc_cases' => 'id'
]
]
],
'WHERE' => [
'glpi_plugin_soc_case_changes.changes_id' => $changes_id
],
'ORDER' => [
'glpi_plugin_soc_cases.date_creation DESC'
]
]);
return $iterator;
}
/**
* Show cases for a change
*
* @param Change $change
* @return void
*/
function showForChange(Change $change) {
global $DB;
$change_id = $change->getID();
if (!$change->can($change_id, READ)) {
return false;
}
$cases = self::getCasesForChange($change_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 change', '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?changes_id=".$change_id."' class='submit'>";
echo __('Create SOC case from this change', 'soc');
echo "</a>";
echo "</div>";
}
echo "</div>";
}
/**
* Show form for linking a change 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 change to this case', 'soc')."</th></tr>";
echo "<tr class='tab_bg_1'><td class='right'>".__('Change')."</td>";
echo "<td class='left'>";
Change::dropdown(['name' => 'changes_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_change' value=\""._sx('button', 'Add')."\" class='submit'>";
echo "</td></tr>";
echo "</table>";
echo "</div>";
Html::closeForm();
}
}