76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php if (!defined('BASEPATH')) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
class Email_trigger_model extends CI_Model
|
|
{
|
|
private $read_replica;
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
|
}
|
|
|
|
public function get_email_trigger_records(
|
|
$filters = [],
|
|
$limit = null,
|
|
$offset = null
|
|
) {
|
|
|
|
$combo_array = [
|
|
'send_notification',
|
|
'send_mail',
|
|
'status',
|
|
];
|
|
|
|
$this->read_replica->select([
|
|
'id',
|
|
'e_trigger AS trigger_id',
|
|
'category AS next_action',
|
|
'template_name AS email_template',
|
|
'dynamic_key AS card_key',
|
|
'action_detail',
|
|
'message',
|
|
'send_mail',
|
|
'send_notification',
|
|
'status',
|
|
'icon',
|
|
'notify_title',
|
|
'CASE
|
|
WHEN send_mail=1 THEN \'Yes\'
|
|
ELSE \'No\'
|
|
END AS send_mail_text',
|
|
'CASE
|
|
WHEN send_notification=1 THEN \'Yes\'
|
|
ELSE \'No\'
|
|
END AS send_notification_text',
|
|
'CASE
|
|
WHEN status=1 THEN \'Active\'
|
|
ELSE \'Disabled\'
|
|
END AS status_text'
|
|
]);
|
|
|
|
$this->read_replica->from('email_trigger');
|
|
$sub_query = "( {$this->read_replica->get_compiled_select()} ) AS tmp";
|
|
|
|
$this->read_replica->reset_query();
|
|
|
|
$this->read_replica->from($sub_query);
|
|
foreach($filters as $key => $val) {
|
|
if (in_array($key, $combo_array)) {
|
|
$this->read_replica->where($key, $val);
|
|
} else {
|
|
$this->read_replica->like('lower(' . $key . ')', strtolower($val));
|
|
}
|
|
}
|
|
|
|
if ($limit) {
|
|
$this->read_replica->limit($limit, $offset);
|
|
}
|
|
|
|
$this->read_replica->order_by('trigger_id ASC');
|
|
|
|
return $this->read_replica->get()->result_array();
|
|
}
|
|
}
|