You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
1.6 KiB
63 lines
1.6 KiB
<?php |
|
|
|
namespace app\Middleware; |
|
|
|
use app\Interfaces\IApi; |
|
use app\Models\Supervisor; |
|
|
|
|
|
class ApiSupervisor implements IApi |
|
{ |
|
public $supervisor; |
|
|
|
public function __construct() |
|
{ |
|
$this->supervisor = new Supervisor(); |
|
} |
|
|
|
function router($rota, $request) |
|
{ |
|
switch ($rota) { |
|
case 'listarAgentesDisponivel': |
|
$this->listaAgentesDisponivel(); |
|
break; |
|
default: |
|
echo json_encode(['status' => '404']); |
|
break; |
|
} |
|
} |
|
function listaAgentesDisponivel() |
|
{; |
|
try { |
|
$ret = $this->supervisor->listaAgentesDisponivel(); |
|
$agentes = []; |
|
foreach ($ret as $key => $value) { |
|
array_push($agentes, $value); |
|
} |
|
$this->retorno( |
|
$agentes ? "Sucesso" : "Nenhum agente disponivel", |
|
$agentes ? $agentes : null, |
|
$agentes ? $agentes : null |
|
); |
|
} catch (\Exception $th) { |
|
$this->retorno($th->getMessage()); |
|
} |
|
return null; |
|
} |
|
|
|
function retorno($mensagem, $status = null, $dados = null) |
|
{ |
|
//{ "status": "success", "message": "register created!", "data": [ "id": 20 ] } |
|
$data = []; |
|
$data['message'] = utf8_encode($mensagem); |
|
if (!empty($status)) { |
|
$data['status'] = "success"; |
|
} else { |
|
$data['status'] = "error"; |
|
} |
|
if (!empty($dados)) { |
|
$data['data'] = $dados; |
|
} |
|
echo json_encode($data); |
|
} |
|
} |