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

83 lines
2.3 KiB
PHP

<?php if (!defined('BASEPATH')) {
exit('No direct script access allowed');
}
class Carpool_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_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',
'\'<a href =/member/viewLocateMember?member_id=\'||m.id||\'>\'||m.firstname||\'</a>\'',
'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',
'\'<button type="button" onclick="viewSubscription1(\'||cp.id||\');" class="btn btn-primary">Proc</button>\' 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();
}
}