|
|
@ -30,7 +30,7 @@ class CallController |
|
|
|
|
|
|
|
|
|
|
|
function listarBilhetes(Request $request, Response $response, array $args) |
|
|
|
function listarBilhetes(Request $request, Response $response, array $args) |
|
|
|
{ |
|
|
|
{ |
|
|
|
self::$logger->debug('Org id do token: ' . print_r($request->getAttribute('orgs'), true), true); |
|
|
|
//self::$logger->debug('Org id do token: ' . print_r($request->getAttribute('orgs'), true), true); |
|
|
|
try { |
|
|
|
try { |
|
|
|
$validator = new Validator(); |
|
|
|
$validator = new Validator(); |
|
|
|
$validator->mapFieldsRules([ |
|
|
|
$validator->mapFieldsRules([ |
|
|
@ -38,9 +38,9 @@ class CallController |
|
|
|
'uniqueid' => [], |
|
|
|
'uniqueid' => [], |
|
|
|
'src' => [], |
|
|
|
'src' => [], |
|
|
|
'dst' => [], |
|
|
|
'dst' => [], |
|
|
|
'i_date' => ['date'], |
|
|
|
'data_i' => ['date'], |
|
|
|
'f_date' => ['date'], |
|
|
|
'data_f' => ['date'], |
|
|
|
'entry' => [], |
|
|
|
'entrada' => [], |
|
|
|
'org_id' => ['integer', 'required'] |
|
|
|
'org_id' => ['integer', 'required'] |
|
|
|
]); |
|
|
|
]); |
|
|
|
|
|
|
|
|
|
|
@ -52,17 +52,10 @@ class CallController |
|
|
|
return $response->withStatus(422); |
|
|
|
return $response->withStatus(422); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
self::$logger->debug('Passed in bilhetes validation', true); |
|
|
|
self::$logger->debug('Passed in bilhetes validation with body: ' . print_r($body, true), true); |
|
|
|
|
|
|
|
|
|
|
|
$result = Bilhetes::getBilhetes($body); |
|
|
|
$result = Bilhetes::getBilhetes($body); |
|
|
|
$response->getBody()->write(json_encode(['status' => true, 'data' => $result])); |
|
|
|
$response->getBody()->write(json_encode(['status' => true, 'data' => $result])); |
|
|
|
|
|
|
|
|
|
|
|
//this block returns an error message if the result of the query is empty |
|
|
|
|
|
|
|
/*if (!$result) { |
|
|
|
|
|
|
|
$response->getBody()->write(json_encode(['status' => false, 'data' => ['message' => 'Nenhum resultado encontrado!']])); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$response->getBody()->write(json_encode(['status' => true, 'data' => $result])); |
|
|
|
|
|
|
|
} */ |
|
|
|
|
|
|
|
} catch (Exception $e) { |
|
|
|
} catch (Exception $e) { |
|
|
|
$response->getBody()->write(json_encode(['status' => false, 'data' => ["message" => "Nao foi possivel realizar a consulta! " . $e->getMessage()]])); |
|
|
|
$response->getBody()->write(json_encode(['status' => false, 'data' => ["message" => "Nao foi possivel realizar a consulta! " . $e->getMessage()]])); |
|
|
|
return $response->withStatus(500); |
|
|
|
return $response->withStatus(500); |
|
|
@ -73,42 +66,30 @@ class CallController |
|
|
|
public function listarEventos(Request $request, Response $response, array $args) |
|
|
|
public function listarEventos(Request $request, Response $response, array $args) |
|
|
|
{ |
|
|
|
{ |
|
|
|
try { |
|
|
|
try { |
|
|
|
$body = json_decode($request->getBody()->getContents(), true); |
|
|
|
$validator = new Validator(); |
|
|
|
//$dados = $this->validateData($request, true); |
|
|
|
$validator->mapFieldsRules([ |
|
|
|
$query = "SELECT |
|
|
|
'id' => ['integer', ['min', 1]], |
|
|
|
a.id_bilhetes AS id, |
|
|
|
'fila' => [], |
|
|
|
a.uniqueid, |
|
|
|
'entrada' => [], |
|
|
|
c.id AS fila_id, |
|
|
|
'uniqueid' => [], |
|
|
|
b.fila, |
|
|
|
'src' => [], |
|
|
|
d.nome, |
|
|
|
'dst' => [], |
|
|
|
d.apelido AS login, |
|
|
|
'data_i' => ['date'], |
|
|
|
SUBSTRING(b.agente,7,4) AS matricula, |
|
|
|
'data_f' => ['date'], |
|
|
|
b.evento AS evento, |
|
|
|
'org_id' => ['integer', 'required'] |
|
|
|
b.param1 AS param1, |
|
|
|
]); |
|
|
|
b.param2 AS param2, |
|
|
|
|
|
|
|
b.param3 AS param3, |
|
|
|
|
|
|
|
b.param4 AS param4 |
|
|
|
|
|
|
|
FROM pbx_bilhetes a |
|
|
|
|
|
|
|
INNER JOIN pbx_eventos_dacs b ON a.uniqueid = b.uid2 |
|
|
|
|
|
|
|
INNER JOIN pbx_dacs c ON c.nome = b.fila |
|
|
|
|
|
|
|
INNER JOIN pbx_usuarios d ON d.matricula = SUBSTRING(b.agente,7,4) |
|
|
|
|
|
|
|
WHERE evento IN ('ABANDON','COMPLETEAGENT','COMPLETECALLER','CONNECT','ENTERQUEUE', |
|
|
|
|
|
|
|
'EXITWITHTIMEOUT', 'TRANSBORDANDO', 'TRANSBORDADO','TRANSFER', 'TRANSFERORIG', |
|
|
|
|
|
|
|
'COMPLETACALLER', 'COMPLETAAGENT', 'ANSWERED', 'BUSYS', 'NOANSWERS') "; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$dados['org_id'] = $body['org_id']; |
|
|
|
$body = json_decode($request->getBody()->getContents(), true); |
|
|
|
$data = Bilhetes::query($query, $dados); |
|
|
|
$validator = $validator->withData($body); |
|
|
|
foreach ($dados as $k => $v) { |
|
|
|
if (!$validator->validate()) { |
|
|
|
if ($v) { |
|
|
|
$response->getBody() |
|
|
|
$query .= " AND $k = :$k"; |
|
|
|
->write(json_encode($validator->errors())); |
|
|
|
} |
|
|
|
return $response->withStatus(422); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!$data) { |
|
|
|
self::$logger->debug('Passed in bilhetes validation with body: ' . print_r($body, true), true); |
|
|
|
$response->getBody()->write(json_encode(['status' => false, 'data' => ['message' => 'Nenhum resultado encontrado!']])); |
|
|
|
$result = Bilhetes::getEventosBilhetes($body); |
|
|
|
} else { |
|
|
|
$response->getBody()->write(json_encode(['status' => true, 'data' => $result])); |
|
|
|
$response->getBody()->write(json_encode(['status' => true, 'data' => $data])); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} catch (Exception $e) { |
|
|
|
} catch (Exception $e) { |
|
|
|
$response->getBody()->write(json_encode(['status' => false, 'data' => ["message" => "Nao foi possivel realizar a consulta! " . $e->getMessage()]])); |
|
|
|
$response->getBody()->write(json_encode(['status' => false, 'data' => ["message" => "Nao foi possivel realizar a consulta! " . $e->getMessage()]])); |
|
|
|
} |
|
|
|
} |
|
|
|