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

class Core_Model extends CI_Model {
  private $table=array();
  function __construct($config) 
  {
     $this->table=$config;
    /* Call the Model constructor */
    parent::__construct();
  }
 //select default functions 
 //select row
protected function get_row_array_mater_record_data_by_primary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['mater_table']);
		$this->db->where($this->table['master_table_primary_id'], $id);
		$query = $this->db->get();
		return $query->row_array(); 
 }
 protected function get_row_array_mater_record_data_by_secondary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['mater_table']);
		$this->db->where($this->table['master_table_seconrary_id'], $id);
		$query = $this->db->get();
		return $query->row_array(); 
 }
 protected function get_row_array_item_record_data_by_primary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['item_table']);
		$this->db->where($this->table['item_table_primary_id'], $id);
		$query = $this->db->get();
		return $query->row_array(); 
 }
  protected function get_row_array_item_record_data_by_secondary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['item_table']);
		$this->db->where($this->table['item_table_seconrary_id'], $id);
		$query = $this->db->get();
		return $query->row_array(); 
 }
 protected function get_row_array_sub_item_record_data_by_primary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['sub_item_table']);
		$this->db->where($this->table['sub_item_table_primary_id'], $id);
		$query = $this->db->get();
		return $query->row_array(); 
 }
  protected function get_row_array_sub_item_record_data_by_secondary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['sub_item_table']);
		$this->db->where($this->table['sub_item_table_seconrary_id'], $id);
		$query = $this->db->get();
		return $query->row_array(); 
 }
 //select result array
 protected function get_result_array_mater_record_data(){
    	$this->db->select('*');
		$this->db->from($this->table['mater_table']);
		$query = $this->db->get();
		return $query->result_array(); 
 }
 protected function get_result_array_mater_record_data_by_primary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['mater_table']);
		$this->db->where($this->table['master_table_primary_id'], $id);
		$query = $this->db->get();
		return $query->result_array(); 
 }
 protected function get_result_array_mater_record_data_by_secondary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['mater_table']);
		$this->db->where($this->table['master_table_seconrary_id'], $id);
		$query = $this->db->get();
		return $query->result_array(); 
 }
 protected function get_result_array_item_record_data(){
    	$this->db->select('*');
		$this->db->from($this->table['item_table']);
		$query = $this->db->get();
		return $query->result_array(); 
 }
 protected function get_result_array_item_record_data_by_primary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['item_table']);
		$this->db->where($this->table['item_table_primary_id'], $id);
		$query = $this->db->get();
		return $query->result_array(); 
 }
  protected function get_result_array_item_record_data_by_secondary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['item_table']);
		$this->db->where($this->table['item_table_seconrary_id'], $id);
		$query = $this->db->get();
		return $query->result_array(); 
 }
 protected function get_result_array_sub_item_record_data(){
    	$this->db->select('*');
		$this->db->from($this->table['sub_item_table']);
		$query = $this->db->get();
		return $query->result_array(); 
 }
 protected function get_result_array_sub_item_record_data_by_primary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['sub_item_table']);
		$this->db->where($this->table['sub_item_table_primary_id'], $id);
		$query = $this->db->get();
		return $query->result_array(); 
 }
  protected function get_result_array_sub_item_record_data_by_secondary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['sub_item_table']);
		$this->db->where($this->table['sub_item_table_seconrary_id'], $id);
		$query = $this->db->get();
		return $query->result_array(); 
 }
 //select result
 protected function get_result_mater_record_data(){
    	$this->db->select('*');
		$this->db->from($this->table['mater_table']);
		$query = $this->db->get();
		return $query->result(); 
 }
 protected function get_result_mater_record_data_by_primary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['mater_table']);
		$this->db->where($this->table['master_table_primary_id'], $id);
		$query = $this->db->get();
		return $query->result(); 
 }
 protected function get_result_mater_record_data_by_secondary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['mater_table']);
		$this->db->where($this->table['master_table_seconrary_id'], $id);
		$query = $this->db->get();
		return $query->result(); 
 }
 protected function get_result_item_record_data(){
    	$this->db->select('*');
		$this->db->from($this->table['item_table']);
		$query = $this->db->get();
		return $query->result(); 
 }
 protected function get_result_item_record_data_by_primary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['item_table']);
		$this->db->where($this->table['item_table_primary_id'], $id);
		$query = $this->db->get();
		return $query->result(); 
 }
 protected function get_result_item_record_data_by_secondary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['item_table']);
		$this->db->where($this->table['item_table_seconrary_id'], $id);
		$query = $this->db->get();
		return $query->result(); 
 }
  protected function get_result_sub_item_record_data(){
    	$this->db->select('*');
		$this->db->from($this->table['sub_item_table']);
		$query = $this->db->get();
		return $query->result(); 
 }
 protected function get_result_sub_item_record_data_by_primary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['sub_item_table']);
		$this->db->where($this->table['sub_item_table_primary_id'], $id);
		$query = $this->db->get();
		return $query->result(); 
 }
  protected function get_result_sub_item_record_data_by_secondary_id($id){
    	$this->db->select('*');
		$this->db->from($this->table['sub_item_table']);
		$this->db->where($this->table['sub_item_table_seconrary_id'], $id);
		$query = $this->db->get();
		return $query->result(); 
 }
 //insert default functions
 protected function save_master_table($data)
	{
	    $this->db->insert($this->table['mater_table'],$data);
	    return $this->db->insert_id();
	}
