read_replica = $this->load->database('savvy_replica', TRUE);
}
public function get_carpool_records(
$filters = [],
$limit = null,
$offset = null
) {
$combo_array = [
// 'status'
];
$numeric_array = [
'pool' => 'pool',
'card_id' => 'card_id',
'status' => 'cp.status'
];
$this->read_replica->select([
'cp.id AS carpool_id',
'\'\'||m.firstname||\'\'',
'm.lastname',
'm.email',
'cp.pool',
'mc.title',
'mc.id AS card_id',
'cp.added',
'cp.updated',
'(CASE
WHEN cp.status = 1 THEN \'Pending\'
ELSE cp.status::text END
) AS status',
'\'\' AS proc1',
]);
$this->read_replica->from('members_carpool cp');
$this->read_replica->join('members m', 'm.id = cp.member_id', 'left');
$this->read_replica->join('main_cards mc', 'mc.id=cp.card_id', 'left');
foreach($filters as $key => $val) {
if (in_array($key, $combo_array)) {
$this->read_replica->where($key, $val);
} else if (array_key_exists($key, $numeric_array)) {
$this->read_replica->where($numeric_array[$key], $val);
} else if (strpos($key, 'from') !== FALSE) {
$this->read_replica->where('DATE(cp.added) >=', $val);
} else if (strpos($key, 'to') !== FALSE) {
$this->read_replica->where('DATE(cp.added) <=', $val);
} else {
$this->read_replica->like('lower(' . $key . ')', strtolower($val));
}
}
if ($limit) {
$this->read_replica->limit($limit, $offset);
$this->read_replica->order_by('carpool_id ASC');
}
return $this->read_replica->get()->result_array();
}
}