supervisorModel = new SupervisorModel; $agentes = $this->supervisorModel->listaAgentesDisponivel(null, false); foreach ($agentes as $key => $agente) { if ($this->validaInatividade($agente->duracao)) { $agentPbx = $this->validaAgentCriado($agente->matricula); if (!$agentPbx) { $this->criaRegistroSupervisor($agente); } else { $this->atualizaTabelaSupervisor($agente, $agentPbx); } } else { $this->supervisorModel->deleteAgent($agente->matricula); } } $agentesPbx = $this->supervisorModel->findAllAgentesPBX(null, CONF_MEDIA_PBX); foreach ($agentesPbx as $key => $pbx) { $age = $this->supervisorModel->findAgentByMatricula($pbx->matricula); if (empty($age)) { $this->supervisorModel->deleteAgentPbx($pbx->matricula); } } } catch (\Exception $ex) { logger('ServiceSupervisorPBx')->info($ex->getMessage(), debug_backtrace()); } } function atualizaTabelaSupervisor($agente, $agentePbx) { $this->supervisorModel->updateAgent2( $agente->matricula, $agente->ramal, $agente->fila, $agente->status, $agente->status != $agentePbx->status, $agente->motivo_pausa, $this->retornaQuantidadeAtendimento($agente->matricula), $this->statusDisponivelFila($agente) ); } function criaRegistroSupervisor($agente) { $this->supervisorModel->addAgent2( $agente->nome, $agente->matricula, $agente->ramal, $agente->fila, $agente->tempo_login, $agente->status, $agente->motivo_pausa, $this->retornaQuantidadeAtendimento($agente->matricula) ); } function retornaQuantidadeAtendimento($matricula, $retornaBool = false) { $atendimentoModel = new Atendimento(); $paratroModel = new Parametros(); $atendimentos = $atendimentoModel->getAtendimentoAbertoByAgente($matricula); $parametros = $paratroModel->findProtocolByParams(); $count = count($atendimentos); if ($retornaBool) { return $count < $parametros->prm_media_simultaneo; } return "$count/{$parametros->prm_media_simultaneo}"; } function validaAgentCriado($matricula) { return $this->supervisorModel->findAgentByMatriculaPbx($matricula); } function statusDisponivelFila($agente) { if ($agente->status == 'LIVRE' && $this->retornaQuantidadeAtendimento($agente->matricula, true)) { return 1; } return 0; } function validaInatividade($dateTime) { $timealert = strtotime($dateTime . '+70 seconds'); if ($timealert < strtotime(date('Y-m-d H:i:s'))) { return false; } return true; } }