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

class We_roadshow_model extends CI_Model {

    /**
     * CONSTRUCTOR | LOAD DB
    */
    public function __construct() {
     parent::__construct();
     $this->load->database();
 }

    /**
     * SHOW | GET method.
     *
     * @return Response
    */
    public function show($id_user = 0,$id_club = 0, $page = 0, $limit = 10)
    {
        if(empty($id_user)) $id_user=0;
        if(empty($id_club)) $id_club=0;
        if(empty($page)) $page=0;
        if(empty($limit)) $limit=10;

        $offset = ($page-1)*$limit;
        $filter_limit = " limit ".$offset.",".$limit;
        $sql = "SELECT * from we_roadshow where ".
        " id_user='".$id_user."' ".
        " and id_club='".$id_club."' order by id DESC ".$filter_limit;      
        $query = $this->db->query($sql)->result();
        return $query;
    }



    /**
     * create_user function.
     * 
     * @access public
     * @param mixed $username
     * @param mixed $email
     * @param mixed $password
     * @return bool true on success, false on failure
     */
    public function create($input_data) {

        date_default_timezone_set("Asia/Bangkok");
        $tgl_now = date("Y-m-d H:i:s");

        $data = array(
            'id_club' => $input_data["id_club"],
            'id_user' => $input_data["id_user"],
            'nama' => $input_data["nama"],
            'hp' => $input_data["hp"],
            'usia' => $input_data["usia"],
            'jenis_kelamin' => $input_data["jenis_kelamin"],
            'tinggi_badan' => $input_data["tinggi_badan"],
            'berat_badan' => $input_data["berat_badan"],
            'lemak_tubuh' => $input_data["lemak_tubuh"],
            'kadar_air' => $input_data["kadar_air"],
            'massa_otot' => $input_data["massa_otot"],
            'rating_fisik' => $input_data["rating_fisik"],
            'kebutuhan_kalori' => $input_data["kebutuhan_kalori"],
            'usia_sel' => $input_data["usia_sel"],
            'massa_tulang' => $input_data["massa_tulang"],
            'lemak_perut' => $input_data["lemak_perut"],
            'bmi' => $input_data["bmi"],
            'protein' => $input_data["protein"],
            'create_tgl' => $tgl_now,
            'latitude' => $input_data["latitude"],
            'longitude' => $input_data["longitude"],
            'rating' => $input_data["rating"],
            'keterangan' => $input_data["keterangan"]
        );

          // var_dump($data) ;
        
        $this->db->insert('we_roadshow', $data);

        // if ($this->db->affected_rows()>0) {
        //     $res='OK';
        // } else {
        //     $res='FAILED';
        // }

        // $arr_Result = array(
        //     'insertId' => $this->db->insert_id(), 
        //     'result' => $res);
        // return json_encode($arr_Result);


        return $this->db->insert_id(); 
        
    }


}
