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

82 lines
2.3 KiB
PHP

<?php if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Survey_report_model extends CI_Model {
private $read_replica;
public function __construct()
{
parent::__construct();
$this->read_replica = $this->load->database('savvy_replica', TRUE);
}
public function get_survey_report_records(
$filters = [],
$limit = null,
$offset = null
) {
$combo_array = [
'status' => 'ms.status'
];
$numberic_array = [
'member_id' => 'ms.member_id'
];
$string_array = [
'description' => 'm.title',
'answer' => 'ms.answer',
'action' => 'm.button1_action'
];
$this->read_replica->select([
'ms.id||\':\'||ms.member_id AS id',
'\'<a href =/member/viewLocateMember?member_id=\'||ms.member_id||\'>\'||me.firstname||\'</a>\'',
'me.lastname',
'm.title',
'ms.answer',
'CASE WHEN ms.status = 1 THEN \'Active\' ELSE \'Deleted\' END AS status',
'me.added',
'm.button1_action'
]);
$this->read_replica->from('members_survey ms');
$this->read_replica->join('main_cards m', 'm.id = ms.card_id', 'left');
$this->read_replica->join('members me', 'me.id = ms.member_id', 'left');
foreach($filters as $key => $val) {
if (array_key_exists($key, $combo_array)) {
$this->read_replica->where($combo_array[$key], $val);
} else if (array_key_exists($key, $numberic_array)) {
$this->read_replica->where($numberic_array[$key], $val);
} else if (strpos($key, 'from') !== FALSE) {
$this->read_replica->where('DATE(me.added) >=', $val);
} else if (strpos($key, 'to') !== FALSE) {
$this->read_replica->where('DATE(me.added) <=', $val);
} else if (array_key_exists($key, $string_array)) {
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
}
}
if ($limit) {
$this->read_replica->limit($limit, $offset);
}
return $this->read_replica->get()->result_array();
}
}