. * --------------------------------------------------------------------- */ /** * @since 9.2 */ if (!defined('GLPI_ROOT')) { die("Sorry. You can't access this file directly"); } /** * OlaLevel class **/ class OlaLevel extends LevelAgreementLevel { protected $rules_id_field = 'olalevels_id'; protected $ruleactionclass = 'OlaLevelAction'; static protected $parentclass = 'OLA'; static protected $fkparent = 'olas_id'; // No criteria protected $rulecriteriaclass = 'OlaLevelCriteria'; static function getTable($classname = null) { return CommonDBTM::getTable(__CLASS__); } function cleanDBonPurge() { parent::cleanDBonPurge(); // OlaLevel_Ticket does not extends CommonDBConnexity $olt = new OlaLevel_Ticket(); $olt->deleteByCriteria([$this->rules_id_field => $this->fields['id']]); } function showForParent(OLA $ola) { return $this->showForOLA($ola); } /** * @param $ola OLA object * * @since 9.1 (before showForOLA) **/ function showForOLA(OLA $ola) { global $DB; $ID = $ola->getField('id'); if (!$ola->can($ID, READ)) { return false; } $canedit = $ola->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 = $ola->getTime(); self::dropdownExecutionTime('execution_time', ['max_time' => $delay, 'used' => self::getAlreadyUsedExecutionTime($ola->fields['id'])]); echo "".__('Active').""; Dropdown::showYesNo("is_active", 1); echo ""; echo ""; echo "
"; Html::closeForm(); echo "
"; } $iterator = $DB->request([ 'FROM' => 'glpi_olalevels', 'WHERE' => ['olas_id' => $ID], 'ORDER' => 'execution_time' ]); $numrows = count($iterator); echo "
"; if ($canedit && $numrows) { Html::openMassiveActionsForm('mass'.__CLASS__.$rand); $massiveactionparams = ['num_displayed' => $numrows, 'container' => 'mass'.__CLASS__.$rand]; Html::showMassiveActions($massiveactionparams); } echo ""; echo ""; if ($canedit && $numrows) { echo ""; } echo ""; echo ""; echo ""; echo ""; Session::initNavigateListItems('OlaLevel', //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'), OLA::getTypeName(1), $ola->getName())); while ($data = $iterator->next()) { Session::addToNavigateListItems('OlaLevel', $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) : ($ola->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['olas_id']); $actions['recall_ola']['name'] = __('Automatic reminders of OLA'); $actions['recall_ola']['type'] = 'yesonly'; $actions['recall_ola']['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 = []) { $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"; $ola = new OLA(); $ola->getFromDB($this->fields['olas_id']); echo ""; echo "".OLA::getTypeName(1).""; echo "".$ola->getLink().""; echo "".__('Execution').""; echo ""; $delay = $ola->getTime(); self::dropdownExecutionTime('execution_time', ['max_time' => $delay, 'used' => self::getAlreadyUsedExecutionTime($ola->fields['id']), 'value' => $this->fields['execution_time']]); echo "\n"; echo ""; echo "".__('Logical operator').""; echo ""; $this->dropdownRulesMatch(['value' => $this->fields["match"]]); echo ""; echo " "; $this->showFormButtons($options); } /** * Get first level for a OLA * * @param $olas_id integer id of the OLA * * @since 9.1 (before getFirst OlaLevel) * * @return id of the ola level : 0 if not exists **/ static function getFirstOlaLevel($olas_id) { global $DB; $iterator = $DB->request([ 'SELECT' => 'id', 'FROM' => 'glpi_olalevels', 'WHERE' => [ 'olas_id' => $olas_id, 'is_active' => 1 ], 'ORDER' => 'execution_time ASC', 'LIMIT' => 1 ]); if (count($iterator)) { $result = $iterator->next(); return $result['id']; } return 0; } /** * Get next level for a OLA * * @param $olas_id integer id of the OLA * @param $olalevels_id integer id of the current OLA level * * @return id of the ola level : 0 if not exists **/ static function getNextOlaLevel($olas_id, $olalevels_id) { global $DB; $iterator = $DB->request([ 'SELECT' => 'execution_time', 'FROM' => 'glpi_olalevels', 'WHERE' => ['id' => $olalevels_id] ]); if (count($iterator)) { $result = $iterator->next(); $execution_time = $result['execution_time']; $iterator = $DB->request([ 'SELECT' => 'id', 'FROM' => 'glpi_olalevels', 'WHERE' => [ 'olas_id' => $olas_id, 'id' => ['<>', $olalevels_id], 'execution_time' => ['>', $execution_time], 'is_active' => 1 ], 'ORDER' => 'execution_time ASC', 'LIMIT' => 1 ]); if (count($iterator)) { $result = $iterator->next(); return $result['id']; } } return 0; } }