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 ''; } /** * Item update hook * * @param CommonDBTM $item Item being updated * @return void */ function plugin_soc_item_update(CommonDBTM $item) { // Handle item updates switch ($item->getType()) { case 'Ticket': case 'Change': // Custom update logic if needed break; } } /** * Item add hook * * @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) { // Handle item deletions switch ($item->getType()) { case 'Ticket': case 'Change': // Custom delete logic if needed break; } } /** * Item purge hook * * @param CommonDBTM $item Item being purged * @return void */ function plugin_soc_item_purge(CommonDBTM $item) { // 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; } } /** * Display tab content for item * * @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) { $options = []; // Add search options for supported item types if ($itemtype == 'Ticket' || $itemtype == 'Change') { $options[9000] = [ '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', 'joinparams' => [ 'jointype' => 'itemtype_item', 'specific_itemtype' => $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'), ]; }