<?php
//use nego\application\models\huellas\Entradas;

//namespace nego\application\models\huellas;
require_once 'Entradas.php';

class Empleado extends CI_Model
{
    public $table = "empleado";
    public $idProducto = "clave";
    public $db_1;
    
    public function __construct(){
        parent::__construct();
    }
    public function probar(){
        $sql = $this->db->get_compiled_select($this->table);
        //echo $sql;
        //SELECT * FROM `empleado`
        
        $this->db->select("clave, nombre, municipio");
        $query = $this->db->get($this->table);
        
        $row = $query->row(); // una sola fila
       
        $result=array();
        //foreach ($query->result() as $row) //stdObject
        foreach ($query->result_array() as $row)
        {
            $result[]=$row;
        }
        //var_dump($query->result_array());
        echo $this->getDato("SELECT MAX(clave) FROM empleado");
    }
    public function insertar(){
        
    }
    public function getDato($sql)
    {
        $dato=null;
        //$sql=$this->db->select();
        $res = $this->db->query($sql);
        $row = $res->row_array();
        
        if(count($row)==1){
            $dato=current($row);
        }else{
            throw new Exception("Error al consultar dato"); 
        }
        return $dato;
    }
    public function testObj()
    {
        $obj = new Entradas();
        $query = $this->db->query("SELECT * FROM entradas");
        $rows = $query->custom_result_object(get_class($obj));
        
        $ent = current($rows);
        //foreach ($rows as $value) {
          //  var_dump($value->__get("fecha"));
        //}
        $ent->__set("clave",null);
        $ent->__set("fecha",date("Y-m-d"));
        $ent->__set("horaEntrada",date("H:i:s"));
        $ent->__set("destino","Casa");
       // $ent->fecha=date("Y-m-d");
        //$ent->setHoraEntrada(date("H:i:s"));
        var_dump($ent);
        $this->db->insert('entradas', $ent);
    }
}

