<?php
/**
 * Created by PhpStorm.
 * User: SysWork
 * Date: 11/09/2018
 * Time: 9:57 AM
 */

class Roles_model  extends CI_Model
{
    public $ide_rol;
    public $nombre_rol;
    public $descripcion_rol;
    public $estado = 1;

    function __construct()
    {
        parent::__construct();
    }
    public function set_data($data_form)
    {
        foreach ($data_form as $campo => $valor) {
            if (property_exists("Roles_model", $campo)) {
                $this->$campo = $valor;
            }
        }
        return $this;
    }
    private function error()
    {
        return $this->db->error();
    }
    public function insert()
    {
        $rta = $this->db->insert('seg_roles', $this);
        #echo '---'.$this->db->last_query();
        if ($rta) {
            $respuesta = [
                "error" => false,
                'msg' => "Registro guardado correctamente",
                'cd_rol' => $this->db->insert_id()
            ];
        } else {
            $respuesta = [
                "error" => true,
                'msg' => "Error al guardar nuevo registro",
                'error_msg' => $this->error(),
                'error_num' => $this->error()
            ];
        }
        return $respuesta;
    }
    public function update()
    {
        $this->db->where('ide_rol', $this->ide_rol);
        $rta = $this->db->update('seg_roles'