<?php
defined('BASEPATH') or exit('No direct script access allowed');

class Auth_model extends CI_Model
{

    public function check_username($username)
    {
        $query = $this->db->get_where('tbl_user', ['username' => $username]);
        return $query->num_rows();
    }

    public function check_entidad($username)
    {
        $data = $this->db->get_where('tbl_user', ['username' => $username])->row_array();

        $id_entidad = $data['id_entidad'];
        
        $data_entidad = $this->db->get_where('tbl_entidades', ['id_entidad' => $id_entidad])->row_array();

        $is_active = $data_entidad['is_active'];

        if ($data['role'] == 'admin')
        {
            $is_active = 1;
        }

        return $is_active;
    }

    public function get_entidad($id_entidad)
    {
        $data = $this->db->get_where('tbl_entidades', ['id_entidad' => $id_entidad])->row_array();
        return $data['nombre_entidad'];
    }

    public function get_password($username)
    {
        $data = $this->db->get_where('tbl_user', ['username' => $username])->row_array();
        return $data['password'];
    }

    public function userdata($username)
    {
        return $this->db->get_where('tbl_user', ['username' => $username])->row_array();
    }

}
