68 lines
1.9 KiB
PHP
68 lines
1.9 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
class ModelModel extends CI_Model {
|
|
public function create($table, $data, $batch = false)
|
|
{
|
|
if($batch === false){
|
|
$insert = $this->db->insert($table, $data);
|
|
}else{
|
|
$insert = $this->db->insert_batch($table, $data);
|
|
}
|
|
return $insert;
|
|
}
|
|
|
|
public function update($table, $data, $pk, $id = null, $batch = false)
|
|
{
|
|
if($batch === false){
|
|
$insert = $this->db->update($table, $data, array($pk => $id));
|
|
}else{
|
|
$insert = $this->db->update_batch($table, $data, $pk);
|
|
}
|
|
return $insert;
|
|
}
|
|
|
|
public function delete($table, $data, $pk)
|
|
{
|
|
$this->db->where_in($pk, $data);
|
|
return $this->db->delete($table);
|
|
}
|
|
|
|
public function getData_Model($id = null){
|
|
if ($id === null) {
|
|
$this->db->select('*');
|
|
$this->db->from('model');
|
|
$this->db->order_by('NAMA_MODEL ASC');
|
|
}else{
|
|
$this->db->select('*');
|
|
$this->db->from('model');
|
|
$this->db->where(['ID_MODEL' => $id]);
|
|
$this->db->order_by('NAMA_MODEL ASC');
|
|
}
|
|
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Barang_byMODEL($id){
|
|
$this->db->select('*');
|
|
$this->db->from('barang a');
|
|
$this->db->join('model b','b.ID_MODEL=a.MODEL_ID');
|
|
$this->db->where(['a.MODEL_ID' => $id]);
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
public function getData_Model_byNAMA($id1, $id2=null){
|
|
if ($id2 == null) {
|
|
$this->db->select('*');
|
|
$this->db->from('model');
|
|
$this->db->where(['NAMA_MODEL' => $id1]);
|
|
} else {
|
|
$this->db->select('*');
|
|
$this->db->from('model');
|
|
$this->db->where(['NAMA_MODEL' => $id1]);
|
|
$this->db->where('ID_MODEL!=', $id2);
|
|
}
|
|
return $this->db->get()->result_array();
|
|
}
|
|
|
|
}
|
|
?>
|