project done before
This commit is contained in:
100
application/models/M_tabel_ss.php
Normal file
100
application/models/M_tabel_ss.php
Normal file
@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
class M_tabel_ss extends CI_Model {
|
||||
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->database();
|
||||
}
|
||||
|
||||
private function _get_datatables_query($column_search,$column_order,$order,$table,$table_join,$where)
|
||||
{
|
||||
|
||||
|
||||
|
||||
$column_search = $column_search;
|
||||
$column_order = $column_order;
|
||||
$order = $order;
|
||||
$this->db->from($table);
|
||||
if ($table_join != null) {
|
||||
$this->db->join($table_join['table'],$table_join['join']);
|
||||
}
|
||||
if ($where != null) {
|
||||
$this->db->where($where);
|
||||
}
|
||||
|
||||
|
||||
$i = 0;
|
||||
|
||||
|
||||
// foreach ($this->column_search as $item) // looping awal
|
||||
foreach ($column_search as $item) // looping awal
|
||||
{
|
||||
if($_POST['search']['value']) // jika datatable mengirimkan pencarian dengan metode POST
|
||||
{
|
||||
|
||||
if($i===0) // looping awal
|
||||
{
|
||||
$this->db->group_start();
|
||||
$this->db->like($item, $_POST['search']['value']);
|
||||
}
|
||||
else
|
||||
{
|
||||
$this->db->or_like($item, $_POST['search']['value']);
|
||||
}
|
||||
|
||||
// if(count($this->column_search) - 1 == $i)
|
||||
if(count($column_search) - 1 == $i)
|
||||
$this->db->group_end();
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
|
||||
if(isset($_POST['order']))
|
||||
{
|
||||
$this->db->order_by($column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
|
||||
// $this->db->order_by($this->column_order[$_POST['order']['0']['column']], $_POST['order']['0']['dir']);
|
||||
}
|
||||
else if(isset($this->order))
|
||||
{
|
||||
$order = $this->order;
|
||||
$this->db->order_by(key($order), $order[key($order)]);
|
||||
}
|
||||
}
|
||||
|
||||
function get_datatables($column_search,$column_order,$order,$table,$table_join,$where)
|
||||
{
|
||||
$this->_get_datatables_query($column_search,$column_order,$order,$table,$table_join,$where);
|
||||
if($_POST['length'] != -1)
|
||||
$this->db->limit($_POST['length'], $_POST['start']);
|
||||
$query = $this->db->get();
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
function count_filtered($column_search,$column_order,$order,$table,$table_join,$where)
|
||||
{
|
||||
$this->_get_datatables_query($column_search,$column_order,$order,$table,$table_join,$where);
|
||||
$query = $this->db->get();
|
||||
return $query->num_rows();
|
||||
}
|
||||
|
||||
public function count_all($table,$table_join,$where)
|
||||
{
|
||||
|
||||
|
||||
$this->db->from($table);
|
||||
if ($table_join != null) {
|
||||
$this->db->join($table_join['table'],$table_join['join']);
|
||||
}
|
||||
if ($where != null) {
|
||||
$this->db->where($where);
|
||||
}
|
||||
|
||||
|
||||
|
||||
return $this->db->count_all_results();
|
||||
}
|
||||
|
||||
}
|
||||
103
application/models/Model.php
Normal file
103
application/models/Model.php
Normal file
@ -0,0 +1,103 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
|
||||
class Model extends CI_Model {
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
}
|
||||
|
||||
function index(){
|
||||
|
||||
}
|
||||
|
||||
function tampil_data_keseluruhan($namatabel) //gunakan ini untuk menampilkan tabel yg lebih spesifik 'where'
|
||||
{
|
||||
$this->db->select("*");
|
||||
$this->db->from($namatabel);
|
||||
|
||||
$query = $this->db->get();
|
||||
return $query;
|
||||
}
|
||||
|
||||
function tampil_data_where($namatabel,$array) //gunakan ini untuk menampilkan tabel yg lebih spesifik 'where'
|
||||
{
|
||||
$this->db->select("*");
|
||||
$this->db->from($namatabel);
|
||||
$this->db->where($array);
|
||||
// $this->db->limit(1);
|
||||
$query = $this->db->get();
|
||||
return $query;
|
||||
}
|
||||
|
||||
function tampil_data_group_by($namatabel,$array,$kolum) //gunakan ini untuk menampilkan tabel yg lebih spesifik 'where'
|
||||
{
|
||||
$this->db->select("*");
|
||||
$this->db->from($namatabel);
|
||||
$this->db->where($array);
|
||||
$this->db->group_by($kolum);
|
||||
$query = $this->db->get();
|
||||
return $query;
|
||||
}
|
||||
|
||||
function custom_query($query)
|
||||
{
|
||||
$query1 = $this->db->query($query);
|
||||
return $query1;
|
||||
|
||||
}
|
||||
|
||||
function delete($table,$array_condition)
|
||||
{
|
||||
// $this->db->where($array);
|
||||
$this->db->delete($table, $array_condition);
|
||||
// $this->db->delete(table_name, where_clause)
|
||||
}
|
||||
|
||||
|
||||
function insert($namatabel,$array)
|
||||
{
|
||||
return $this->db->insert($namatabel,$array);
|
||||
}
|
||||
|
||||
function update($table,$array,$array_condition)
|
||||
{
|
||||
$this->db->where($array);
|
||||
$this->db->update($table, $array_condition);
|
||||
}
|
||||
|
||||
function like($namatabel,$field,$like,$kategori)
|
||||
{
|
||||
if ($kategori == '') {
|
||||
$this->db->select("*");
|
||||
$this->db->from($namatabel);
|
||||
$this->db->like($field, $like, 'both');
|
||||
// $this->db->limit(1);
|
||||
$query = $this->db->get();
|
||||
return $query;
|
||||
}else{
|
||||
$this->db->select("*");
|
||||
$this->db->from($namatabel);
|
||||
$this->db->where(array('kategori'=>$kategori));
|
||||
$this->db->like($field, $like, 'both');
|
||||
// $this->db->limit(1);
|
||||
$query = $this->db->get();
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
|
||||
function serialize($data){
|
||||
$keys = array_column($data,'name');
|
||||
$values = array_column($data,'value');
|
||||
$data = array_combine($keys, $values);
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
11
application/models/index.html
Normal file
11
application/models/index.html
Normal file
@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user