| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /wamp/www/sipapbd_2019/application/core/ |
Upload File : |
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*********************************************************************************************
SUPER CLASS dari semua Model
*********************************************************************************************/
class Base_Model extends Core_Model{
var $fieldmap_daftar; // variabel untuk menampung kolom-kolom yang ditampilkan di daftar
var $fieldmap_filter; // variabel untuk menampung mapping kolom-kolom yang digunakan dalam filter
var $id; // variabel untuk menampung primary key
var $last_changed;
var $last_error_id;
var $last_error_message;
function __construct()
{
parent::__construct();
}
// mengembalikan daftar kolom yang bisa dilakukan pencarian
function get_data_fields()
{
}
function fill_data()
{
}
function cek_exist()
{
}
function cek_changed()
{
}
protected function get_id($generator)
{
$result = $this->db->query('select gen_id('.$generator.', 1) id from rdb$database')->row_array();
return $result['ID'];
}
function check_trans_status($exception)
{
if ($this->db->trans_status() === FALSE) {
throw new Exception($exception);
}
}
function save_data()
{
$this->db->trans_begin();
try {
$this->save_detail();
}
catch(Exception $e){
//TODO : log error to file
}
if ($this->db->trans_status() === FALSE)
{
$this->id = NULL;
$this->last_error_id = $this->db->_error_number();
$this->last_error_message = $this->db->_error_message();
$this->db->trans_rollback();
return FALSE;
}
$this->db->trans_commit();
return TRUE;
}
function delete_data($id)
{
$this->db->trans_begin();
try {
$this->build_query_hapus($id);
}
catch(Exception $e){
//TODO : log error to file
}
if ($this->db->trans_status() === FALSE)
{
$this->last_error_id = $this->db->_error_number();
$this->last_error_message = $this->db->_error_message();
$this->db->trans_rollback();
return FALSE;
}
$this->db->trans_commit();
return TRUE;
}
function build_query_daftar()
{
// di override di modul Aktivitas
}
function build_query_form($id=0)
{
// di override di modul Aktivitas
}
function build_query_hapus()
{
// di override di modul Aktivitas
}
function get_data($param, $isCount=FALSE, $CompileOnly=False)
{
$this->build_query_daftar();
isset($param['limit']) && $param['limit'] ? $this->db->limit($param['limit']['end'], $param['limit']['start']) : '';
// proses parameter pencarian, jika ada
if (isset($param['search_mode']) && $param['search_mode'] !=='' )
{
// proses pencarian singkat (simple search)
if ($param['search_mode'] == 'ss')
{
foreach($this->fieldmap_filter as $key => $value){
$flt[$key] = array('search_str' => $param['q'], 'search_op' => 'cn');
}
if (count($flt) > 0)
{
$swhere = get_where_str($flt, $this->fieldmap_filter);
if ($swhere) {
$swhere = build_or_where($swhere);
$this->db->where($swhere);
}
}
}
// proses pencarian lanjut (advanced search)
else if ($param['search_mode'] == 'as') {
$fields = $this->get_data_fields();
if (is_array($param['q']) && count($param['q']) > 0)
{
foreach ($param['q'] as $key=>$val) {
$kolom = $val['c'];
$search_str = isset($val['s']) ? $val['s'] : '';
$search_str2 = isset($val['s2']) ? $val['s2'] : '';
$flt[$kolom] = array(
'search_str' => $search_str,
'search_str2' => $search_str2,
'search_op' => $val['o'],
'search_datatype' => $fields[$kolom]['kategori'],
);
}
if (count($flt) > 0)
{
$wh = get_where_str($flt, $this->fieldmap_filter);
$this->db->where($wh);
}
}
}
}
// proses jika ada pengurutan
if (isset($param['sort_by']) && $param['sort_by'] != null && !$isCount && $ob = get_order_by_str($param['sort_by'], $this->fieldmap_filter))
{
$this->db->order_by($ob, $param['sort_direction']);
}
if ($isCount) {
$result = $this->db->count_all_results();
return $result;
}
else
{
if ($CompileOnly)
{
return $this->db->get_compiled_select();
}
else
{
$result = $this->db->get();
return $result->result_array();
}
}
}
function get_data_by_id($id)
{
$this->build_query_form($id);
$result = $this->db->get()->row_array();
return $result;
}
function get_last_changed($modul,$id_modul,$id)
{
$last_changed = $this->db->query("select last_changed from ".$modul." where ".$id_modul."=".$id."")->row_array();
return $last_changed['LAST_CHANGED'];
}
function check_dependency($id)
{
return TRUE;
}
function check_lock($ID,$MODUL)
{
$timelimit = date("d.m.Y.H.i.s", strtotime("-5 minute"));
$this->db->trans_start();
$this->db->select("*");
$this->db->from('LOCKING');
$this->db->where('LAST_CHANGED <', $timelimit);
$hsl = $this->db->get()->result_array();
if($hsl){
for ($i=0;$i<count($hsl);$i++){
$this->db->where('ID', $hsl[$i]['ID']);
$this->db->where('MODUL', $hsl[$i]['MODUL']);
$this->db->where('USERNAME', $hsl[$i]['USERNAME']);
$this->db->delete('LOCKING');
}
}
$this->db->select("*");
$this->db->from('LOCKING');
$this->db->where('MODUL', $MODUL);
$this->db->where('USERNAME', $this->session->userdata('username'));
$rsl = $this->db->get()->row_array();
if($rsl){
$this->db->where('MODUL', $rsl['MODUL']);
$this->db->where('USERNAME', $rsl['USERNAME']);
$this->db->delete('LOCKING');
}
$this->db->select("*");
$this->db->from('LOCKING');
$this->db->where('ID', $ID);
$this->db->where('MODUL', $MODUL);
$result = $this->db->get()->row_array();
if($result){
if($result['USERNAME']==$this->session->userdata('username')){
$this->db->where('ID', $ID);
$this->db->where('MODUL', $MODUL);
$this->db->where('USERNAME', $this->session->userdata('username'));
$this->db->update('LOCKING', array('LAST_CHANGED' => date('d.m.Y.H.i.s')));
return 0;
}
else return 1;
}
else
{
$this->db->insert('LOCKING', array('ID' => $ID,'MODUL' => $MODUL, 'USERNAME' => $this->session->userdata('username'), 'LAST_CHANGED' => date('d.m.Y.H.i.s'), 'STATUS' => 'EDIT'));
return 0;
}
$this->db->trans_complete();
}
function check_period_locking()
{
$this->db->trans_start();
$this->db->select("*");
$this->db->from('LOCKING');
$this->db->where('ID', $this->input->post('id'));
$this->db->where('MODUL', $this->input->post('modul'));
//$this->db->where('username', $this->session->userdata('username'));
$result = $this->db->get()->row_array();
if($result){
if($this->input->post('lock')=='0'){
$this->db->where('ID', $this->input->post('id'));
$this->db->where('MODUL', $this->input->post('modul'));
$this->db->where('username', $this->session->userdata('username'));
$this->db->update('LOCKING', array('LAST_CHANGED' => date('d.m.Y.H.i.s'),'STATUS' => 'EDIT'));
return TRUE;
}
else if($this->input->post('lock')=='1'){
$this->db->where('ID', $result['ID']);
$this->db->where('MODUL', $result['MODUL']);
$this->db->where('USERNAME', $result['USERNAME']);
$this->db->delete('LOCKING');
return TRUE;
}
else if($this->input->post('lock')=='2'){
$this->db->where('ID', $this->input->post('id'));
$this->db->where('MODUL', $this->input->post('modul'));
$this->db->where('username', $this->session->userdata('username'));
$this->db->update('LOCKING', array('LAST_CHANGED' => date('d.m.Y.H.i.s'),'STATUS' => 'SIMPAN'));
return TRUE;
}
else if($this->input->post('lock')=='3'){
$this->db->where('ID', $this->input->post('id'));
$this->db->where('MODUL', $this->input->post('modul'));
$this->db->update('LOCKING', array('LAST_CHANGED' => date('d.m.Y.H.i.s'),'STATUS' => 'EDIT'));
return TRUE;
}
}
else return FALSE;
$this->db->trans_complete();
}
}