Files
dev-chiefworks f76abffdcd first commit
2022-05-31 16:21:53 -04:00

118 lines
2.7 KiB
PHP

<?php if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Global_setting_model extends CI_Model {
private $read_replica;
public function __construct()
{
parent::__construct();
$this->read_replica = $this->load->database('savvy_replica', TRUE);
}
// Fetch records
public function getData($rowno, $rowperpage, $filters = []) {
$this->read_replica->select('*');
$this->read_replica->from('global_settings');
$this->read_replica->order_by('key');
foreach($filters as $key => $value) {
if ($key === 'key_filter') {
$this->read_replica->like('lower(key)', strtolower($value));
} else if ($key === 'description_filter') {
$this->read_replica->like('lower(description)', strtolower($value));
} else if ($key === 'card_status_filter') {
$this->read_replica->where('status', $value);
}
}
$this->read_replica->limit($rowperpage, $rowno);
$query = $this->read_replica->get();
return $query->result_array();
}
// Select total records
public function getrecordCount($filters = []) {
$this->read_replica->select('count(*) as allcount');
$this->read_replica->from('global_settings');
foreach($filters as $key => $value) {
if ($key === 'key_filter') {
$this->read_replica->like('lower(key)', strtolower($value));
} else if ($key === 'description_filter') {
$this->read_replica->like('lower(description)', strtolower($value));
} else if ($key === 'card_status_filter') {
$this->read_replica->where('status', $value);
}
}
$query = $this->read_replica->get();
$result = $query->result_array();
return $result[0]['allcount'];
}
public function insertGlobalSetting($data) {
try {
unset($data['old_key']);
$this->db->insert('global_settings', $data);
return $this->db->insert_id();
} catch (Exception $ex) {
return false;
}
}
public function updateGlobalSetting($id, $data) {
try {
unset($data['old_key']);
$this->db->where('id',$id);
$this->db->update('global_settings', $data);
return $this->db->affected_rows();
} catch (Exception $ex) {
return false;
}
}
public function deleteGlobalSettingById($id) {
try {
$this->db->delete('global_settings', $id);
return $this->db->affected_rows();
} catch (Exception $ex) {
return false;
}
}
public function getGlobalSettingsByID($id) {
try {
return $this->read_replica->get_where('global_settings', $id)->num_rows();
} catch (Exception $ex) {
return false;
}
}
}