File "Historico.php"

Full Path: C:/wamp64/www/casos_medicos1/model/Historico.php
File size: 1.39 KB
MIME-type: text/x-php
Charset: utf-8

<?php
require_once __DIR__ . "/conexion.php";

class HistoricoModel {

    private $conn;

    public function __construct() {
        $this->conn = (new Conexion())->getConexion();
    }

    public function getHistorico($filtros) {

        $where = "WHERE 1=1";

        if (!empty($filtros['cedula'])) {
            $cedula = preg_replace('/\D/', '', $filtros['cedula']);
            $where .= " AND cedula = '" . $this->conn->real_escape_string($cedula) . "'";
        }

        // Empresa no existe en la tabla ausentismo
        /*
        if (!empty($filtros['empresa'])) {
            $empresa = $this->conn->real_escape_string($filtros['empresa']);
            $where .= " AND empresa LIKE '%$empresa%'";
        }
        */

        if (!empty($filtros['fecha_inicio'])) {
            $f = $this->conn->real_escape_string($filtros['fecha_inicio']);
            $where .= " AND fecha_inicio >= '$f'";
        }

        if (!empty($filtros['fecha_fin'])) {
            $f = $this->conn->real_escape_string($filtros['fecha_fin']);
            $where .= " AND fecha_fin <= '$f'";
        }

        $sql = "SELECT * FROM ausentismo $where ORDER BY fecha_registro DESC";
        $res = $this->conn->query($sql);

        return [
            "total" => $res ? $res->num_rows : 0,
            "lista" => $res ? $res->fetch_all(MYSQLI_ASSOC) : []
        ];
    }
}