mirror of
https://github.com/tips-of-mine/GLPI-Plugin-SOC-Case-Management.git
synced 2025-06-28 05:38:42 +02:00
Correction du fichier hook.php pour le plugin SOC
This commit is contained in:
326
hook.php
326
hook.php
@ -4,49 +4,156 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Hook called after a new item has been added
|
||||
* Item display hook - adds tabs to items
|
||||
*
|
||||
* @param CommonDBTM $item
|
||||
* @return void
|
||||
* @param CommonGLPI $item Object on which to add the tab
|
||||
* @param integer $withtemplate
|
||||
* @return array|string
|
||||
*/
|
||||
function plugin_soc_item_add(CommonDBTM $item) {
|
||||
// Add actions when a new item is created
|
||||
function plugin_soc_getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
|
||||
if ($withtemplate) {
|
||||
return '';
|
||||
}
|
||||
|
||||
switch ($item->getType()) {
|
||||
case 'Ticket':
|
||||
if (Session::haveRight('plugin_soc_case', READ)) {
|
||||
return PluginSocCase::getTypeName(Session::getPluralNumber());
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Change':
|
||||
if (Session::haveRight('plugin_soc_case', READ)) {
|
||||
return PluginSocCase::getTypeName(Session::getPluralNumber());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called after an item has been updated
|
||||
* Item update hook
|
||||
*
|
||||
* @param CommonDBTM $item
|
||||
* @param CommonDBTM $item Item being updated
|
||||
* @return void
|
||||
*/
|
||||
function plugin_soc_item_update(CommonDBTM $item) {
|
||||
// Add actions when an item is updated
|
||||
// Handle item updates
|
||||
switch ($item->getType()) {
|
||||
case 'Ticket':
|
||||
case 'Change':
|
||||
// Custom update logic if needed
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called after an item has been deleted
|
||||
* Item add hook
|
||||
*
|
||||
* @param CommonDBTM $item
|
||||
* @param CommonDBTM $item Item being added
|
||||
* @return void
|
||||
*/
|
||||
function plugin_soc_item_add(CommonDBTM $item) {
|
||||
// Handle item additions
|
||||
switch ($item->getType()) {
|
||||
case 'Ticket':
|
||||
case 'Change':
|
||||
// Custom add logic if needed
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Item delete hook
|
||||
*
|
||||
* @param CommonDBTM $item Item being deleted
|
||||
* @return void
|
||||
*/
|
||||
function plugin_soc_item_delete(CommonDBTM $item) {
|
||||
// Add actions when an item is deleted
|
||||
// Handle item deletions
|
||||
switch ($item->getType()) {
|
||||
case 'Ticket':
|
||||
case 'Change':
|
||||
// Custom delete logic if needed
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called after an item has been purged
|
||||
* Item purge hook
|
||||
*
|
||||
* @param CommonDBTM $item
|
||||
* @param CommonDBTM $item Item being purged
|
||||
* @return void
|
||||
*/
|
||||
function plugin_soc_item_purge(CommonDBTM $item) {
|
||||
// Add actions when an item is purged
|
||||
// Handle item purges
|
||||
global $DB;
|
||||
|
||||
switch ($item->getType()) {
|
||||
case 'Ticket':
|
||||
// Delete case-ticket relations
|
||||
$DB->delete(
|
||||
'glpi_plugin_soc_case_tickets',
|
||||
['tickets_id' => $item->getID()]
|
||||
);
|
||||
break;
|
||||
|
||||
case 'Change':
|
||||
// Delete case-change relations
|
||||
$DB->delete(
|
||||
'glpi_plugin_soc_case_changes',
|
||||
['changes_id' => $item->getID()]
|
||||
);
|
||||
break;
|
||||
|
||||
case 'PluginSocCase':
|
||||
// Delete related items
|
||||
$DB->delete(
|
||||
'glpi_plugin_soc_case_tickets',
|
||||
['plugin_soc_cases_id' => $item->getID()]
|
||||
);
|
||||
|
||||
$DB->delete(
|
||||
'glpi_plugin_soc_case_changes',
|
||||
['plugin_soc_cases_id' => $item->getID()]
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook called when displaying the tabs for an item
|
||||
* Display tab content for item
|
||||
*
|
||||
* @param array $params
|
||||
* @param CommonGLPI $item Object on which to display the tab
|
||||
* @param integer $tabnum Tab number
|
||||
* @param integer $withtemplate
|
||||
* @return boolean
|
||||
*/
|
||||
function plugin_soc_displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
|
||||
if ($withtemplate) {
|
||||
return false;
|
||||
}
|
||||
|
||||
switch ($item->getType()) {
|
||||
case 'Ticket':
|
||||
$case_ticket = new PluginSocCaseTicket();
|
||||
$case_ticket->showForTicket($item);
|
||||
return true;
|
||||
|
||||
case 'Change':
|
||||
$case_change = new PluginSocCaseChange();
|
||||
$case_change->showForChange($item);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to define additional search options for types
|
||||
*
|
||||
* @param string $itemtype Item type
|
||||
* @return array
|
||||
*/
|
||||
function plugin_soc_getAddSearchOptions($itemtype) {
|
||||
@ -58,6 +165,27 @@ function plugin_soc_getAddSearchOptions($itemtype) {
|
||||
'table' => 'glpi_plugin_soc_cases',
|
||||
'field' => 'name',
|
||||
'name' => __('SOC Case', 'soc'),
|
||||
'datatype' => 'itemlink',
|
||||
'itemlink_type' => 'PluginSocCase',
|
||||
'massiveaction' => false,
|
||||
'joinparams' => [
|
||||
'beforejoin' => [
|
||||
'table' => $itemtype == 'Ticket' ? 'glpi_plugin_soc_case_tickets' : 'glpi_plugin_soc_case_changes',
|
||||
'joinparams' => [
|
||||
'jointype' => 'itemtype_item',
|
||||
'specific_itemtype' => $itemtype
|
||||
]
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
$options[9001] = [
|
||||
'table' => 'glpi_plugin_soc_cases',
|
||||
'field' => 'severity',
|
||||
'name' => __('SOC Case Severity', 'soc'),
|
||||
'datatype' => 'specific',
|
||||
'searchtype' => ['equals', 'notequals'],
|
||||
'massiveaction' => false,
|
||||
'joinparams' => [
|
||||
'beforejoin' => [
|
||||
'table' => $itemtype == 'Ticket' ? 'glpi_plugin_soc_case_tickets' : 'glpi_plugin_soc_case_changes',
|
||||
@ -71,4 +199,170 @@ function plugin_soc_getAddSearchOptions($itemtype) {
|
||||
}
|
||||
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to add cron tasks
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function plugin_soc_cron_info() {
|
||||
return [
|
||||
'soc' => [
|
||||
'description' => __('Auto-close SOC cases', 'soc'),
|
||||
'parameter' => __('Delay in days', 'soc'),
|
||||
'state' => CronTask::STATE_WAITING,
|
||||
'mode' => CronTask::MODE_EXTERNAL,
|
||||
'frequency' => DAY_TIMESTAMP,
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute cron task
|
||||
*
|
||||
* @param CronTask $task CronTask object
|
||||
* @return integer
|
||||
*/
|
||||
function plugin_soc_cronSoc(CronTask $task) {
|
||||
global $DB;
|
||||
|
||||
// Get autoclose delay from config
|
||||
$config = PluginSocConfig::getConfig();
|
||||
$delay = $config['autoclose_delay'];
|
||||
|
||||
if ($delay <= 0) {
|
||||
// Auto-closing is disabled
|
||||
$task->log(__('Auto-closing SOC cases is disabled in plugin configuration.', 'soc'));
|
||||
return 0;
|
||||
}
|
||||
|
||||
$time_limit = date('Y-m-d H:i:s', strtotime("-$delay days"));
|
||||
|
||||
// Find resolved cases older than the delay
|
||||
$cases = $DB->request([
|
||||
'FROM' => 'glpi_plugin_soc_cases',
|
||||
'WHERE' => [
|
||||
'status' => PluginSocCase::STATUS_RESOLVED,
|
||||
'date_mod' => ['<', $time_limit],
|
||||
'is_deleted' => 0
|
||||
]
|
||||
]);
|
||||
|
||||
$count = 0;
|
||||
foreach ($cases as $case_data) {
|
||||
$case = new PluginSocCase();
|
||||
$case->getFromDB($case_data['id']);
|
||||
|
||||
// Update status to closed
|
||||
$case->update([
|
||||
'id' => $case_data['id'],
|
||||
'status' => PluginSocCase::STATUS_CLOSED
|
||||
]);
|
||||
|
||||
$task->addVolume(1);
|
||||
$count++;
|
||||
}
|
||||
|
||||
$task->log(sprintf(__('Closed %d SOC cases.', 'soc'), $count));
|
||||
|
||||
return ($count > 0) ? 1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for database relations
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function plugin_soc_getDatabaseRelations() {
|
||||
return [
|
||||
'glpi_entities' => [
|
||||
'glpi_plugin_soc_cases' => 'entities_id'
|
||||
],
|
||||
'glpi_users' => [
|
||||
'glpi_plugin_soc_cases' => 'users_id_tech'
|
||||
],
|
||||
'glpi_groups' => [
|
||||
'glpi_plugin_soc_cases' => 'groups_id_tech'
|
||||
],
|
||||
'glpi_tickets' => [
|
||||
'glpi_plugin_soc_case_tickets' => 'tickets_id'
|
||||
],
|
||||
'glpi_changes' => [
|
||||
'glpi_plugin_soc_case_changes' => 'changes_id'
|
||||
],
|
||||
'glpi_plugin_soc_cases' => [
|
||||
'glpi_plugin_soc_case_tickets' => 'plugin_soc_cases_id',
|
||||
'glpi_plugin_soc_case_changes' => 'plugin_soc_cases_id'
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for headings (used in massive actions)
|
||||
*
|
||||
* @param string $type Item type
|
||||
* @return array
|
||||
*/
|
||||
function plugin_soc_getHaveItemtype($type) {
|
||||
switch ($type) {
|
||||
case 'PluginSocCase':
|
||||
return ['Ticket' => PluginSocCase::getTypeName(Session::getPluralNumber()),
|
||||
'Change' => PluginSocCase::getTypeName(Session::getPluralNumber())];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook for massive actions
|
||||
*
|
||||
* @param string $type Item type
|
||||
* @return array
|
||||
*/
|
||||
function plugin_soc_getMassiveActions($type) {
|
||||
switch ($type) {
|
||||
case 'Ticket':
|
||||
return [
|
||||
'PluginSocCase:add_to_case' => __('Add to SOC case', 'soc'),
|
||||
'PluginSocCase:create_from_ticket' => __('Create SOC case from ticket', 'soc')
|
||||
];
|
||||
|
||||
case 'Change':
|
||||
return [
|
||||
'PluginSocCase:add_to_case' => __('Add to SOC case', 'soc'),
|
||||
'PluginSocCase:create_from_change' => __('Create SOC case from change', 'soc')
|
||||
];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Define dropdown tables
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function plugin_soc_getDropdowns() {
|
||||
return [
|
||||
PluginSocCase::getTypeName(Session::getPluralNumber()) => [
|
||||
'table' => 'glpi_plugin_soc_cases',
|
||||
'title' => PluginSocCase::getTypeName(Session::getPluralNumber()),
|
||||
'field' => 'name',
|
||||
'linkfield' => '',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Add event to notifications
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
function plugin_soc_getEvents() {
|
||||
return [
|
||||
'new_soc_case' => __('New SOC case', 'soc'),
|
||||
'update_soc_case' => __('SOC case updated', 'soc'),
|
||||
'close_soc_case' => __('SOC case closed', 'soc'),
|
||||
];
|
||||
}
|
Reference in New Issue
Block a user