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

59 lines
1.5 KiB
PHP

<?php if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Assigns_point_model extends CI_Model {
private $read_replica;
public function __construct()
{
parent::__construct();
$this->read_replica = $this->load->database('savvy_replica', TRUE);
}
public function get_assigns_point_records(
$filters = [],
$limit = null,
$offset = null
) {
$numeric_array = [
'from_points' => 'points >=',
'to_points' => 'points <='
];
$in_list = ['email', 'firstname', 'lastname'];
$this->read_replica->select([
'id',
'username',
'firstname',
'lastname',
'points',
'\'<button type="button" id="acc\'||id||\'" class="btn btn-danger" onclick="pointMember(\'||id||\');" >Select</button>\' AS ACT',
]);
$this->read_replica->from('members');
$this->read_replica->where('id > 0');
foreach($filters as $key => $val) {
if (in_array($key, $in_list)) {
$this->read_replica->like('lower(' . $key . ')', strtolower($val));
} else if (array_key_exists($key, $numeric_array)) {
$this->read_replica->where($numeric_array[$key], $val);
}
}
if ($limit) {
$this->read_replica->limit($limit, $offset);
$this->read_replica->order_by('id ASC');
}
return $this->read_replica->get()->result_array();
}
}