PABX da Simples IP
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.
 
 
 
 
 
 

52 lines
1.8 KiB

<?php
namespace app\traits;
use app\models\Parametro;
use Slim\Psr7\Request;
use Exception;
trait Validate
{
public function validateData(array $body, array $filters = [], bool $date = false): array
{
$parametro = Parametro::find(['org_id' => $body['org_id']], ['prm_max_dias_relatorio']);
$dates = [];
if (empty($filters)) {
$filters = [
'id', 'uniqueid', 'origem', 'destino',
'fila', 'org_id', 'data_inicial',
'data_final', 'agente', 'apelido',
'nome', 'ramal', 'evento'
];
}
foreach ($body as $k => $v) {
if (!in_array($k, $filters)) {
throw new Exception("O parametro informado e invalido [$k]!");
}
}
if ($date) {
$dates['data_inicial'] = $body['data_inicial'] ?? date('Y-m-d H:i:s');
$dates['data_final'] = $body['data_final'] ?? date('Y-m-d H:i:s');
if (($body['data_inicial'] && $body['data_final']) && strtotime($body['data_inicial']) > strtotime($body['data_final'])) {
throw new Exception('A [data_inicial] nao pode ser maior que [data_final]!');
}
if ($body['data_final'] && strtotime($datas['data_inicial']) > strtotime($body['data_final'])) {
throw new Exception('Informe o parametro de [data_inicial]!');
}
if ($parametro->prm_max_dias_relatorio) {
if (strtotime($dates['data_inicial']) > strtotime($body['data_inicial'] . "+" . $parametro->prm_max_dias_relatorio . "days")) {
throw new Exception("O periodo nao pode ultrapassar " . $parametro->prm_max_dias_relatorio . " dias!");
}
}
}
return $dates;
}
}