first commit
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Login_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_login_report_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
$this->read_replica->select([
|
||||
'ms.id',
|
||||
'm.username',
|
||||
'ms.member_id',
|
||||
'ms.created',
|
||||
'ms.updated',
|
||||
'ms.loc',
|
||||
'ms.shop'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('members_session ms');
|
||||
$this->read_replica->join('members m', 'm.id = ms.member_id');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
$key = $key === 'loc' ? "TEXT(ms.$key)" : $key;
|
||||
$key = $key === 'username' ? "m.$key" : $key;
|
||||
|
||||
if ($key === 'member_id') {
|
||||
|
||||
$this->read_replica->where($key, $val);
|
||||
|
||||
} else if (strpos($key, 'from') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(ms.' . substr($key, 5) .') >=', $val);
|
||||
|
||||
} else if (strpos($key, 'to') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(ms.' . substr($key, 3) .') <=', $val);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->like('lower(' . $key . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
}
|
||||
|
||||
$this->read_replica->order_by('id ASC');
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user