diff --git a/service/ServiceSupervisorPBx.php b/service/ServiceSupervisorPBx.php index 44d7fe5..f3102a7 100644 --- a/service/ServiceSupervisorPBx.php +++ b/service/ServiceSupervisorPBx.php @@ -16,18 +16,24 @@ class ServiceSupervisorPBx implements IService $this->supervisorModel = new SupervisorModel; $agentes = $this->supervisorModel->listaAgentesDisponivel(null, false); foreach ($agentes as $key => $agente) { - $agentPbx = $this->validaAgentCriado($agente->matricula); - if (!$agentPbx) { - $this->criaRegistroSupervisor($agente); + if ($this->validaInatividade($agente->duracao)) { + $agentPbx = $this->validaAgentCriado($agente->matricula); + if (!$agentPbx) { + $this->criaRegistroSupervisor($agente); + } else { + $this->atualizaTabelaSupervisor($agente, $agentPbx); + } } else { - $this->atualizaTabelaSupervisor($agente, $agentPbx); + $this->supervisorModel->deleteAgent($agente->matricula); } } $agentesPbx = $this->supervisorModel->findAllAgentesPBX(); foreach ($agentesPbx as $key => $pbx) { - $age = $this->supervisorModel->findAgentByMatricula($pbx->matricula); - if (empty($age) && empty($pbx->ramal)) { - $this->supervisorModel->deleteAgentPbx($pbx->matricula); + if (empty($pbx->ramal)) { + $age = $this->supervisorModel->findAgentByMatricula($pbx->matricula); + if (empty($age) && empty($pbx->ramal)) { + $this->supervisorModel->deleteAgentPbx($pbx->matricula); + } } } } @@ -84,4 +90,13 @@ class ServiceSupervisorPBx implements IService } return 0; } + + function validaInatividade($dateTime) + { + $timealert = strtotime($dateTime . '+40 seconds'); + if ($timealert < strtotime(date('Y-m-d H:i:s'))) { + return false; + } + return true; + } } \ No newline at end of file