. * --------------------------------------------------------------------- */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * SlaLevel class **/ class SlaLevel extends LevelAgreementLevel { protected $rules_id_field = 'slalevels_id'; protected $ruleactionclass = 'SlaLevelAction'; static protected $parentclass = 'SLA'; static protected $fkparent = 'slas_id'; // No criteria protected $rulecriteriaclass = 'SlaLevelCriteria'; static function getTable($classname = null) { return CommonDBTM::getTable(__CLASS__); } function cleanDBonPurge() { parent::cleanDBonPurge(); // SlaLevel_Ticket does not extends CommonDBConnexity $slt = new SlaLevel_Ticket(); $slt->deleteByCriteria([$this->rules_id_field => $this->fields['id']]); } function showForParent(SLA $sla) { return $this->showForSLA($sla); } /** * @param $sla SLA object * * @since 9.1 (before showForSLA) **/ function showForSLA(SLA $sla) { global $DB; $ID = $sla->getField('id'); if (!$sla->can($ID, READ)) { return false; } $canedit = $sla->can($ID, UPDATE); $rand = mt_rand(); if ($canedit) { echo "
"; echo "
"; echo ""; echo ""; echo ""; echo "
".__('Add an escalation level')."
".__('Name').""; echo ""; echo ""; echo ""; echo ""; echo ""; echo "".__('Execution').""; $delay = $sla->getTime(); self::dropdownExecutionTime('execution_time', ['max_time' => $delay, 'used' => self::getAlreadyUsedExecutionTime($sla->fields['id']), 'type' => $sla->fields['type']]); echo "".__('Active').""; Dropdown::showYesNo("is_active", 1); echo ""; echo ""; echo "
"; Html::closeForm(); echo "
"; } $iterator = $DB->request([ 'FROM' => self::getTable(), 'WHERE' => [ 'slas_id' => $ID ], 'ORDER' => 'execution_time' ]); $numrows = count($iterator); echo "
"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = ['num_displayed' => min($_SESSION['glpilist_limit'], $numrows), 'container' => 'mass'.__CLASS__.$rand]; Html::showMassiveActions($massiveactionparams); } echo ""; echo ""; if ($canedit && $numrows) { echo ""; } echo ""; echo ""; echo ""; echo ""; Session::initNavigateListItems('SlaLevel', //TRANS: %1$s is the itemtype name, %2$s is the name of the item (used for headings of a list) sprintf(__('%1$s = %2$s'), SLA::getTypeName(1), $sla->getName())); while ($data = $iterator->next()) { Session::addToNavigateListItems('SlaLevel', $data["id"]); echo ""; if ($canedit) { echo ""; } echo ""; echo ""; echo ""; echo ""; echo ""; } echo "
".Html::getCheckAllAsCheckbox('mass'.__CLASS__.$rand)."".__('Name')."".__('Execution')."".__('Active')."
".Html::getMassiveActionCheckBox(__CLASS__, $data["id"]).""; if ($canedit) { echo ""; } echo $data["name"]; if (empty($data["name"])) { echo "(".$data['id'].")"; } if ($canedit) { echo ""; } echo "".($data["execution_time"] != 0 ? Html::timestampToString($data["execution_time"], false) : ($sla->fields['type'] == 1 ? __('Time to own') : __('Time to resolve'))). "".Dropdown::getYesNo($data["is_active"])."
"; $this->getRuleWithCriteriasAndActions($data['id'], 1, 1); $this->showCriteriasList($data["id"], ['readonly' => true]); echo ""; $this->showActionsList($data["id"], ['readonly' => true]); echo "
"; if ($canedit && $numrows) { $massiveactionparams['ontop'] = false; Html::showMassiveActions($massiveactionparams); Html::closeForm(); } echo "
"; } function getActions() { $actions = parent::getActions(); unset($actions['slas_id']); $actions['recall']['name'] = __('Automatic reminders of SLA'); $actions['recall']['type'] = 'yesonly'; $actions['recall']['force_actions'] = ['send']; return $actions; } /** * Show the rule * * @param $ID ID of the rule * @param $options array of possible options * * @return void **/ function showForm($ID, $options = []) { $canedit = $this->can('sla', UPDATE); $this->initForm($ID, $options); $this->showFormHeader($options); echo ""; echo "".__('Name').""; echo ""; Html::autocompletionTextField($this, "name"); echo ""; echo "".__('Active').""; echo ""; Dropdown::showYesNo("is_active", $this->fields["is_active"]); echo"\n"; $sla = new SLA(); $sla->getFromDB($this->fields['slas_id']); echo ""; echo "".SLA::getTypeName(1).""; echo "".$sla->getLink().""; echo "".__('Execution').""; echo ""; $delay = $sla->getTime(); self::dropdownExecutionTime('execution_time', ['max_time' => $delay, 'used' => self::getAlreadyUsedExecutionTime($sla->fields['id']), 'value' => $this->fields['execution_time'], 'type' => $sla->fields['type']]); echo "\n"; echo ""; echo "".__('Logical operator').""; echo ""; $this->dropdownRulesMatch(['value' => $this->fields["match"]]); echo ""; echo " "; $this->showFormButtons($options); } /** * Get first level for a SLA * * @param $slas_id integer id of the SLA * * @since 9.1 (before getFirst SlaLevel) * * @return id of the sla level : 0 if not exists **/ static function getFirstSlaLevel($slas_id) { global $DB; $iterator = $DB->request([ 'SELECT' => 'id', 'FROM' => self::getTable(), 'WHERE' => [ 'slas_id' => $slas_id, 'is_active' => 1 ], 'ORDER' => 'execution_time ASC', 'LIMIT' => 1 ]); if ($result = $iterator->next()) { return $result['id']; } return 0; } /** * Get next level for a SLA * * @param $slas_id integer id of the SLA * @param $slalevels_id integer id of the current SLA level * * @return id of the sla level : 0 if not exists **/ static function getNextSlaLevel($slas_id, $slalevels_id) { global $DB; $iterator = $DB->request([ 'SELECT' => 'execution_time', 'FROM' => self::getTable(), 'WHERE' => ['id' => $slalevels_id] ]); if ($result = $iterator->next()) { $execution_time = $result['execution_time']; $lvl_iterator = $DB->request([ 'SELECT' => 'id', 'FROM' => self::getTable(), 'WHERE' => [ 'slas_id' => $slas_id, 'is_active' => 1, 'id' => ['<>', $slalevels_id], 'execution_time' => ['>', $execution_time] ], 'ORDER' => 'execution_time ASC', 'LIMIT' => 1 ]); if ($result = $lvl_iterator->next()) { return $result['id']; } } return 0; } }