<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Sampel_model extends CI_Model
{

    public $table = 'sampel';
    public $id = 'id_sampel';
    public $order = 'DESC';

    function __construct()
    {
        parent::__construct();
    }

    // get all
    function get_all()
    {
        $this->db->order_by($this->id, $this->order);
        return $this->db->get($this->table)->result();
    }

    // get style
    function get_style()
    {
        $this->db->select('*');
        $this->db->from('web_management');
        $this->db->join('web_style_2', 'web_management.style_web = web_style_2.id_web_style');
        return $this->db->get()->row();
    }

    // get data by id
    function get_by_id($id)
    {
        $this->db->where($this->id, $id);
        return $this->db->get($this->table)->row();
    }
    
    // get total rows
    function total_rows($q = NULL) {
        $this->db->like('id_sampel', $q);
	$this->db->or_like('sampel_text', $q);
	$this->db->or_like('sampel_tanggal', $q);
	$this->db->or_like('sampel_time', $q);
	$this->db->or_like('sampel_enum', $q);
	$this->db->or_like('sampel_file', $q);
	$this->db->or_like('sampel_number', $q);
	$this->db->from($this->table);
        return $this->db->count_all_results();
    }

    // get data with limit and search
    function get_limit_data($limit, $start = 0, $q = NULL) {
        $this->db->order_by($this->id, $this->order);
        $this->db->like('id_sampel', $q);
	$this->db->or_like('sampel_text', $q);
	$this->db->or_like('sampel_tanggal', $q);
	$this->db->or_like('sampel_time', $q);
	$this->db->or_like('sampel_enum', $q);
	$this->db->or_like('sampel_file', $q);
	$this->db->or_like('sampel_number', $q);
	$this->db->limit($limit, $start);
        return $this->db->get($this->table)->result();
    }

    // insert data
    function insert($data)
    {
        $this->db->insert($this->table, $data);
    }

    // update data
    function update($id, $data)
    {
        $this->db->where($this->id, $id);
        $this->db->update($this->table, $data);
    }

    // delete data
    function delete($id)
    {
        $this->db->where($this->id, $id);
        $this->db->delete($this->table);
    }

    // delete data list
    function delete_list()
    {
        $data_id        = $_POST['pilih'];
        $jml_dipilih    = count($data_id);
        for ($x = 0; $x < $jml_dipilih; $x++) {
            $this->db->where($this->id, $data_id[$x]);
            $this->db->delete($this->table);
        }
    }

    // import data
    public function insert_multiple($data)
    {
        $this->db->insert_batch($this->table, $data);
    }

}

/* End of file Sampel_model.php */
/* Location: ./application/models/Sampel_model.php */
/* Please DO NOT modify this information : */
/* Generated by IDETech Codeigniter CRUD Generator 2021-06-09 17:05:27 */
/* http://idetech.id */