protected function save_item_table($data)
	{
	    $this->db->insert($this->table['item_table'],$data);
	    return $this->db->insert_id();
	}
protected function save_sub_item_table($data)
	{
	    $this->db->insert($this->table['sub_item_table'],$data);
	    return $this->db->insert_id();
	}
//update default functions
protected function update_master_table_by_primary_id($id,$data){
     if($id>0){
        $this->db->where($this->table['master_table_primary_id'],$id);
        return $this->db->update($this->table['mater_table'],$data);
     }else{
         return false;
     }
 }
protected function update_master_table_by_secondary_id($id,$data){
     if($id>0){
        $this->db->where($this->table['master_table_seconrary_id'],$id);
        return $this->db->update($this->table['mater_table'],$data);
     }else{
         return false;
     }
 }
 protected function update_item_table_by_primary_id($id,$data){
     if($id>0){
        $this->db->where($this->table['item_table_primary_id'],$id);
        return $this->db->update($this->table['item_table'],$data);
     }else{
         return false;
     }
 }
 protected function update_item_table_by_secondary_id($id,$data){
     if($id>0){
        $this->db->where($this->table['item_table_seconrary_id'],$id);
        return $this->db->update($this->table['item_table'],$data);
     }else{
         return false;
     }
 }
 protected function update_sub_item_table_by_primary_id($id,$data){
     if($id>0){
        $this->db->where($this->table['sub_item_table_primary_id'],$id);
        return $this->db->update($this->table['sub_item_table'],$data);
     }else{
         return false;
     }
 }
 protected function update_sub_item_table_by_secondary_id($id,$data){
     if($id>0){
        $this->db->where($this->table['sub_item_table_seconrary_id'],$id);
        return $this->db->update($this->table['sub_item_table'],$data);
     }else{
         return false;
     }
 }
 //delete default functions
 	protected function delete_master_table_by_primary_id($id)
	{
	    if($id>0){
	      	$this->db->where($this->table['master_table_primary_id'], $id);
		    return $this->db->delete($this->table['mater_table']);  
	    }
	}
	protected function delete_master_table_by_secondary_id($id)
	{
	    if($id>0){
	      	$this->db->where($this->table['master_table_seconrary_id'], $id);
		    return $this->db->delete($this->table['mater_table']);  
	    }
	}
	protected function delete_item_table_by_primary_id($id)
	{
	    if($id>0){
	      	$this->db->where($this->table['item_table_primary_id'], $id);
		    return $this->db->delete($this->table['item_table']);  
	    }
	}
	protected function delete_item_table_by_secondary_id($id)
	{
	    if($id>0){
	      	$this->db->where($this->table['item_table_seconrary_id'], $id);
		    return $this->db->delete($this->table['item_table']);  
	    }
	}
		protected function delete_sub_item_table_by_primary_id($id)
	{
	    if($id>0){
	      	$this->db->where($this->table['sub_item_table_primary_id'], $id);
		    return $this->db->delete($this->table['sub_item_table']);  
	    }
	}
	protected function delete_sub_item_table_by_secondary_id($id)
	{
	    if($id>0){
	      	$this->db->where($this->table['sub_item_table_seconrary_id'], $id);
		    return $this->db->delete($this->table['sub_item_table']);  
	    }
	}
	//count default functions
	protected function get_master_table_row_count(){
	    $this->db->from($this->table['mater_table']);
        $query = $this->db->get();
        return $query->num_rows();
	}
	protected function get_master_table_row_count_by_primary_id($id){
	    $this->db->from($this->table['mater_table']);
	    $this->db->where($this->table['master_table_primary_id'],$id);
        $query = $this->db->get();
        return $query->num_rows();
	}
	protected function get_master_table_row_count_by_secondary_id($id){
	    $this->db->from($this->table['mater_table']);
	    $this->db->where($this->table['master_table_seconrary_id'],$id);
        $query = $this->db->get();
        return $query->num_rows();
	}
	protected function get_item_table_row_count(){
	    $this->db->from($this->table['item_table']);
        $query = $this->db->get();
        return $query->num_rows();
	}
	protected function get_item_table_row_count_by_primary_id($id){
	    $this->db->from($this->table['item_table']);
	    $this->db->where($this->table['item_table_primary_id'],$id);
        $query = $this->db->get();
        return $query->num_rows();
	}
	protected function get_item_table_row_count_by_secondary_id($id){
	    $this->db->from($this->table['item_table']);
	    $this->db->where($this->table['item_table_seconrary_id'],$id);
        $query = $this->db->get();
        return $query->num_rows();
	}
	protected function get_sub_item_table_row_count(){
	    $this->db->from($this->table['sub_item_table']);
        $query = $this->db->get();
        return $query->num_rows();
	}
	protected function get_sub_item_table_row_count_by_primary_id($id){
	    $this->db->from($this->table['sub_item_table']);
	    $this->db->where($this->table['sub_item_table_primary_id'],$id);
        $query = $this->db->get();
        return $query->num_rows();
	}
	protected function get_sub_item_table_row_count_by_secondary_id($id){
	    $this->db->from($this->table['sub_item_table']);
	    $this->db->where($this->table['sub_item_table_seconrary_id'],$id);
        $query = $this->db->get();
        return $query->num_rows();
	}
  
}