Add a level to do for a ticket
public addLevelToDo ( Ticket $ticket, $slalevels_id ) : execution | ||
$ticket | Ticket | Ticket object |
$slalevels_id | ||
return | execution | date time (NULL if sla not exists) |
function pre_updateInDB() { // get again object to reload actors $this->loadActors(); // Setting a solution or solution type means the problem is solved if (in_array("solutiontypes_id", $this->updates) && $this->input["solutiontypes_id"] > 0 || in_array("solution", $this->updates) && !empty($this->input["solution"])) { if (!in_array('status', $this->updates)) { $this->oldvalues['status'] = $this->fields['status']; $this->updates[] = 'status'; } // Special case for Ticket : use autoclose if ($this->getType() == 'Ticket') { $autoclosedelay = Entity::getUsedConfig('autoclose_delay', $this->getEntityID(), '', Entity::CONFIG_NEVER); // 0 = immediatly if ($autoclosedelay == 0) { $this->fields['status'] = self::CLOSED; $this->input['status'] = self::CLOSED; } else { $this->fields['status'] = self::SOLVED; $this->input['status'] = self::SOLVED; } } else { $this->fields['status'] = self::SOLVED; $this->input['status'] = self::SOLVED; } } // Check dates change interval due to the fact that second are not displayed in form if (($key = array_search('date', $this->updates)) !== false && substr($this->fields["date"], 0, 16) == substr($this->oldvalues['date'], 0, 16)) { unset($this->updates[$key]); unset($this->oldvalues['date']); } if (($key = array_search('closedate', $this->updates)) !== false && substr($this->fields["closedate"], 0, 16) == substr($this->oldvalues['closedate'], 0, 16)) { unset($this->updates[$key]); unset($this->oldvalues['closedate']); } if (($key = array_search('due_date', $this->updates)) !== false && substr($this->fields["due_date"], 0, 16) == substr($this->oldvalues['due_date'], 0, 16)) { unset($this->updates[$key]); unset($this->oldvalues['due_date']); } if (($key = array_search('solvedate', $this->updates)) !== false && substr($this->fields["solvedate"], 0, 16) == substr($this->oldvalues['solvedate'], 0, 16)) { unset($this->updates[$key]); unset($this->oldvalues['solvedate']); } if (isset($this->input["status"])) { if ($this->input["status"] != self::WAITING && $this->countSuppliers(CommonITILActor::ASSIGN) == 0 && $this->countUsers(CommonITILActor::ASSIGN) == 0 && $this->countGroups(CommonITILActor::ASSIGN) == 0 && !in_array($this->fields['status'], array_merge($this->getSolvedStatusArray(), $this->getClosedStatusArray()))) { if (!in_array('status', $this->updates)) { $this->oldvalues['status'] = $this->fields['status']; $this->updates[] = 'status'; } // $this->fields['status'] = self::INCOMING; // Don't change status if it's a new status allow if (in_array($this->oldvalues['status'], $this->getNewStatusArray()) && !in_array($this->input['status'], $this->getNewStatusArray())) { $this->fields['status'] = $this->oldvalues['status']; } } if (in_array("status", $this->updates) && in_array($this->input["status"], $this->getSolvedStatusArray())) { $this->updates[] = "solvedate"; $this->oldvalues['solvedate'] = $this->fields["solvedate"]; $this->fields["solvedate"] = $_SESSION["glpi_currenttime"]; // If invalid date : set open date if ($this->fields["solvedate"] < $this->fields["date"]) { $this->fields["solvedate"] = $this->fields["date"]; } } if (in_array("status", $this->updates) && in_array($this->input["status"], $this->getClosedStatusArray())) { $this->updates[] = "closedate"; $this->oldvalues['closedate'] = $this->fields["closedate"]; $this->fields["closedate"] = $_SESSION["glpi_currenttime"]; // If invalid date : set open date if ($this->fields["closedate"] < $this->fields["date"]) { $this->fields["closedate"] = $this->fields["date"]; } // Set solvedate to closedate if (empty($this->fields["solvedate"])) { $this->updates[] = "solvedate"; $this->oldvalues['solvedate'] = $this->fields["solvedate"]; $this->fields["solvedate"] = $this->fields["closedate"]; } } } // check dates // check due_date (SLA) if ((in_array("date", $this->updates) || in_array("due_date", $this->updates)) && !is_null($this->fields["due_date"])) { // Date set if ($this->fields["due_date"] < $this->fields["date"]) { Session::addMessageAfterRedirect(__('Invalid dates. Update cancelled.'), false, ERROR); if (($key = array_search('date', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['date']); } if (($key = array_search('due_date', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['due_date']); } } } // Status close : check dates if (in_array($this->fields["status"], $this->getClosedStatusArray()) && (in_array("date", $this->updates) || in_array("closedate", $this->updates))) { // Invalid dates : no change // closedate must be > solvedate if ($this->fields["closedate"] < $this->fields["solvedate"]) { Session::addMessageAfterRedirect(__('Invalid dates. Update cancelled.'), false, ERROR); if (($key = array_search('closedate', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['closedate']); } } // closedate must be > create date if ($this->fields["closedate"] < $this->fields["date"]) { Session::addMessageAfterRedirect(__('Invalid dates. Update cancelled.'), false, ERROR); if (($key = array_search('date', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['date']); } if (($key = array_search('closedate', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['closedate']); } } } if (($key = array_search('status', $this->updates)) !== false && $this->oldvalues['status'] == $this->fields['status']) { unset($this->updates[$key]); unset($this->oldvalues['status']); } // Status solved : check dates if (in_array($this->fields["status"], $this->getSolvedStatusArray()) && (in_array("date", $this->updates) || in_array("solvedate", $this->updates))) { // Invalid dates : no change // solvedate must be > create date if ($this->fields["solvedate"] < $this->fields["date"]) { Session::addMessageAfterRedirect(__('Invalid dates. Update cancelled.'), false, ERROR); if (($key = array_search('date', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['date']); } if (($key = array_search('solvedate', $this->updates)) !== false) { unset($this->updates[$key]); unset($this->oldvalues['solvedate']); } } } // Manage come back to waiting state if (!is_null($this->fields['begin_waiting_date']) && ($key = array_search('status', $this->updates)) !== false && ($this->oldvalues['status'] == self::WAITING || in_array($this->oldvalues["status"], $this->getSolvedStatusArray()) && !in_array($this->fields["status"], $this->getClosedStatusArray()))) { // Compute ticket waiting time use calendar if exists $calendar = new Calendar(); $calendars_id = $this->getCalendar(); $delay_time = 0; // Compute ticket waiting time use calendar if exists // Using calendar if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) { $delay_time = $calendar->getActiveTimeBetween($this->fields['begin_waiting_date'], $_SESSION["glpi_currenttime"]); } else { // Not calendar defined $delay_time = strtotime($_SESSION["glpi_currenttime"]) - strtotime($this->fields['begin_waiting_date']); } // SLT case : compute slt_ttr duration if (isset($this->fields['slts_ttr_id']) && $this->fields['slts_ttr_id'] > 0) { $slt = new SLT(); if ($slt->getFromDB($this->fields['slts_ttr_id'])) { $slt->setTicketCalendar($calendars_id); $delay_time_sla = $slt->getActiveTimeBetween($this->fields['begin_waiting_date'], $_SESSION["glpi_currenttime"]); $this->updates[] = "sla_waiting_duration"; $this->fields["sla_waiting_duration"] += $delay_time_sla; } // Compute new due date $this->updates[] = "due_date"; $this->fields['due_date'] = $slt->computeDate($this->fields['date'], $this->fields["sla_waiting_duration"]); // Add current level to do $slt->addLevelToDo($this); } else { // Using calendar if ($calendars_id > 0 && $calendar->getFromDB($calendars_id)) { if ($this->fields['due_date'] > 0) { // compute new due date using calendar $this->updates[] = "due_date"; $this->fields['due_date'] = $calendar->computeEndDate($this->fields['due_date'], $delay_time); } } else { // Not calendar defined if ($this->fields['due_date'] > 0) { // compute new due date : no calendar so add computed delay_time $this->updates[] = "due_date"; $this->fields['due_date'] = date('Y-m-d H:i:s', $delay_time + strtotime($this->fields['due_date'])); } } } $this->updates[] = "waiting_duration"; $this->fields["waiting_duration"] += $delay_time; // Reset begin_waiting_date $this->updates[] = "begin_waiting_date"; $this->fields["begin_waiting_date"] = 'NULL'; } // Set begin waiting date if needed if (($key = array_search('status', $this->updates)) !== false && ($this->fields['status'] == self::WAITING || in_array($this->fields["status"], $this->getSolvedStatusArray()))) { $this->updates[] = "begin_waiting_date"; $this->fields["begin_waiting_date"] = $_SESSION["glpi_currenttime"]; // Specific for tickets if (isset($this->fields['slts_ttr_id']) && $this->fields['slts_ttr_id'] > 0) { SLT::deleteLevelsToDo($this); } } // solve_delay_stat : use delay between opendate and solvedate if (in_array("solvedate", $this->updates)) { $this->updates[] = "solve_delay_stat"; $this->fields['solve_delay_stat'] = $this->computeSolveDelayStat(); } // close_delay_stat : use delay between opendate and closedate if (in_array("closedate", $this->updates)) { $this->updates[] = "close_delay_stat"; $this->fields['close_delay_stat'] = $this->computeCloseDelayStat(); } // Do not take into account date_mod if no update is done if (count($this->updates) == 1 && ($key = array_search('date_mod', $this->updates)) !== false) { unset($this->updates[$key]); } }
/** * Manage SLT level escalation * * @since version 9.1 * * @param $slts_id **/ function manageSltLevel($slts_id) { $calendars_id = Entity::getUsedConfig('calendars_id', $this->fields['entities_id']); // Add first level in working table $slalevels_id = SlaLevel::getFirstSltLevel($slts_id); $slt = new SLT(); if ($slt->getFromDB($slts_id)) { $slt->setTicketCalendar($calendars_id); $slt->addLevelToDo($this, $slalevels_id); } SlaLevel_Ticket::replayForTicket($this->getID(), $slt->getField('type')); }
/** * Do a specific SLAlevel for a ticket * * @param $data array data of an entry of slalevels_tickets * @param $sltType Type of slt * * @since version 9.1 2 parameters mandatory * * @return nothing **/ static function doLevelForTicket(array $data, $sltType) { $ticket = new Ticket(); $slalevelticket = new self(); // existing ticket and not deleted if ($ticket->getFromDB($data['tickets_id']) && !$ticket->isDeleted()) { // search all actors of a ticket foreach ($ticket->getUsers(CommonITILActor::REQUESTER) as $user) { $ticket->fields['_users_id_requester'][] = $user['users_id']; } foreach ($ticket->getUsers(CommonITILActor::ASSIGN) as $user) { $ticket->fields['_users_id_assign'][] = $user['users_id']; } foreach ($ticket->getUsers(CommonITILActor::OBSERVER) as $user) { $ticket->fields['_users_id_observer'][] = $user['users_id']; } foreach ($ticket->getGroups(CommonITILActor::REQUESTER) as $group) { $ticket->fields['_groups_id_requester'][] = $group['groups_id']; } foreach ($ticket->getGroups(CommonITILActor::ASSIGN) as $group) { $ticket->fields['_groups_id_assign'][] = $group['groups_id']; } foreach ($ticket->getGroups(CommonITILActor::OBSERVER) as $group) { $ticket->fields['_groups_id_observer'][] = $group['groups_id']; } foreach ($ticket->getSuppliers(CommonITILActor::ASSIGN) as $supplier) { $ticket->fields['_suppliers_id_assign'][] = $supplier['suppliers_id']; } $slalevel = new SlaLevel(); $slt = new SLT(); // Check if slt datas are OK list($dateField, $sltField) = SLT::getSltFieldNames($sltType); if ($ticket->fields[$sltField] > 0) { if ($ticket->fields['status'] == CommonITILObject::CLOSED) { // Drop line when status is closed $slalevelticket->delete(array('id' => $data['id'])); } else { if ($ticket->fields['status'] != CommonITILObject::SOLVED) { // No execution if ticket has been taken into account if (!($sltType == SLT::TTO && $ticket->fields['takeintoaccount_delay_stat'] > 0)) { // If status = solved : keep the line in case of solution not validated $input['id'] = $ticket->getID(); $input['_auto_update'] = true; if ($slalevel->getRuleWithCriteriasAndActions($data['slalevels_id'], 1, 1) && $slt->getFromDB($ticket->fields[$sltField])) { $doit = true; if (count($slalevel->criterias)) { $doit = $slalevel->checkCriterias($ticket->fields); } // Process rules if ($doit) { $input = $slalevel->executeActions($input, array()); } } // Put next level in todo list $next = $slalevel->getNextSltLevel($ticket->fields[$sltField], $data['slalevels_id']); $slt->addLevelToDo($ticket, $next); // Action done : drop the line $slalevelticket->delete(array('id' => $data['id'])); $ticket->update($input); } else { // Drop line $slalevelticket->delete(array('id' => $data['id'])); } } } } else { // Drop line $slalevelticket->delete(array('id' => $data['id'])); } } else { // Drop line $slalevelticket->delete(array('id' => $data['id'])); } }