__('Critical', 'soc'),
self::SEVERITY_HIGH => __('High', 'soc'),
self::SEVERITY_MEDIUM => __('Medium', 'soc'),
self::SEVERITY_LOW => __('Low', 'soc')
];
}
/**
* Get status options
*
* @return array
*/
static function getStatusOptions() {
return [
self::STATUS_NEW => __('New', 'soc'),
self::STATUS_ASSIGNED => __('Assigned', 'soc'),
self::STATUS_IN_PROGRESS => __('In Progress', 'soc'),
self::STATUS_PENDING => __('Pending', 'soc'),
self::STATUS_RESOLVED => __('Resolved', 'soc'),
self::STATUS_CLOSED => __('Closed', 'soc')
];
}
/**
* Show form
*
* @param integer $ID
* @param array $options
* @return boolean
*/
function showForm($ID, $options = []) {
global $CFG_GLPI;
$this->initForm($ID, $options);
$this->showFormHeader($options);
echo "
";
echo "" . __('Name') . " | ";
echo "";
echo Html::input('name', ['value' => $this->fields['name']]);
echo " | ";
echo "" . __('Status') . " | ";
echo "";
Dropdown::showFromArray('status', self::getStatusOptions(), ['value' => $this->fields['status']]);
echo " | ";
echo "
";
echo "";
echo "" . __('Severity', 'soc') . " | ";
echo "";
Dropdown::showFromArray('severity', self::getSeverityOptions(), ['value' => $this->fields['severity']]);
echo " | ";
echo "" . __('Technician') . " | ";
echo "";
User::dropdown(['name' => 'users_id_tech',
'value' => $this->fields['users_id_tech'],
'entity' => $this->fields['entities_id'],
'right' => 'interface']);
echo " | ";
echo "
";
echo "";
echo "" . __('Description') . " | ";
echo "";
Html::textarea([
'name' => 'description',
'value' => $this->fields['description'],
'cols' => 125,
'rows' => 5
]);
echo " | ";
echo "
";
$this->showFormButtons($options);
return true;
}
/**
* Get search options
*
* @return array
*/
function rawSearchOptions() {
$tab = [];
$tab[] = [
'id' => 'common',
'name' => self::getTypeName(2)
];
$tab[] = [
'id' => '1',
'table' => $this->getTable(),
'field' => 'name',
'name' => __('Name'),
'datatype' => 'itemlink',
'massiveaction' => false
];
$tab[] = [
'id' => '2',
'table' => $this->getTable(),
'field' => 'id',
'name' => __('ID'),
'massiveaction' => false,
'datatype' => 'number'
];
$tab[] = [
'id' => '3',
'table' => $this->getTable(),
'field' => 'severity',
'name' => __('Severity', 'soc'),
'datatype' => 'specific',
'searchtype' => ['equals', 'notequals']
];
$tab[] = [
'id' => '4',
'table' => $this->getTable(),
'field' => 'status',
'name' => __('Status'),
'datatype' => 'specific',
'searchtype' => ['equals', 'notequals']
];
$tab[] = [
'id' => '5',
'table' => $this->getTable(),
'field' => 'date_creation',
'name' => __('Creation date'),
'datatype' => 'datetime',
'massiveaction' => false
];
$tab[] = [
'id' => '6',
'table' => $this->getTable(),
'field' => 'date_mod',
'name' => __('Last update'),
'datatype' => 'datetime',
'massiveaction' => false
];
$tab[] = [
'id' => '7',
'table' => 'glpi_users',
'field' => 'name',
'linkfield' => 'users_id_tech',
'name' => __('Technician'),
'datatype' => 'dropdown'
];
return $tab;
}
/**
* Create a ticket from this case
*
* @param array $input
* @return integer|boolean
*/
function createTicket($input) {
$ticket = new Ticket();
$ticket_input = [
'name' => sprintf(__('[SOC Case #%s] %s', 'soc'), $this->fields['id'], $this->fields['name']),
'content' => $this->fields['description'],
'entities_id' => $this->fields['entities_id'],
'urgency' => self::mapSeverityToUrgency($this->fields['severity']),
'users_id_recipient' => Session::getLoginUserID()
];
$tickets_id = $ticket->add($ticket_input);
if ($tickets_id) {
$this->addTicket($tickets_id);
return $tickets_id;
}
return false;
}
/**
* Create a change from this case
*
* @param array $input
* @return integer|boolean
*/
function createChange($input) {
$change = new Change();
$change_input = [
'name' => sprintf(__('[SOC Case #%s] %s', 'soc'), $this->fields['id'], $this->fields['name']),
'content' => $this->fields['description'],
'entities_id' => $this->fields['entities_id'],
'urgency' => self::mapSeverityToUrgency($this->fields['severity']),
'users_id_recipient' => Session::getLoginUserID()
];
$changes_id = $change->add($change_input);
if ($changes_id) {
$this->addChange($changes_id);
return $changes_id;
}
return false;
}
/**
* Map SOC severity to GLPI urgency
*
* @param string $severity
* @return integer
*/
static function mapSeverityToUrgency($severity) {
switch ($severity) {
case self::SEVERITY_CRITICAL:
return 5; // Very high
case self::SEVERITY_HIGH:
return 4; // High
case self::SEVERITY_MEDIUM:
return 3; // Medium
case self::SEVERITY_LOW:
return 2; // Low
default:
return 3; // Medium by default
}
}
/**
* Add a ticket to this case
*
* @param integer $tickets_id
* @return boolean
*/
function addTicket($tickets_id) {
global $DB;
$case_ticket = new PluginSocCaseTicket();
return $case_ticket->add([
'plugin_soc_cases_id' => $this->fields['id'],
'tickets_id' => $tickets_id,
'date_creation' => $_SESSION["glpi_currenttime"]
]);
}
/**
* Add a change to this case
*
* @param integer $changes_id
* @return boolean
*/
function addChange($changes_id) {
global $DB;
$case_change = new PluginSocCaseChange();
return $case_change->add([
'plugin_soc_cases_id' => $this->fields['id'],
'changes_id' => $changes_id,
'date_creation' => $_SESSION["glpi_currenttime"]
]);
}
/**
* Display tab content for item
*
* @param CommonGLPI $item
* @param integer $tabnum
* @param integer $withtemplate
* @return boolean
*/
static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
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;
}
}