File: /var/www/html/nt/application/models/Mcommon.php
<?php
class Mcommon extends CI_Model {
function __construct(){
parent::__construct();
}
public function insert($table,$data){
$this->db->insert($table,$data);
//echo $this->db->last_query();die;
return $this->db->insert_id();
}
public function batch_insert($table,$data){
$this->db->insert_batch($table,$data);
return 1;
}
public function getDetails($table,$condition){
$this->db->where($condition);
$query=$this->db->get($table);
//echo $this->db->last_query();die;
return $query->result_array();
}
public function getDetailsOrder($table,$condition,$order_by='',$order='ASC'){
$this->db->where($condition);
$this->db->order_by($order_by,$order);
$query=$this->db->get($table);
//echo $this->db->last_query();die;
return $query->result_array();
}
public function getRow($table,$condition){
$this->db->where($condition);
$query=$this->db->get($table);
//echo $this->db->last_query();die;
return $query->row_array();
}
public function getRowOrWhere($table,$condition){
$this->db->or_where($condition);
$query=$this->db->get($table);
//echo $this->db->last_query();die;
return $query->row_array();
}
public function checkUser($table,$condition){
$this->db->where($condition);
$query=$this->db->get($table);
return $query->row_array();
}
public function update($table,$condition,$data){
$this->db->where($condition);
$this->db->update($table,$data);
//echo $this->db->last_query();die;
return 1;
}
public function delete($table,$condition){
$this->db->where($condition);
$this->db->delete($table);
return 1;
}
public function getFullDetails($table){
$query=$this->db->get($table);
return $query->result_array();
}
public function user_check($table,$email, $password) {
$this->db->select('*');
$this->db->from($table);
$this->db->where(array('email' => $email, 'password' => md5($password)));
$query = $this->db->get();
return $query->row_array();
}
public function getDetailsFiltered($table,$params){
$this->db->from($table);
if(!empty($params['date_min']))
{
$this->db->where('date_of_creation >', $params['date_min']);
}
if(!empty($params['date_max']))
{
$stop_date = date('Y-m-d', strtotime($params['date_max'].' +1 day'));
$this->db->where('date_of_creation <=', $stop_date);
}
$query=$this->db->get();
return $query->result_array();
}
public function getFamilyIncomeCategory($monthly_family_income = 0) {
$sql = "SELECT category_monthly_limit.*, category.category_name FROM category_monthly_limit
LEFT JOIN category ON category_monthly_limit.category_id = category.category_id
WHERE $monthly_family_income BETWEEN familty_income_from AND familty_income_to";
$query = $this->db->query($sql);
return $query->row_array();
}
public function getActiveUomList($type = '') {
$this->db->where('is_active', 1);
if (!empty($type)) {
$this->db->where('type', $type);
}
$query = $this->db->get('uom_master');
return $query->result();
}
public function save_audit_log($audit_data) {
// Insert audit data into the database
$this->db->insert('audit_log', $audit_data);
// Check if the insertion was successful
if ($this->db->affected_rows() > 0) {
return true; // Return true if data was saved successfully
} else {
return false; // Return false if data saving failed
}
}
public function get_table_data($table_name, $table_pkkey, $pk_value) {
// Fetch data from the specified table using table PK key and value
$this->db->where($table_pkkey, $pk_value);
$query = $this->db->get($table_name);
$table_data = $query->row_array();
// Create JSON format for the retrieved record
$json_data = json_encode($table_data);
return $json_data;
}
}