first commit
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Acl_Whitelist_Extra_model extends CI_Model {
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function getRecordAclWhiteListExtraByParamNameAndParamValueAndAclWhiteListID($data) {
|
||||
$this->read_replica->select('id');
|
||||
$this->read_replica->from('bko_acl_whitelist_extra');
|
||||
$this->read_replica->where('bko_acl_whitelist_id', $data['bko_acl_whitelist_id']);
|
||||
$this->read_replica->where('parameter_name', $data['parameter_name']);
|
||||
$this->read_replica->where('parameter_value', $data['parameter_value']);
|
||||
|
||||
return $this->read_replica->get()->num_rows();
|
||||
}
|
||||
|
||||
public function insertAclWhitelistExtra($data) {
|
||||
|
||||
$this->db->insert('bko_acl_whitelist_extra', $data);
|
||||
return $this->db->insert_id();
|
||||
|
||||
}
|
||||
|
||||
public function getRecordAclWhitelistExtraByID($data) {
|
||||
return $this->read_replica->get_where('bko_acl_whitelist_extra', $data)->num_rows();
|
||||
}
|
||||
|
||||
public function updateAclWhitelistExtra($data) {
|
||||
$this->db->set('parameter_name', $data['parameter_name']);
|
||||
$this->db->set('parameter_value', $data['parameter_value']);
|
||||
$this->db->where('id', $data['id']);
|
||||
$this->db->update('bko_acl_whitelist_extra');
|
||||
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
|
||||
public function deleteAclWhitelistExtra($id) {
|
||||
|
||||
$this->db->where('id', $id);
|
||||
$this->db->delete('bko_acl_whitelist_extra');
|
||||
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,101 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Acl_Whitelist_model extends CI_Model {
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function getControllerAndMethod() {
|
||||
$this->read_replica->select('acl_wl.id AS bko_acl_whitelist_id, CONCAT(acl.class_name, \' - \', acl.method_name) AS class_method');
|
||||
$this->read_replica->from('bko_acl_whitelist acl_wl');
|
||||
$this->read_replica->join('bko_acl acl', 'acl.id = acl_wl.bko_acl_id');
|
||||
|
||||
$query = $this->read_replica->get();
|
||||
|
||||
return array_column($query->result_array(), 'class_method', 'bko_acl_whitelist_id');
|
||||
}
|
||||
|
||||
// Fetch records
|
||||
public function getData($rowno,$rowperpage, $filters = []) {
|
||||
|
||||
$this->read_replica->select( 'acl.id AS acl_id,
|
||||
acl_wl_ext.id AS acl_wl_ext_id,
|
||||
acl_wl.id AS acl_wl_id,
|
||||
acl.method_name AS method_name,
|
||||
acl.class_name AS class_name,
|
||||
pl.name AS name,
|
||||
acl_wl_ext.parameter_name AS parameter_name,
|
||||
acl_wl_ext.parameter_value AS parameter_value');
|
||||
$this->read_replica->from('bko_acl acl');
|
||||
$this->read_replica->join('bko_acl_permission_level', 'acl.id = bko_acl_permission_level.bko_acl_id ');
|
||||
$this->read_replica->join('bko_permission_level pl', 'bko_acl_permission_level.plevel = pl.plevel ');
|
||||
$this->read_replica->join('bko_acl_whitelist acl_wl', 'acl_wl.bko_acl_id = acl.id ');
|
||||
$this->read_replica->join('bko_acl_whitelist_extra acl_wl_ext', 'acl_wl_ext.bko_acl_whitelist_id = acl_wl.id ');
|
||||
|
||||
foreach($filters as $key => $value) {
|
||||
if ($key === 'card_class_filter') {
|
||||
|
||||
$this->read_replica->where('lower(acl.class_name)', strtolower($value));
|
||||
|
||||
} else if ($key === 'method_filter') {
|
||||
|
||||
$this->read_replica->like('acl.method_name', strtolower($value));
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->where('pl.plevel', $value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->read_replica->order_by('acl_id');
|
||||
$this->read_replica->limit($rowperpage, $rowno);
|
||||
$query = $this->read_replica->get();
|
||||
|
||||
return $query->result_array();
|
||||
}
|
||||
|
||||
// Select total records
|
||||
public function getrecordCount($filters = []) {
|
||||
|
||||
$this->read_replica->select('count(*) as allcount');
|
||||
$this->read_replica->from('bko_acl acl');
|
||||
$this->read_replica->join('bko_acl_permission_level', 'acl.id = bko_acl_permission_level.bko_acl_id ');
|
||||
$this->read_replica->join('bko_permission_level pl', 'bko_acl_permission_level.plevel = pl.plevel ');
|
||||
$this->read_replica->join('bko_acl_whitelist acl_wl', 'acl_wl.bko_acl_id = acl.id ');
|
||||
$this->read_replica->join('bko_acl_whitelist_extra acl_wl_ext', 'acl_wl_ext.bko_acl_whitelist_id = acl_wl.id ');
|
||||
|
||||
foreach($filters as $key => $value) {
|
||||
if ($key === 'card_class_filter') {
|
||||
|
||||
$this->read_replica->where('lower(acl.class_name)', strtolower($value));
|
||||
|
||||
} else if ($key === 'method_filter') {
|
||||
|
||||
$this->read_replica->like('acl.method_name', strtolower($value));
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->where('pl.plevel', $value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$query = $this->read_replica->get();
|
||||
$result = $query->result_array();
|
||||
|
||||
return $result[0]['allcount'];
|
||||
}
|
||||
|
||||
public function getRecordAclWhitelistById($data) {
|
||||
$this->read_replica->get_where('bko_acl_whitelist', $data);
|
||||
return $this->read_replica->affected_rows();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,165 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Acl_model extends CI_Model {
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function insert_acl($data) {
|
||||
|
||||
$data = [
|
||||
'class_name' => $data['controller'],
|
||||
'method_name' => $data['method']
|
||||
];
|
||||
|
||||
$this->read_replica->select('id');
|
||||
$this->read_replica->from('bko_acl');
|
||||
$this->read_replica->where('class_name', $data['class_name']);
|
||||
$this->read_replica->where('method_name', $data['method_name']);
|
||||
|
||||
$query = $this->read_replica->get();
|
||||
$id = isset($query->result_array()[0]['id']) ? $query->result_array()[0]['id'] : 0;
|
||||
|
||||
if (!$id) {
|
||||
$insert_query = $this->db->insert_string('bko_acl', $data);
|
||||
$this->db->query($insert_query);
|
||||
$id = $this->db->insert_id();
|
||||
}
|
||||
|
||||
return $id;
|
||||
}
|
||||
|
||||
public function insert_acl_permission_level($data) {
|
||||
|
||||
$data = [
|
||||
'bko_acl_id' => $data['bko_acl_id'],
|
||||
'plevel' => $data['plevel'],
|
||||
];
|
||||
|
||||
$insert_query = $this->db->insert_string('bko_acl_permission_level', $data);
|
||||
$insert_query .= " ON CONFLICT (bko_acl_id, plevel) DO NOTHING";
|
||||
|
||||
$this->db->query($insert_query);
|
||||
}
|
||||
|
||||
public function insert_acl_whitelist($data) {
|
||||
$data = [
|
||||
'bko_acl_id' => $data['bko_acl_id']
|
||||
];
|
||||
|
||||
$insert_query = $this->db->insert_string('bko_acl_whitelist', $data);
|
||||
$insert_query .= " ON CONFLICT (bko_acl_id) DO NOTHING";
|
||||
|
||||
$this->db->query($insert_query);
|
||||
}
|
||||
|
||||
public function update_acl_permission_level($data) {
|
||||
$this->db->set('plevel', $data['plevel']);
|
||||
$this->db->where('bko_acl_id', $data['bko_acl_id']);
|
||||
$this->db->update('bko_acl_permission_level');
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
|
||||
// Fetch records
|
||||
public function getData($rowno,$rowperpage, $filters = []) {
|
||||
|
||||
$this->read_replica->select( 'acl.id AS id,
|
||||
acl.method_name AS method_name,
|
||||
acl.class_name AS class_name,
|
||||
pl.plevel as plevel,
|
||||
pl.name AS name');
|
||||
$this->read_replica->from('bko_acl acl');
|
||||
$this->read_replica->join('bko_acl_permission_level', 'acl.id = bko_acl_permission_level.bko_acl_id ');
|
||||
$this->read_replica->join('bko_permission_level pl', 'bko_acl_permission_level.plevel = pl.plevel ');
|
||||
|
||||
foreach($filters as $key => $value) {
|
||||
if ($key === 'card_class_filter') {
|
||||
|
||||
$this->read_replica->where('lower(acl.class_name)', strtolower($value));
|
||||
|
||||
} else if ($key === 'method_filter') {
|
||||
|
||||
$this->read_replica->like('acl.method_name', strtolower($value));
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->where('pl.plevel', $value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->read_replica->order_by('id');
|
||||
$this->read_replica->limit($rowperpage, $rowno);
|
||||
$query = $this->read_replica->get();
|
||||
|
||||
return $query->result_array();
|
||||
}
|
||||
|
||||
// Select total records
|
||||
public function getrecordCount($filters = []) {
|
||||
|
||||
$this->read_replica->select('count(*) as allcount');
|
||||
$this->read_replica->from('bko_acl acl');
|
||||
$this->read_replica->join('bko_acl_permission_level', 'acl.id = bko_acl_permission_level.bko_acl_id ');
|
||||
$this->read_replica->join('bko_permission_level pl', 'bko_acl_permission_level.plevel = pl.plevel ');
|
||||
|
||||
foreach($filters as $key => $value) {
|
||||
if ($key === 'card_class_filter') {
|
||||
|
||||
$this->read_replica->where('lower(acl.class_name)', strtolower($value));
|
||||
|
||||
} else if ($key === 'method_filter') {
|
||||
|
||||
$this->read_replica->like('acl.method_name', strtolower($value));
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->where('pl.plevel', $value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$query = $this->read_replica->get();
|
||||
$result = $query->result_array();
|
||||
|
||||
return $result[0]['allcount'];
|
||||
}
|
||||
|
||||
public function getRecordControllerMethodPlevel($data) {
|
||||
|
||||
$this->read_replica->select('acl.id AS id');
|
||||
$this->read_replica->from('bko_acl acl');
|
||||
$this->read_replica->join('bko_acl_permission_level acl_p_l', 'acl.id = acl_p_l.bko_acl_id');
|
||||
$this->read_replica->where('acl.class_name', $data['controller']);
|
||||
$this->read_replica->where('acl.method_name', $data['method']);
|
||||
$this->read_replica->where('acl_p_l.plevel', $data['plevel']);
|
||||
|
||||
$query = $this->read_replica->get();
|
||||
return $query->num_rows();
|
||||
}
|
||||
|
||||
public function getRecordByPermissionLevel($data) {
|
||||
|
||||
$query = $this->read_replica->get_where('bko_permission_level', $data);
|
||||
|
||||
return $query->num_rows();
|
||||
}
|
||||
|
||||
public function gerRecordAclById($data) {
|
||||
$query = $this->read_replica->get_where('bko_acl', $data);
|
||||
|
||||
return $query->num_rows();
|
||||
}
|
||||
|
||||
public function deleteAclById($id) {
|
||||
$this->db->where('id', $id);
|
||||
$this->db->delete('bko_acl');
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Address_model extends CI_Model
|
||||
{
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function Address($data)
|
||||
{
|
||||
return (array) $data;
|
||||
}
|
||||
|
||||
public function getAddresses($params)
|
||||
{
|
||||
$res = SQEAPI::get('address/api/address/all', $params);
|
||||
|
||||
if (isset($res['error'])) {
|
||||
return ['success' => false, 'error' => $res['error']];
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($res['data'] as $addr) {
|
||||
$data[] = $this->parseAddress($addr);
|
||||
}
|
||||
|
||||
$total = isset($res['total']) ? $res['total'] : 0;
|
||||
$page = isset($res['page']) ? $res['page'] : 0;
|
||||
|
||||
return [
|
||||
'list' => $data,
|
||||
'total' => $total,
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
||||
public function getAddressesWithUsingQuery($params)
|
||||
{
|
||||
$page = $params['page'] ?? 1;
|
||||
$per_page = $params['per_page'] ?? 20;
|
||||
|
||||
$offset = ($page - 1) * $per_page;
|
||||
if ($offset < 0) {
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
$whereQuery = ' WHERE 1 = 1 ';
|
||||
if (!empty($params)) {
|
||||
if (!empty($params['address'])) {
|
||||
$search_text = $this->read_replica->escape_like_str($params['address']);
|
||||
$whereQuery .= ' AND address ILIKE \'%' . $search_text . '%\'';
|
||||
}
|
||||
}
|
||||
|
||||
$totalQueryString = 'SELECT * FROM address ' . $whereQuery;
|
||||
|
||||
$queryString = 'SELECT * FROM address ' . $whereQuery . '
|
||||
ORDER BY address ASC
|
||||
LIMIT ' . pg_escape_string($per_page) . ' OFFSET ' . pg_escape_string($offset);
|
||||
|
||||
$totalQuery = $this->read_replica->query($totalQueryString);
|
||||
$query = $this->read_replica->query($queryString);
|
||||
|
||||
return [
|
||||
'total' => count($totalQuery->result()),
|
||||
'data' => $query->result(),
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
||||
public function createAddress($params)
|
||||
{
|
||||
return SQEAPI::post('address/api/address/new', $params);
|
||||
}
|
||||
|
||||
public function removeAddressById($addrId)
|
||||
{
|
||||
return SQEAPI::delete("address/api/address/$addrId");
|
||||
}
|
||||
|
||||
public function getAddressById($addrId)
|
||||
{
|
||||
$res = SQEAPI::get("address/api/address/$addrId", null);
|
||||
if (isset($res['error'])) {
|
||||
return $res;
|
||||
}
|
||||
|
||||
return array_merge($res, ['data' => $this->parseAddress($res['data'])]);
|
||||
}
|
||||
|
||||
public function updateAddressById($addrId, $params)
|
||||
{
|
||||
return SQEAPI::put("address/api/address/$addrId", $params);
|
||||
}
|
||||
|
||||
private function parseAddress($originData)
|
||||
{
|
||||
return $this->Address($originData);
|
||||
}
|
||||
|
||||
public function getCitieByID($city_id)
|
||||
{
|
||||
$q = $this
|
||||
->read_replica
|
||||
->select('id, city')
|
||||
->where('id', $city_id)
|
||||
->get('geofence_area_city');
|
||||
|
||||
return $q->result_array();
|
||||
}
|
||||
|
||||
public function getCountryByCode($country_cd)
|
||||
{
|
||||
$q = $this
|
||||
->read_replica
|
||||
->select('id, country')
|
||||
->where('code', $country_cd)
|
||||
->get('country');
|
||||
|
||||
return $q->result_array();
|
||||
}
|
||||
|
||||
public function generate_query_select_address($filters = [], $count_record = true) {
|
||||
$numeric_array = [
|
||||
'address_id' => 'ta.address_id',
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'attraction' => 'attraction'
|
||||
];
|
||||
|
||||
$count_record ?
|
||||
$this->db->select(['count(*) AS all_count']) :
|
||||
$this->db->select([
|
||||
'gac.id as gac_id',
|
||||
'gac.city as gac_city',
|
||||
'gac.country as gac_country',
|
||||
'gac.latitude as gac_latitude',
|
||||
'gac.longitude as gac_longitude',
|
||||
'gac.location as gac_location',
|
||||
'gac.radius as gac_radius',
|
||||
'gac.status as gac_status',
|
||||
'gacs.id as gacs_id',
|
||||
'gacs.status as gacs_status',
|
||||
'gacs.geofence_area_city as gacs_geofence_area_city',
|
||||
'gacs.image_url as gacs_image_url',
|
||||
'gacs.is_fectched_data as gacs_is_fectched_data',
|
||||
'ta.id as ta_id',
|
||||
'ta.attraction as ta_attraction',
|
||||
'ta.active as ta_active',
|
||||
'ta.address_id as ta_address_id',
|
||||
'ta.city_id as ta_city_id',
|
||||
'ta.feature_image as ta_feature_image',
|
||||
'ta.description as ta_description',
|
||||
'a.address as a_address'
|
||||
]);
|
||||
|
||||
$this->db->from('tourist_attraction ta')
|
||||
->join('address a', 'a.id=ta.address_id', 'LEFT')
|
||||
->join('geofence_area_city gac', 'gac.id=ta.city_id', 'LEFT')
|
||||
->join('geofence_area_city_settings gacs', 'gacs.geofence_area_city=ta.city_id', 'LEFT');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
if (array_key_exists($key, $numeric_array)) {
|
||||
|
||||
$this->db->where($numeric_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
|
||||
$this->db->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
foreach($filters['city_id'] as $key => $val) {
|
||||
$this->db->or_where('ta.city_id', $val);
|
||||
}
|
||||
|
||||
if (isset($filters['latitude']) &&
|
||||
isset($filters['longitude']) &&
|
||||
isset($filters['radius'])) {
|
||||
|
||||
$this->db->where(
|
||||
"ST_DWithin(
|
||||
geometry,
|
||||
ST_SetSRID(
|
||||
ST_MakePoint(
|
||||
{$filters['longitude']},
|
||||
{$filters['latitude']}
|
||||
),
|
||||
4326
|
||||
),
|
||||
{$filters['radius']}
|
||||
)"
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
if ($count_record === false) {
|
||||
|
||||
$this->db->order_by('ta.attraction ASC');
|
||||
|
||||
}
|
||||
|
||||
return $this->db->get_compiled_select();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Advice_model extends CI_Model
|
||||
{
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function getAdviceQuery($params = [])
|
||||
{
|
||||
$whereQuery = '';
|
||||
|
||||
if (!empty($params['travel_date'])) {
|
||||
// travel_date format: 2020-02-03 - 2020-03-01
|
||||
$fromToArray = explode(' - ', $params['travel_date']);
|
||||
$fromDate = $fromToArray[0];
|
||||
$toDate = $fromToArray[1];
|
||||
|
||||
$whereQuery .= " AND (
|
||||
(to_char(a.travel_date, 'YYYY-MM-DD') >= '" . pg_escape_string($fromDate) . "'
|
||||
AND
|
||||
to_char(a.travel_date, 'YYYY-MM-DD') <= '" . pg_escape_string($toDate) . "'
|
||||
)
|
||||
OR
|
||||
(to_char(a.updated, 'YYYY-MM-DD') >= '" . pg_escape_string($fromDate) . "'
|
||||
AND
|
||||
to_char(a.updated, 'YYYY-MM-DD') <= '" . pg_escape_string($toDate) . "'
|
||||
)
|
||||
) ";
|
||||
}
|
||||
|
||||
if (!empty($params['duration_from'])) {
|
||||
$whereQuery .= " AND a.duration >= " . pg_escape_string($params['duration_from']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['duration_to'])) {
|
||||
$whereQuery .= " AND a.duration <= " . pg_escape_string($params['duration_to']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['distance_from'])) {
|
||||
$whereQuery .= " AND a.distance >= " . pg_escape_string($params['distance_from']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['distance_to'])) {
|
||||
$whereQuery .= " AND a.distance <= " . pg_escape_string($params['distance_to']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['location_start_id'])) {
|
||||
$whereQuery .= " AND a.location_start_id = " . pg_escape_string($params['location_start_id']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['location_end_id'])) {
|
||||
$whereQuery .= " AND a.location_end_id = " . pg_escape_string($params['location_end_id']) . " ";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT a.id,a.travel_date||'<br/>'||a.updated As \"Date/Updated\",a.duration,a.distance,
|
||||
b.address||'<br/>'||c.address as \"From and To\",
|
||||
'<input type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"return viewAdvice('||a.id||');\" value=\"View\" />' AS \"View\"
|
||||
FROM parsedemail_item a
|
||||
LEFT JOIN address b ON b.id = a.location_start_id
|
||||
LEFT JOIN address c ON c.id = a.location_end_id
|
||||
WHERE a.private='t' AND a.trackedemail_item_id IS NULL " . $whereQuery . " ORDER BY a.id DESC
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function get_query_parsed_email_quote_records($filters, $count_record = true) {
|
||||
$combo_array = [
|
||||
];
|
||||
|
||||
$numeric_array = [
|
||||
'duration_from' => 'a.duration >=',
|
||||
'duration_to' => 'a.duration <=',
|
||||
'distance_from' => 'a.distance >=',
|
||||
'distance_to' => 'a.distance <=',
|
||||
'location_start_id' => 'a.location_start_id',
|
||||
'location_end_id' => 'a.location_end_id',
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
];
|
||||
|
||||
$boolean_array = [
|
||||
];
|
||||
|
||||
if ($count_record) {
|
||||
|
||||
$this->read_replica->select([
|
||||
'count(*) AS all_count'
|
||||
]);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->select([
|
||||
'a.travel_date',
|
||||
'a.duration',
|
||||
'a.cost_raw',
|
||||
'a.cost',
|
||||
'a.updated',
|
||||
'a.distance',
|
||||
'a.transport_provider_id',
|
||||
'a.travel_date_end',
|
||||
'a.location_start_id',
|
||||
'a.location_end_id',
|
||||
'b.address AS location_start_address',
|
||||
'b.latitude AS location_start_lat',
|
||||
'b.longitude AS location_start_lng',
|
||||
'b.postal AS location_start_postal',
|
||||
'b.country AS location_start_country',
|
||||
'b.description AS location_start_description',
|
||||
'd.timezone AS location_start_tz',
|
||||
'c.address AS location_end_address',
|
||||
'c.latitude AS location_end_lat',
|
||||
'c.longitude AS location_end_lng',
|
||||
'c.postal AS location_end_postal',
|
||||
'c.country AS location_end_country',
|
||||
'c.description AS location_end_description',
|
||||
'e.timezone AS location_end_tz'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
$this->read_replica->from('parsedemail_item a');
|
||||
$this->read_replica->join('address b', 'b.id=a.location_start_id', 'LEFT');
|
||||
$this->read_replica->join('address c', 'c.id=a.location_end_id', 'LEFT');
|
||||
$this->read_replica->join('address_timezone d', 'b.timezone=d.id', 'LEFT');
|
||||
$this->read_replica->join('address_timezone e', 'c.timezone=e.id', 'LEFT');
|
||||
|
||||
$this->read_replica->where('a.trackedemail_item_id IS NULL');
|
||||
$this->read_replica->where('a.private', 't');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if ($key === 'travel_date') {
|
||||
|
||||
$fromToArray = explode(' - ', $val);
|
||||
$this->read_replica->group_start()
|
||||
->group_start()
|
||||
->where('DATE(a.travel_date) >=', $fromToArray[0]) // start date
|
||||
->where('DATE(a.travel_date) <=', $fromToArray[1]) // end date
|
||||
->group_end()
|
||||
->or_group_start()
|
||||
->where('DATE(a.updated) >=', $fromToArray[0]) // start date
|
||||
->where('DATE(a.updated) <=', $fromToArray[1]) // end date
|
||||
->group_end()
|
||||
->group_end();
|
||||
|
||||
|
||||
} else if ($key === 'location_start_ids') {
|
||||
|
||||
$this->read_replica->where_in('a.location_start_id', $val);
|
||||
|
||||
} else if ($key === 'location_end_ids') {
|
||||
|
||||
$this->read_replica->where_in('a.location_end_id', $val);
|
||||
|
||||
} else if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numeric_array)) {
|
||||
|
||||
$this->read_replica->where($numeric_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
} else if (array_key_exists($key, $boolean_array)) {
|
||||
|
||||
$this->read_replica->where($boolean_array[$key], $val);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($count_record === false) {
|
||||
|
||||
$this->read_replica->order_by('a.id DESC');
|
||||
|
||||
}
|
||||
|
||||
return $this->read_replica->get_compiled_select();
|
||||
}
|
||||
|
||||
public function count_parsedemail_item_record() {
|
||||
return $this->read_replica->select(['count(id) AS all_count'])
|
||||
->from('parsedemail_item')
|
||||
->get()
|
||||
->result_array()[0]['all_count'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Android_automation_job_detail_model extends CI_Model
|
||||
{
|
||||
public function __constructor()
|
||||
{
|
||||
parent::__constructor();
|
||||
}
|
||||
|
||||
public function Android_automation_job_details($data)
|
||||
{
|
||||
return (array) $data;
|
||||
}
|
||||
|
||||
public function getAndroidAutomationJobDetail($params)
|
||||
{
|
||||
$res = AutomaticServerAPI::get('android-automation-job-detail', $params);
|
||||
|
||||
if (isset($res['error'])) {
|
||||
return ['success' => false, 'error' => $res['error']];
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($res['data'] as $addr) {
|
||||
$data[] = $this->parse_android_automation_job_details($addr);
|
||||
}
|
||||
|
||||
$totalPage = isset($res['total']) ? $res['total'] : 0;
|
||||
$page = isset($res['page']) ? $res['page'] : 0;
|
||||
|
||||
return [
|
||||
'list' => $data,
|
||||
'totalItems' => $totalPage,
|
||||
'page' => $page,
|
||||
'transport_providers' => empty($res['transportProviders']) ? [] : $res['transportProviders'],
|
||||
'android_automation_jobs' => empty($res['jobs']) ? [] : $res['jobs']
|
||||
];
|
||||
}
|
||||
|
||||
public function getAndroidAutomationJobDetailByID($id) {
|
||||
$res = AutomaticServerAPI::get("android-automation-job-detail/$id", NULL);
|
||||
$res['data'] = $this->parse_android_automation_job_details($res['data']);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function createAndroidAutomationJobDetail($params)
|
||||
{
|
||||
return AutomaticServerAPI::post('android-automation-job-detail', $params);
|
||||
}
|
||||
|
||||
public function removeAndroidAutomationJobDetailById($AndroidAutomationJobDetailID)
|
||||
{
|
||||
return AutomaticServerAPI::delete("android-automation-job-detail/$AndroidAutomationJobDetailID");
|
||||
}
|
||||
|
||||
public function updateAndroidAutomationJobDetailById($AndroidAutomationJobDetailID, $params)
|
||||
{
|
||||
return AutomaticServerAPI::put("android-automation-job-detail/$AndroidAutomationJobDetailID", $params);
|
||||
}
|
||||
|
||||
private function parse_android_automation_job_details($originData)
|
||||
{
|
||||
return $this->android_automation_job_details($originData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Automation_job_model extends CI_Model
|
||||
{
|
||||
|
||||
public function __constructor()
|
||||
{
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function automation_job($data)
|
||||
{
|
||||
return (array) $data;
|
||||
}
|
||||
|
||||
public function getJobs($params)
|
||||
{
|
||||
$res = AutomaticServerAPI::get('android-automation-jobs', $params);
|
||||
|
||||
if (isset($res['error'])) {
|
||||
return ['success' => false, 'error' => $res['error']];
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($res['data'] as $addr) {
|
||||
$data[] = $this->parse_job($addr);
|
||||
}
|
||||
|
||||
$totalPage = isset($res['total']) ? $res['total'] : 0;
|
||||
$page = isset($res['page']) ? $res['page'] : 0;
|
||||
|
||||
return [
|
||||
'list' => $data,
|
||||
'totalItems' => $totalPage,
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
||||
public function getById($id) {
|
||||
$res = AutomaticServerAPI::get("android-automation-jobs/$id", NULL);
|
||||
$res['data'] = $this->parse_job($res['data']);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function createJob($params)
|
||||
{
|
||||
return AutomaticServerAPI::post('android-automation-jobs', $params);
|
||||
}
|
||||
|
||||
public function removeById($itemId)
|
||||
{
|
||||
return AutomaticServerAPI::delete("android-automation-jobs/$itemId");
|
||||
}
|
||||
|
||||
public function updateById($itemId, $params)
|
||||
{
|
||||
return AutomaticServerAPI::put("android-automation-jobs/$itemId", $params);
|
||||
}
|
||||
|
||||
private function parse_job($originData)
|
||||
{
|
||||
return $this->automation_job($originData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Bank_model extends CI_Model
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function insert($data) {
|
||||
$data_insert = array('bank_name' => $data['bank_name']);
|
||||
|
||||
$sql = $this->db->insert_string('banks', $data_insert)
|
||||
. ' ON CONFLICT (bank_name)
|
||||
DO UPDATE SET bank_name=EXCLUDED.bank_name
|
||||
RETURNING id';
|
||||
|
||||
return $this->db->query($sql)->result_array()[0]['id'];
|
||||
}
|
||||
|
||||
public function delete($data) {
|
||||
$this->db->where('id', $data['bank_id']);
|
||||
$this->db->delete('banks');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,372 @@
|
||||
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Bko_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_decision_status_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
|
||||
$combo_array = [
|
||||
'status' => 'd.status'
|
||||
];
|
||||
|
||||
$numeric_array = [
|
||||
'from_order' => 'd.lorder >=',
|
||||
'to_order' => 'd.lorder <='
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'description' => 'd.description',
|
||||
'personalty' => 'd.personality',
|
||||
'key' => 'd.dkey'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'd.id',
|
||||
'd.lorder',
|
||||
'd.description||\'<br><b>Personalty:</b>\'||d.personality AS pp',
|
||||
'\'<a class="btn btn-warning btn-sm btn-block"
|
||||
onclick="configureDescision(\'||d.id||\',0);" >V</a>\'',
|
||||
'd.dkey',
|
||||
'\'<a id="nacc\'||d.id||\'" style="backgound-color:yellow;"
|
||||
class="btn btn-sm btn-block"
|
||||
onclick="configureNext(\'||d.id||\',0);" >\'||count(a.id)||\'</a>\' AS nxt',
|
||||
'(CASE WHEN d.status = 1 THEN \'Active\' ELSE \'Not Active\' END) AS status',
|
||||
'\'<button type="button" id="\'||d.id||\'" class="btn btn-info btn-sm"
|
||||
onclick="configureCard(\'||d.id||\',0);">Cards</button>\' AS Cards',
|
||||
]);
|
||||
|
||||
$this->read_replica->from('decision_group d');
|
||||
$this->read_replica->join('decision_group_action a', 'a.dkey = d.dkey', 'LEFT');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numeric_array)) {
|
||||
|
||||
$this->read_replica->where($numeric_array[$key], $val);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$this->read_replica->group_by(
|
||||
'd.id,
|
||||
d.description,
|
||||
d.personality,
|
||||
d.dkey,
|
||||
d.lorder,
|
||||
d.status'
|
||||
);
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('d.lorder ASC');
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function get_quote_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
|
||||
$combo_array = [
|
||||
];
|
||||
|
||||
$numeric_array = [
|
||||
'transport_provider' => 'transport_provider_id'
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
];
|
||||
|
||||
$boolean_array = [
|
||||
'prefill' => 'a.prefill'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'\'<div id="check"\'||a.id||\'"><button type="button" class="btn btn-danger btn-xs"
|
||||
onclick="return checkQuote(\'||a.id||\',this)">Check Quote</button></div>\' AS "Check Quote"',
|
||||
'date_trunc(\'second\',a.created) AS Created',
|
||||
'date_trunc(\'second\',a.completed) AS Completed',
|
||||
'date_trunc(\'second\',a.travel_date) AS "Travel Date"',
|
||||
'a.cost_raw AS "Cost Raw"',
|
||||
'ROUND(a.cost,2) AS Cost',
|
||||
'CASE WHEN a.prefill=\'t\' THEN \'Automatic\' ELSE \'Application\' END AS "Data Source"',
|
||||
'd.name AS "Transport Provider"',
|
||||
'b.address AS Origin',
|
||||
'c.address AS Destination',
|
||||
'b.country AS "Origin Country"',
|
||||
'b.postal AS "Origin Postal"'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('quotes a');
|
||||
$this->read_replica->join('address b', 'b.id=a.location_start_id', 'LEFT');
|
||||
$this->read_replica->join('address c', 'c.id=a.location_end_id', 'LEFT');
|
||||
$this->read_replica->join('transport_providers d', 'd.id=a.transport_provider_id', 'LEFT');
|
||||
|
||||
$this->read_replica->where('a.id > 0');
|
||||
|
||||
if (isset($filters['sql_raw'])) {
|
||||
|
||||
$this->read_replica->where($filters['sql_raw']);
|
||||
|
||||
} else {
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if ($key === 'country') {
|
||||
|
||||
$this->read_replica->group_start();
|
||||
$this->read_replica->where('b.country', $val);
|
||||
$this->read_replica->or_where('c.country', $val);
|
||||
$this->read_replica->group_end();
|
||||
|
||||
} else if ($key === 'location_start_ids') {
|
||||
|
||||
$this->read_replica->where_in('a.location_start_id', $val);
|
||||
|
||||
} else if ($key === 'location_end_ids') {
|
||||
|
||||
$this->read_replica->where_in('a.location_end_id', $val);
|
||||
|
||||
} else if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numeric_array)) {
|
||||
|
||||
$this->read_replica->where($numeric_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
} else if (array_key_exists($key, $boolean_array)) {
|
||||
|
||||
$this->read_replica->where($boolean_array[$key], $val);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
}
|
||||
|
||||
$this->read_replica->order_by('a.created DESC');
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function get_query_export_quote_records(
|
||||
$filters = [],
|
||||
$count_record = true
|
||||
) {
|
||||
|
||||
$combo_array = [
|
||||
];
|
||||
|
||||
$numeric_array = [
|
||||
'transport_provider' => 'transport_provider_id'
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
];
|
||||
|
||||
$boolean_array = [
|
||||
'prefill' => 'a.prefill'
|
||||
];
|
||||
|
||||
if ($count_record) {
|
||||
|
||||
$this->read_replica->select([
|
||||
'count(*) AS all_count'
|
||||
]);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->select([
|
||||
'a.transport_provider_id',
|
||||
'a.automation_id',
|
||||
'a.cost_raw',
|
||||
'ROUND(a.cost,2) AS cost',
|
||||
'date_trunc(\'second\',a.created) AS created',
|
||||
'date_trunc(\'second\',a.completed) AS completed',
|
||||
'date_trunc(\'second\',a.travel_date) AS travel_date',
|
||||
'a.member_id',
|
||||
'a.location_start_id',
|
||||
'a.location_end_id',
|
||||
'a.quote_group_id',
|
||||
'b.address AS location_start_address',
|
||||
'b.latitude AS location_start_lat',
|
||||
'b.longitude AS location_start_lng',
|
||||
'b.postal AS location_start_postal',
|
||||
'b.country AS location_start_country',
|
||||
'b.description AS location_start_description',
|
||||
'd.timezone AS location_start_tz',
|
||||
'c.address AS location_end_address',
|
||||
'c.latitude AS location_end_lat',
|
||||
'c.longitude AS location_end_lng',
|
||||
'c.postal AS location_end_postal',
|
||||
'c.country AS location_end_country',
|
||||
'c.description AS location_end_description',
|
||||
'e.timezone AS location_end_tz'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
$this->read_replica->from('quotes a');
|
||||
$this->read_replica->join('address b', 'b.id=a.location_start_id', 'LEFT');
|
||||
$this->read_replica->join('address c', 'c.id=a.location_end_id', 'LEFT');
|
||||
$this->read_replica->join('address_timezone d', 'b.timezone=d.id', 'LEFT');
|
||||
$this->read_replica->join('address_timezone e', 'c.timezone=e.id', 'LEFT');
|
||||
$this->read_replica->join('transport_providers f', 'f.id=a.transport_provider_id', 'LEFT');
|
||||
|
||||
$this->read_replica->where('a.id > 0');
|
||||
|
||||
if (isset($filters['sql_raw'])) {
|
||||
|
||||
$this->read_replica->where($filters['sql_raw']);
|
||||
|
||||
} else {
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if ($key === 'country') {
|
||||
|
||||
$this->read_replica->group_start();
|
||||
$this->read_replica->where('b.country', $val);
|
||||
$this->read_replica->or_where('c.country', $val);
|
||||
$this->read_replica->group_end();
|
||||
|
||||
} else if ($key === 'location_start_ids') {
|
||||
|
||||
$this->read_replica->where_in('a.location_start_id', $val);
|
||||
|
||||
} else if ($key === 'location_end_ids') {
|
||||
|
||||
$this->read_replica->where_in('a.location_end_id', $val);
|
||||
|
||||
} else if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numeric_array)) {
|
||||
|
||||
$this->read_replica->where($numeric_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
} else if (array_key_exists($key, $boolean_array)) {
|
||||
|
||||
$this->read_replica->where($boolean_array[$key], $val);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($count_record === false) {
|
||||
$this->read_replica->order_by('a.created DESC');
|
||||
}
|
||||
|
||||
return $this->read_replica->get_compiled_select();
|
||||
}
|
||||
|
||||
public function count_quote_records($filters) {
|
||||
|
||||
$combo_array = [
|
||||
];
|
||||
|
||||
$numeric_array = [
|
||||
'transport_provider' => 'transport_provider_id',
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
];
|
||||
|
||||
$boolean_array = [
|
||||
'prefill' => 'a.prefill'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'count(a.id) AS all_count'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('quotes a');
|
||||
$this->read_replica->join('address b', 'b.id=a.location_start_id', 'LEFT');
|
||||
$this->read_replica->join('address c', 'c.id=a.location_end_id', 'LEFT');
|
||||
|
||||
$this->read_replica->where('a.id > 0');
|
||||
|
||||
if (isset($filters['sql_raw'])) {
|
||||
|
||||
$this->read_replica->where($filters['sql_raw']);
|
||||
|
||||
} else {
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if ($key === 'country') {
|
||||
|
||||
$this->read_replica->group_start();
|
||||
$this->read_replica->where('b.country', $val);
|
||||
$this->read_replica->or_where('c.country', $val);
|
||||
$this->read_replica->group_end();
|
||||
|
||||
} else if ($key === 'location_start_ids') {
|
||||
|
||||
$this->read_replica->where_in('a.location_start_id', $val);
|
||||
|
||||
} else if ($key === 'location_end_ids') {
|
||||
|
||||
$this->read_replica->where_in('a.location_end_id', $val);
|
||||
|
||||
} else if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numeric_array)) {
|
||||
|
||||
$this->read_replica->where($numeric_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
} else if (array_key_exists($key, $boolean_array)) {
|
||||
|
||||
$this->read_replica->where($boolean_array[$key], $val);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array()[0]['all_count'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Bkoadmin_model extends CI_Model {
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function get_point_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
$combo_array = [
|
||||
'activated' => 'activated'
|
||||
];
|
||||
|
||||
$numeric_array = [
|
||||
'from_value' => 'value >=',
|
||||
'to_value' => 'value <=',
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'key' => 'point_key',
|
||||
'name' => 'name'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'id',
|
||||
'lorder',
|
||||
'point_key',
|
||||
'name',
|
||||
'\'<input type="text" id="points\'||id||\'" class="form-control" value="\'||value||\'">\' AS pvalue',
|
||||
'\'<button ion-button class="btn-info btn-sx" onclick="return UpdatePoints(this,\'||id||\')">Update</button>\' AS updt',
|
||||
'status',
|
||||
'added',
|
||||
'(CASE
|
||||
WHEN activated = 1 THEN \'Activated\'
|
||||
ELSE \'Not Activated\' END
|
||||
) AS activated_text',
|
||||
'activated',
|
||||
]);
|
||||
|
||||
$this->read_replica->from('points_settings');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$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(added) >=', $val);
|
||||
|
||||
} else if (strpos($key, 'to') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(added) <=', $val);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('id');
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function getAppSettingsQuery($params = [])
|
||||
{
|
||||
$whereQuery = ' WHERE 1 = 1 ';
|
||||
|
||||
if (!empty($params['key'])) {
|
||||
$whereQuery .= " AND setting_key ILIKE '%" . pg_escape_string(trim($params['key'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['name'])) {
|
||||
$whereQuery .= " AND description ILIKE '%" . pg_escape_string(trim($params['name'])) . "%' ";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
lorder,
|
||||
setting_key,
|
||||
description,
|
||||
" . " '<input type=\"text\" class=\"form-control\" name=\"T' || setting_key || '\" id=\"T' || setting_key || '\" value=\"' || value || '\">' AS pvalue,
|
||||
" . " '<button ion-button class=\"btn-info btn-sx\" onclick=\"updateSettings(' || id || ',''' || setting_key || ''');\">Update</button><div id=\"set_form' || setting_key || '\"><div>' AS updt
|
||||
FROM app_settings
|
||||
" . $whereQuery . "
|
||||
ORDER BY id
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getGlobalSettingsQuery($params = [])
|
||||
{
|
||||
$whereQuery = ' WHERE 1 = 1 ';
|
||||
|
||||
if (!empty($params['key'])) {
|
||||
$whereQuery .= " AND key ILIKE '%" . pg_escape_string(trim($params['key'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['description'])) {
|
||||
$whereQuery .= " AND description ILIKE '%" . pg_escape_string(trim($params['description'])) . "%' ";
|
||||
}
|
||||
if (isset($params['status']) && $params['status'] != -1) {
|
||||
$whereQuery .= " AND status = " . pg_escape_string($params['status']) . " ";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT *
|
||||
FROM
|
||||
global_settings
|
||||
" . $whereQuery . "
|
||||
ORDER BY id
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getTransportProviderQuery($params = [])
|
||||
{
|
||||
$whereQuery = ' WHERE 1 = 1 ';
|
||||
|
||||
if (!empty($params['name'])) {
|
||||
$whereQuery .= " AND name ILIKE '%" . pg_escape_string(trim($params['name'])) . "%' ";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
id,
|
||||
concat('<a href=\"/bkoadmin/transportApps?id=', id, '\">', name, '</a>') AS Name,
|
||||
concat('<b>Client:</b> ', client, '<br/><b>Token:</b> ', token, '<br/><b>Code:</b> ', code, '<br/><b>Access Token:</b> ', access_token, '<br/><b>Name Alias:</b> ', name_alias) AS Credentials,
|
||||
(
|
||||
CASE active
|
||||
WHEN 1 THEN
|
||||
'Yes'
|
||||
ELSE
|
||||
'No'
|
||||
END) AS Active,
|
||||
'<input type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"return EditTransportProvider(' || id || ');\" value=\"Edit\" />' AS action
|
||||
FROM
|
||||
transport_providers
|
||||
" . $whereQuery . "
|
||||
ORDER BY
|
||||
name
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getTransportProviderAppQuery($params = [])
|
||||
{
|
||||
$query = "
|
||||
SELECT
|
||||
b.name,
|
||||
a.country,
|
||||
a.ios_app_id,
|
||||
a.android_app_id,
|
||||
concat('<button type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"document.location=''/bkoadmin/transportApps?id=', b.id, '&app_id=', a.id, ''';return false;\">Edit</button>') AS Action
|
||||
FROM
|
||||
transport_provider_apps a,
|
||||
transport_providers b
|
||||
WHERE
|
||||
b.id = a.transport_provider_id
|
||||
ORDER BY
|
||||
b.name,
|
||||
a.country
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function insertOrUpdateAdminQuery($data)
|
||||
{
|
||||
$query = "INSERT INTO bko_users
|
||||
(
|
||||
pid,
|
||||
firstname,
|
||||
lastname,
|
||||
email,
|
||||
username,
|
||||
password,
|
||||
plevel,
|
||||
status,
|
||||
last_login,
|
||||
loc
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
" . $data['pid'] . ",
|
||||
'" . pg_escape_string($data['firstname']) . "',
|
||||
'" . pg_escape_string($data['lastname']) . "',
|
||||
'" . pg_escape_string($data['email']) . "',
|
||||
'" . pg_escape_string($data['username']) . "',
|
||||
'" . pg_escape_string(md5($data['password'])) . "',
|
||||
" . $data['plevel'] . ",
|
||||
" . $data['status'] . ",
|
||||
" . ($data['last_login'] ? "'" . pg_escape_string($data['last_login']) . "'" : 'NULL') . ",
|
||||
" . ($data['loc'] ? "'" . pg_escape_string($data['loc']) . "'" : 'NULL') . "
|
||||
) ON CONFLICT (username) DO UPDATE SET
|
||||
pid = " . $data['pid'] . ",
|
||||
firstname = '" . pg_escape_string($data['firstname']) . "',
|
||||
lastname = '" . pg_escape_string($data['lastname']) . "',
|
||||
email = '" . pg_escape_string($data['email']) . "',
|
||||
" . (empty($data['password']) ? "" : "password = '" . pg_escape_string(md5($data['password'])) . "',") . "
|
||||
plevel = " . $data['plevel'] . ",
|
||||
status = " . $data['status'] . ",
|
||||
last_login = " . ($data['last_login'] ? "'" . pg_escape_string($data['last_login']) . "'" : 'NULL') . ",
|
||||
loc = " . ($data['loc'] ? "'" . pg_escape_string($data['loc']) . "'" : 'NULL') . "
|
||||
RETURNING *,
|
||||
CASE WHEN xmax::text::int > 0
|
||||
THEN 'updated' else 'inserted' END AS active";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getAdminListQuery($params = [])
|
||||
{
|
||||
|
||||
$whereQuery = ' WHERE 1 = 1 ';
|
||||
|
||||
if (!empty($params['pid'])) {
|
||||
$whereQuery .= " AND pid = " . pg_escape_string($params['pid']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['plevel'])) {
|
||||
$whereQuery .= " AND plevel = " . pg_escape_string($params['plevel']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['first_name'])) {
|
||||
$whereQuery .= " AND firstname ILIKE '%" . pg_escape_string(trim($params['first_name'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['last_name'])) {
|
||||
$whereQuery .= " AND lastname ILIKE '%" . pg_escape_string(trim($params['last_name'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['email'])) {
|
||||
$whereQuery .= " AND email ILIKE '%" . pg_escape_string(trim($params['email'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['username'])) {
|
||||
$whereQuery .= " AND username ILIKE '%" . pg_escape_string(trim($params['username'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['last_login'])) {
|
||||
// last_login format: 2020-02-03 - 2020-03-01
|
||||
$fromToArray = explode(' - ', $params['last_login']);
|
||||
$fromDate = $fromToArray[0];
|
||||
$toDate = $fromToArray[1];
|
||||
|
||||
$whereQuery .= " AND to_char(last_login, 'YYYY-MM-DD') >= '" . pg_escape_string($fromDate) . "'
|
||||
AND to_char(last_login, 'YYYY-MM-DD') <= '" . pg_escape_string($toDate) . "' ";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT *,
|
||||
to_char(added, 'YYYY-MM-DD') AS added,
|
||||
to_char(last_login, 'YYYY-MM-DD') AS last_login
|
||||
FROM
|
||||
bko_users
|
||||
" . $whereQuery . "
|
||||
ORDER BY
|
||||
username
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Block_ip_model extends CI_Model
|
||||
{
|
||||
public function __constructor()
|
||||
{
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function getBlockIpQuery($params = [])
|
||||
{
|
||||
$whereQuery = '';
|
||||
|
||||
if (!empty($params['ip_address_filter'])) {
|
||||
$whereQuery .= " AND ip = '" . pg_escape_string(trim($params['ip_address_filter'])) . "' ";
|
||||
}
|
||||
|
||||
if (!empty($params['reason_filter'])) {
|
||||
$whereQuery .= " AND reason ILIKE '%" . pg_escape_string(trim($params['reason_filter'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['blocked_date_filter'])) {
|
||||
// blocked_date_filter format: 2020-02-03 - 2020-03-01
|
||||
$fromToArray = explode(' - ', $params['blocked_date_filter']);
|
||||
$fromDate = $fromToArray[0];
|
||||
$toDate = $fromToArray[1];
|
||||
|
||||
$whereQuery .= " AND to_char(blocked, 'YYYY-MM-DD') >= '" . pg_escape_string($fromDate) . "'
|
||||
AND to_char(blocked, 'YYYY-MM-DD') <= '" . pg_escape_string($toDate) . "'
|
||||
";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
id,
|
||||
ip,
|
||||
reason,
|
||||
blocked,
|
||||
"
|
||||
. " '<button style=\"padding:3px;\" type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"confirmUnblockIp(''' || ip || ''');\" >Unblock</button>' "
|
||||
. " AS ACT "
|
||||
. " "
|
||||
. "
|
||||
FROM
|
||||
block_ip
|
||||
WHERE
|
||||
id > 0
|
||||
" . $whereQuery . "
|
||||
ORDER BY
|
||||
id ASC
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Blog_app_article_model extends CI_Model {
|
||||
|
||||
public function __constructor() {
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function getBlogs($params = null, $page = 0, $limit = 10) {
|
||||
$queryString = 'SELECT * FROM blog_app_articles';
|
||||
$countString = 'SELECT COUNT(*) FROM blog_app_articles';
|
||||
$whereString = ' WHERE 1=1';
|
||||
$orderByString = ' ORDER BY id DESC';
|
||||
$offset = $page * $limit;
|
||||
$paginationString = " LIMIT $limit OFFSET $offset";
|
||||
|
||||
if(isset($params['blog_id']) && !empty($params['blog_id'])) {
|
||||
$whereString .= " AND blog_id = '" . pg_escape_string($params['blog_id']) . "' ";
|
||||
}
|
||||
|
||||
if(isset($params['status']) && $params['status'] > -1) {
|
||||
$whereString .= " AND status = '" . pg_escape_string($params['status']) . "' ";
|
||||
}
|
||||
|
||||
if(isset($params['description']) && !empty($params['description'])) {
|
||||
$whereString .= " AND description ILIKE '%" . pg_escape_string($params['description']) . "%' ";
|
||||
}
|
||||
|
||||
$queryString .= $whereString . $orderByString . $paginationString;
|
||||
$countString .= $whereString;
|
||||
|
||||
$query = $this->db->query($queryString);
|
||||
$countQuery = $this->db->query($countString);
|
||||
|
||||
$data = [
|
||||
'result' => $query->result_array(),
|
||||
'total' => $countQuery->result_array()[0]['count'],
|
||||
'pageSize' => $limit,
|
||||
'pageNo' => $page
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function store($data) {
|
||||
$this->db->insert('blog_app_articles', $data);
|
||||
}
|
||||
|
||||
public function update($id, $data) {
|
||||
$this->db->update('blog_app_articles', $data, "id = $id");
|
||||
}
|
||||
|
||||
public function delete($params) {
|
||||
$this->db->delete('blog_app_articles', $params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Blog_model extends CI_Model {
|
||||
|
||||
public function __constructor() {
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function getBlogs($params = null, $page = 0, $limit = 10) {
|
||||
$queryString = 'SELECT * FROM blogs';
|
||||
$countString = 'SELECT COUNT(*) FROM blogs';
|
||||
$whereString = ' WHERE 1=1';
|
||||
$orderByString = ' ORDER BY id DESC';
|
||||
$offset = $page * $limit;
|
||||
$paginationString = " LIMIT $limit OFFSET $offset";
|
||||
|
||||
if(isset($params['blog_id']) && !empty($params['blog_id'])) {
|
||||
$whereString .= " AND blog_id = '" . pg_escape_string($params['blog_id']) . "' ";
|
||||
}
|
||||
|
||||
if(isset($params['status']) && $params['status'] > -1) {
|
||||
$whereString .= " AND status = '" . pg_escape_string($params['status']) . "' ";
|
||||
}
|
||||
|
||||
if(isset($params['description']) && !empty($params['description'])) {
|
||||
$whereString .= " AND description ILIKE '%" . pg_escape_string($params['description']) . "%' ";
|
||||
}
|
||||
|
||||
$queryString .= $whereString . $orderByString . $paginationString;
|
||||
$countString .= $whereString;
|
||||
|
||||
$query = $this->db->query($queryString);
|
||||
$countQuery = $this->db->query($countString);
|
||||
|
||||
$data = [
|
||||
'result' => $query->result_array(),
|
||||
'total' => $countQuery->result_array()[0]['count'],
|
||||
'pageSize' => $limit,
|
||||
'pageNo' => $page
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function store($data) {
|
||||
$this->db->insert('blogs', $data);
|
||||
}
|
||||
|
||||
public function update($id, $data) {
|
||||
$this->db->update('blogs', $data, "id = $id");
|
||||
}
|
||||
|
||||
public function delete($params) {
|
||||
$this->db->delete('blogs', $params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,110 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Booking_model extends CI_Model {
|
||||
|
||||
public function __constructor() {
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function getReports($params = null, $page = 0, $limit = 10) {
|
||||
$queryString = 'SELECT * FROM booking';
|
||||
$countString = 'SELECT COUNT(*) FROM booking';
|
||||
$whereString = ' WHERE 1=1';
|
||||
$orderByString = ' ORDER BY created DESC';
|
||||
$offset = $page * $limit;
|
||||
$paginationString = " LIMIT $limit OFFSET $offset";
|
||||
|
||||
if (isset($params['id']) && !empty($params['id'])) {
|
||||
$whereString .= " AND id = '" . pg_escape_string($params['id']) . "' ";
|
||||
}
|
||||
|
||||
if (isset($params['quote_id']) && !empty($params['quote_id'])) {
|
||||
$whereString .= " AND quote_id = '" . pg_escape_string($params['quote_id']) . "' ";
|
||||
}
|
||||
|
||||
if (isset($params['member_id']) && !empty($params['member_id'])) {
|
||||
$whereString .= " AND member_id = '" . pg_escape_string($params['member_id']) . "' ";
|
||||
}
|
||||
|
||||
if (isset($params['cost']) && $params['cost'] != '') {
|
||||
$whereString .= " AND cost = '" . pg_escape_string($params['cost']) . "' ";
|
||||
}
|
||||
|
||||
if (isset($params['provider_booking_ref']) && !empty($params['provider_booking_ref'])) {
|
||||
$whereString .= " AND provider_booking_ref ILIKE '%" . pg_escape_string($params['provider_booking_ref']) . "%' ";
|
||||
}
|
||||
|
||||
if (isset($params['message']) && !empty($params['message'])) {
|
||||
$whereString .= " AND message ILIKE '%" . pg_escape_string($params['message']) . "%' ";
|
||||
}
|
||||
|
||||
// if (isset($params['details']) && !empty($params['details'])) {
|
||||
// // Filter JSON data
|
||||
// }
|
||||
|
||||
if (isset($params['status']) && !empty($params['status'])) {
|
||||
switch ($params['status']) {
|
||||
case 'pending':
|
||||
$whereString .= " AND status = 1 ";
|
||||
break;
|
||||
case 'cancelled':
|
||||
$whereString .= " AND status = 3 ";
|
||||
break;
|
||||
case 'active':
|
||||
$whereString .= " AND status IN (2, 4) ";
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (isset($params['created']) && !empty($params['created'])) {
|
||||
$created = explode(' - ', $params['created']);
|
||||
$whereString .= " AND created BETWEEN '$created[0] 00:00:00' AND '$created[1] 23:59:59.99' ";
|
||||
}
|
||||
|
||||
if (isset($params['updated']) && !empty($params['updated'])) {
|
||||
$updated = explode(' - ', $params['updated']);
|
||||
$whereString .= " AND updated BETWEEN '$updated[0] 00:00:00' AND '$updated[1] 23:59:59.99' ";
|
||||
}
|
||||
|
||||
if (isset($params['completed']) && !empty($params['completed'])) {
|
||||
$completed = explode(' - ', $params['completed']);
|
||||
$whereString .= " AND completed BETWEEN '$completed[0] 00:00:00' AND '$completed[1] 23:59:59.99' ";
|
||||
}
|
||||
|
||||
$queryString .= $whereString . $orderByString . $paginationString;
|
||||
$countString .= $whereString;
|
||||
|
||||
$query = $this->db->query($queryString);
|
||||
$countQuery = $this->db->query($countString);
|
||||
|
||||
$data = [
|
||||
'result' => $query->result_array(),
|
||||
'total' => $countQuery->result_array()[0]['count'],
|
||||
'pageSize' => $limit,
|
||||
'pageNo' => $page
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function store($data) {
|
||||
$this->db->insert('booking', $data);
|
||||
}
|
||||
|
||||
public function update($id, $data) {
|
||||
$this->db->update('booking', $data, "id = $id");
|
||||
}
|
||||
|
||||
public function delete($params) {
|
||||
$this->db->delete('booking', $params);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,79 @@
|
||||
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Card_image_model extends CI_Model {
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function get_card_image_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
|
||||
$combo_array = [
|
||||
];
|
||||
|
||||
$numberic_array = [
|
||||
'category_id' => 'b.id',
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'unique_id' => 'a.uniqueid',
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'a.id',
|
||||
'a.uniqueid',
|
||||
'a.name',
|
||||
'a.created',
|
||||
'a.file_size',
|
||||
'a.format',
|
||||
'a.dimensions',
|
||||
'b.description AS category_name',
|
||||
'b.name AS bucket'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('card_images a');
|
||||
$this->read_replica->join('card_image_category b', 'b.id = a.catid', 'left');
|
||||
|
||||
$this->read_replica->where('a.t1', 'FF');
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numberic_array)) {
|
||||
|
||||
$this->read_replica->where($numberic_array[$key], $val);
|
||||
|
||||
} else if (strpos($key, 'from') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(a.created) >=', $val);
|
||||
|
||||
} else if (strpos($key, 'to') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(a.created) <=', $val);
|
||||
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Carpool_friend_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_friend_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
|
||||
$combo_array = [
|
||||
'proc_status' => 'cf.status',
|
||||
'status' => 'cf.status'
|
||||
];
|
||||
|
||||
$numeric_array = [
|
||||
'member_id' => 'cp.member_id',
|
||||
'carpool_id' => 'cf.carpool_id'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'(CASE
|
||||
WHEN cf.status = 1 THEN \'Pending\'
|
||||
WHEN cf.status = 4 THEN \'Accepted\'
|
||||
ELSE cf.status::text END
|
||||
) AS proc_status',
|
||||
'\'<a href =/member/viewLocateMember?member_id=\'||m.id||\'>\'||m.firstname||\'</a>\' AS Member',
|
||||
'm.id AS member_id',
|
||||
'cf.*'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('members_carpool_friends cf');
|
||||
$this->read_replica->join('members_carpool cp', 'cp.id=cf.carpool_id', 'left');
|
||||
$this->read_replica->join('members m', 'm.id = cp.member_id', 'left');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numeric_array)) {
|
||||
|
||||
$this->read_replica->where($key, $val);
|
||||
|
||||
} else if (strpos($key, 'from') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(cf.added) >=', $val);
|
||||
|
||||
} else if (strpos($key, 'to') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(cf.added) <=', $val);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->like('lower(cf.' . $key . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,784 @@
|
||||
<?php
|
||||
|
||||
class Combo_model extends CI_Model {
|
||||
|
||||
var $optCons = '';
|
||||
var $currentStyle = 'form-control';
|
||||
var $readOnlyMode = false;
|
||||
var $defaultComboMessage = 'Select...';
|
||||
var $showDefaultSelect = true;
|
||||
var $defaultComboValue = '';
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->db = $this->load->database('savvy_replica', true);
|
||||
}
|
||||
|
||||
public function getCardList() {
|
||||
return 'Tokun';
|
||||
}
|
||||
|
||||
public function getCardIconsCombo($option_name, $curVal) {
|
||||
$yesno_array = [
|
||||
'deal' => 'Deal',
|
||||
'survey' => 'Survey',
|
||||
'data' => 'Data',
|
||||
'tip' => 'Tip',
|
||||
'carpool' => 'Carpool',
|
||||
'trips' => 'Trips'
|
||||
];
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
|
||||
//trigger_expiration (description,expiration)
|
||||
|
||||
public function getTriggerExpirationCombo($option_name, $curVal) {
|
||||
$sql = "SELECT expiration AS id,expiration||'-'||description AS description FROM trigger_expiration WHERE status = 1 ORDER BY id ASC ";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "description", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getTriggerCardsCombo($option_name, $curVal) {
|
||||
$sql = "SELECT id,id||'-: '||name||' - '||title AS description FROM main_cards WHERE button1_action = 'CARDDYNAMIC' ";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "description", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getPointsSettingsCombo($option_name, $curVal) {
|
||||
$sql = "SELECT point_key AS id,point_key||'-'||name||' - '||value||' Points' AS description FROM points_settings WHERE value>0 AND activated = 1 ORDER BY id ASC";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "description", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getTriggerFrequency($option_name, $curVal)
|
||||
{
|
||||
$vals = [1, 2, 3, 4, 5, 6, 7, 10, 14, 30];
|
||||
$opts[''] = '- Select -';
|
||||
foreach ($vals as $val) {
|
||||
$opts[$val] = $val . ($val > 1 ? ' Days' : ' Day');
|
||||
}
|
||||
$option_value = $this->optionValueArray($opts, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getTriggerSendDay($option_name, $curVal)
|
||||
{
|
||||
$opts = [
|
||||
'' => '- Select -',
|
||||
'instant_send' => 'Instant Send',
|
||||
'no_day_specified' => 'No Day Specified',
|
||||
'monday' => 'Monday',
|
||||
'tuesday' => 'Tuesday',
|
||||
'wednesday' => 'Wednesday',
|
||||
'thursday' => 'Thursday',
|
||||
'friday' => 'Friday',
|
||||
'saturday' => 'Saturday',
|
||||
'sunday' => 'Sunday',
|
||||
];
|
||||
$option_value = $this->optionValueArray($opts, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getTriggerSendTime($option_name, $curVal)
|
||||
{
|
||||
$opts[''] = '- Select -';
|
||||
//AM
|
||||
$opts['00:00:00'] = '12:00 AM';
|
||||
for ($i = 1; $i <= 11; $i++)
|
||||
$opts[sprintf('%02d', $i) . ':00:00'] = sprintf('%02d', $i) . ':00 AM';
|
||||
//PM
|
||||
$opts['12:00:00'] = '12:00 PM';
|
||||
for ($i = 1; $i <= 11; $i++)
|
||||
$opts[sprintf('%02d', $i + 12) . ':00:00'] = sprintf('%02d', $i) . ':00 PM';
|
||||
$option_value = $this->optionValueArray($opts, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
/**
|
||||
* Get points setting for searching subscription deals report
|
||||
* @param string $option_name filter name
|
||||
* @param int $curVal current points
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPointsSubscribedDeals( $option_name, $curVal ) {
|
||||
$sql = sprintf("SELECT distinct value from points_settings where value > 0 and activated = 1 order by value asc");
|
||||
$query = $this->db->query( $sql );
|
||||
$option_value = $this->optionValueObject( $query->result(), 'value', 'value', $curVal );
|
||||
|
||||
return $this->comboFrame( $option_name, $option_value );
|
||||
}
|
||||
|
||||
public function getGPSTriggerLocationCombo($option_name, $curVal) {
|
||||
$sql = "SELECT id, description FROM gps_trigger_location ORDER BY id ASC";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "description", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getSurvelListGroupCombo($option_name, $curVal) {
|
||||
$sql = "SELECT id,title,status FROM main_cards WHERE button1_action = 'SURVEYA' AND status = 1 ORDER BY title";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "title", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getfindMemberType(
|
||||
$option_name,
|
||||
$curVal,
|
||||
$yesno_array = [
|
||||
'email' => 'Email',
|
||||
'firstname' => 'Firstname',
|
||||
'lastname' => 'Lastname'
|
||||
]) {
|
||||
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getDescisionGroupCombo($option_name, $curVal) {
|
||||
$sql = "SELECT dkey,description FROM decision_group where status =1 ORDER by lorder ASC";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "dkey", "description", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardBehaveCombo($option_name, $curVal) {
|
||||
$sql = "SELECT * FROM card_behavior WHERE status=1 ";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "key", "name", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
|
||||
public function getCardblogIdCombo($option_name, $curVal) {
|
||||
$sql = "SELECT blog_id,description, blog_id||'-'||description AS desc2 FROM blog_app_articles WHERE status=1 ORDER BY id ASC";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "blog_id", "desc2", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardTargetActionCombo($option_name, $curVal) {
|
||||
$sql = "SELECT * FROM card_action_target WHERE status=1 ";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "target_key", "description", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardCategoryComboAll($option_name, $curVal) {
|
||||
|
||||
$exl2 = "";
|
||||
|
||||
$sql = "SELECT * FROM card_category ";
|
||||
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "cat", "name", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardCategoryCombo($option_name, $curVal, $fixCat = '', $excludeCat = '') {
|
||||
|
||||
$exl2 = "";
|
||||
if (trim($excludeCat) != '') {
|
||||
$exl2 = " AND cat NOT IN ('$excludeCat')";
|
||||
}
|
||||
|
||||
if (trim($fixCat) == '') {
|
||||
$sql = "SELECT * FROM card_category WHERE status=1 AND special =0 " . $exl2;
|
||||
} else {
|
||||
$sql = "SELECT * FROM card_category WHERE status=1 AND cat='$fixCat' ";
|
||||
}
|
||||
|
||||
$sql = $sql ." ORDER BY name ASC";
|
||||
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "cat", "name", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getStatusCombo($option_name, $curVal) {
|
||||
$yesno_array = [
|
||||
'0' => 'Not-Active',
|
||||
'1' => 'Active'
|
||||
];
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getTitleShowCombo($option_name, $curVal) {
|
||||
$yesno_array = [
|
||||
'1' => 'Show Title',
|
||||
'0' => 'Hide Title'
|
||||
];
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardTemplateCombo($option_name, $curVal) {
|
||||
$yesno_array = [
|
||||
'0' => 'Default Layout 600x600 Text+image',
|
||||
'1' => 'Short Layout 600x300 Text+image',
|
||||
'2' => 'Short Layout 600x300 Image only',
|
||||
'3' => 'Tall Layout 600x600 image only',
|
||||
'5' => 'Tall Layout 600x600 image + text',
|
||||
'4' => 'Short Layout 600x300 Solid Color 1',
|
||||
'6' => 'Default Layout 600x600 Image only',
|
||||
'7' => 'Active Tip 600 x 300',
|
||||
'8' => 'Upper Title 600x600 text + image',
|
||||
'9' => 'Tall Layout 600x750 text + image',
|
||||
'10' => 'Tall Layout upper title 600x800 text + image',
|
||||
];
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getSurveyCardTemplateCombo($option_name, $curVal) {
|
||||
$yesno_array = [
|
||||
'9901' => 'Default Survey',
|
||||
'9902' => 'Swipe Survey 600 x 600'
|
||||
];
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardCategoryType($option_name, $curVal) {
|
||||
$yesno_array = [
|
||||
'' => 'No Type',
|
||||
'A' => 'Type A',
|
||||
'B' => 'Type B',
|
||||
'C' => 'Type C',
|
||||
'D' => 'Type D',
|
||||
'E' => 'Type E'
|
||||
];
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardLocation($option_name, $curVal) {
|
||||
|
||||
$sql = "SELECT id,description FROM address WHERE description != ''";
|
||||
/*
|
||||
$yesno_array = [
|
||||
'0' => 'No Location',
|
||||
'1' => '4201 Defoors Farm trail, ga 30127',
|
||||
'2' => 'Location B',
|
||||
'3' => 'Location C'
|
||||
|
||||
];
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
*/ $this->defaultComboMessage = "No Location Attached";
|
||||
$this->defaultComboValue = '0';
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "description", $curVal);
|
||||
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getReciept($option_name, $curVal) {
|
||||
|
||||
$sql = "SELECT id,name,active FROM transport_providers WHERE active =1 ORDER BY name";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "name", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardPoint($option_name, $curVal) {
|
||||
$cardtime_array = [
|
||||
'0' => 'No Points Applicable'
|
||||
];
|
||||
for ($i = 1; $i < 24; $i++) {
|
||||
$points = $i * 50;
|
||||
$cardtime_array = array_merge($cardtime_array, array($points => "$points Points"));
|
||||
}
|
||||
|
||||
$option_value = $this->optionValueArray($cardtime_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardTime($option_name, $curVal) {
|
||||
$cardtime_array = [
|
||||
'' => 'No Specific Time',
|
||||
'12:AM' => '12:AM'
|
||||
];
|
||||
for ($i = 1; $i < 12; $i++) {
|
||||
$cardtime_array = array_merge($cardtime_array, array("$i:AM" => "$i:AM"));
|
||||
}
|
||||
$cardtime_array = array_merge($cardtime_array, array("12:PM" => "12:PM"));
|
||||
for ($i = 1; $i < 12; $i++) {
|
||||
$cardtime_array = array_merge($cardtime_array, array("$i:PM" => "$i:PM"));
|
||||
}
|
||||
|
||||
$option_value = $this->optionValueArray($cardtime_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getYesNoCombo($option_name, $curVal) {
|
||||
$yesno_array = [
|
||||
'0' => 'No',
|
||||
'1' => 'Yes'
|
||||
];
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardPicturesCombo($option_name, $curVal) {
|
||||
global $savvyext;
|
||||
$storage = $savvyext->cfgReadChar('system.storage_url');
|
||||
|
||||
$sql = "SELECT '{$storage}cards/'||uniqueid||'.'||format AS id,"
|
||||
. " id||' ['|| file_size*0.01 ||'kb] -{$storage}cards/'||uniqueid||'.'||format AS val FROM card_images";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "val", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getJobPostDuration($option_name, $duration) {
|
||||
$this->defaultComboMessage = 'Select duration of post';
|
||||
$cmbstr = "";
|
||||
for ($ii = 2; $ii <= 10; $ii++) {
|
||||
|
||||
$cmbstr .= "<option value='$ii'>$ii day(s)</option>";
|
||||
}
|
||||
|
||||
for ($ii = 2; $ii <= 5; $ii++) {
|
||||
$days_c = $ii * 7;
|
||||
$cmbstr .= "<option value='$days_c'>$ii Weeks</option>";
|
||||
}
|
||||
return $this->comboFrame($option_name, $cmbstr);
|
||||
}
|
||||
|
||||
public function getUserJobGroupCombo($option_name, $member_id, $curVal) {
|
||||
|
||||
// $sql = "SELECT id,group_name FROM members_job_group WHERE member_id = $member_id AND status = 1 ORDER BY group_name ASC ";
|
||||
$sql = "SELECT m.id,m.group_name, m.group_name||' ['||count(g.group_id)||' members]' AS member_group_count "
|
||||
. "FROM members_job_group m "
|
||||
. "LEFT JOIN members_job_groupmember g ON g.group_id = m.id "
|
||||
. "WHERE m.member_id = $member_id "
|
||||
. "AND m.status = 1 GROUP BY m.id,m.group_name ORDER BY m.group_name ASC";
|
||||
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "member_group_count", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getUserRecipientCombo($option_name, $member_id, $curVal) {
|
||||
|
||||
$sql = "SELECT b.id,b.firstname||' '||b.lastname||' '||b.account_no||' '||k.name AS recipient "
|
||||
. "FROM sendmoney_recipient b "
|
||||
. "LEFT JOIN bank_entity_codes k ON k.code=b.bank_code "
|
||||
. "WHERE b.member_id = $member_id AND b.status=1";
|
||||
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "recipient", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getAccountTypeCombo($option_name, $curVal) {
|
||||
$q = $this
|
||||
->db
|
||||
->where('status', 1)
|
||||
->order_by('type_name', 'ASC')
|
||||
->get('account_types');
|
||||
|
||||
$option_value = $this->optionValueObject($q->result(), "type_value", "type_name", $curVal);
|
||||
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getGeneralSkillCombo($option_name, $curVal) {
|
||||
$this->showDefaultSelect = false;
|
||||
$q = $this
|
||||
->db
|
||||
->where('status', 1)
|
||||
->order_by('lorder', 'DESC')
|
||||
->get('skill_category');
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "category", $curVal);
|
||||
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getUserNewSkillCombo($option_name, $curVal, $category_id, $member_id) {
|
||||
$q = $this
|
||||
->db
|
||||
->where('status', 1)
|
||||
->where('category_id', $category_id)
|
||||
->order_by('lorder', 'DESC')
|
||||
->get('skill_types');
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "skill", $curVal);
|
||||
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function setReadOnly($bl) {
|
||||
$this->readOnlyMode = $bl;
|
||||
}
|
||||
|
||||
public function getCountryCombo($option_name, $curVal) {
|
||||
$q = $this
|
||||
->db
|
||||
->where('status', 1)
|
||||
->order_by('country', 'ASC')
|
||||
->get('country');
|
||||
|
||||
$option_value = $this->optionValueObject($q->result(), "code", "country", $curVal);
|
||||
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getTransportProvidersCombo($option_name, $curVal) {
|
||||
$q = $this
|
||||
->db
|
||||
->where('active', 1)
|
||||
->order_by('name', 'ASC')
|
||||
->get('transport_providers');
|
||||
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "name", $curVal);
|
||||
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
private function optionValueArray($sdStd, $val) {
|
||||
$this->optCons = '';
|
||||
foreach ($sdStd as $key => $value) {
|
||||
$selV = '';
|
||||
if ($key == $val) {
|
||||
$selV = " selected ";
|
||||
}
|
||||
$this->optCons .= "<option value='" . $key . "' " . $selV . ">" . $value . "</option>";
|
||||
}
|
||||
return $this->optCons;
|
||||
}
|
||||
|
||||
private function optionValueObject($sdStd, $val, $valname, $curVal) {
|
||||
$this->optCons = '';
|
||||
if ($this->showDefaultSelect == true) {
|
||||
$this->optCons .= "<option value='" . $this->defaultComboValue . "'>" . $this->defaultComboMessage . "</option>";
|
||||
}
|
||||
|
||||
|
||||
foreach ($sdStd as $row) {
|
||||
$selV = '';
|
||||
if ($curVal == $row->$val) {
|
||||
$selV = " selected ";
|
||||
}
|
||||
$this->optCons .= "<option value='" . $row->$val . "' " . $selV . ">" . $row->$valname . "</option>";
|
||||
}
|
||||
return $this->optCons;
|
||||
}
|
||||
|
||||
private function comboFrame($option_name, $option_value) {
|
||||
$addReaOnly = "";
|
||||
if ($this->readOnlyMode == true) {
|
||||
$addReaOnly = " disabled ";
|
||||
}
|
||||
|
||||
|
||||
|
||||
$combo_to_return = $cmb = "<select data-placeholder='" . $this->defaultComboMessage . "' class='" . $this->currentStyle . "' name='$option_name' id='$option_name' $addReaOnly >$option_value</select>";
|
||||
$this->defaultComboMessage = "Select"; // house cleaning
|
||||
$this->defaultComboValue = '';
|
||||
return $combo_to_return;
|
||||
}
|
||||
|
||||
public function getCardActionTypeCombo($option_name, $curVal) {
|
||||
$options_array = [
|
||||
'alert' => 'Show Alert',
|
||||
'browser' => 'Open Browser',
|
||||
'deeplink' => 'Open App via Deeplink',
|
||||
'callback' => 'Call API'
|
||||
];
|
||||
$option_value = $this->optionValueArray($options_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getTimezoneCombo($option_name, $curVal = null) {
|
||||
$q = $this->db->get('address_timezone');
|
||||
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "timezone", $curVal);
|
||||
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
// put this function in the model and use for now for the Neighborhood combo
|
||||
public function getCountryNeighborhoodCombo($option_name, $country, $cState, $curVal) {
|
||||
$hood_array = [
|
||||
'0' => 'Neighborhood 100',
|
||||
'1' => 'Neighborhood 200',
|
||||
'2' => 'Neighborhood 300',
|
||||
'3' => 'Neighborhood 400',
|
||||
'5' => 'Neighborhood 500',
|
||||
'4' => 'Neighborhood 600',
|
||||
'6' => 'Neighborhood 700'
|
||||
];
|
||||
$option_value = $this->optionValueArray($hood_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getControllerCombo($option_name, $options_array, $curVal) {
|
||||
$option_value = $this->optionValueArray($options_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getPermissionLevel($option_name, $curVal) {
|
||||
$sql = "SELECT * FROM bko_permission_level WHERE status=1 ";
|
||||
$q = $this->db->query($sql);
|
||||
$option_value = $this->optionValueObject($q->result(), "plevel", "name", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getControllerAndMethodCombo($option_name, $options_array, $curVal) {
|
||||
$option_value = $this->optionValueArray($options_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCityCombo($option_name, $curVal) {
|
||||
$q = $this
|
||||
->db
|
||||
->order_by('city', 'ASC')
|
||||
->get('geofence_area_city');
|
||||
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "city", $curVal);
|
||||
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getGeofenceAreaCombo($option_name, $curVal) {
|
||||
$q = $this
|
||||
->db
|
||||
->order_by('name', 'ASC')
|
||||
->get('geofence_area');
|
||||
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "name", $curVal);
|
||||
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getAccAndEmailCombo($option_name, $curVal) {
|
||||
$array = [
|
||||
'ALL' => 'ALL',
|
||||
'ACC' => 'ACC',
|
||||
'EMAIL' => 'EMAIL',
|
||||
];
|
||||
$option_value = $this->optionValueArray($array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getMsgStatusCombo($option_name, $curVal = null) {
|
||||
$array = [
|
||||
'' => 'ALL',
|
||||
'1' => 'Pending',
|
||||
'2' => 'Expired',
|
||||
'3' => 'Cancelled',
|
||||
'5' => 'Completed'
|
||||
];
|
||||
|
||||
$option_value = $this->optionValueArray($array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getStatusComboWithAll($option_name, $curVal, $custom_options = []) {
|
||||
$yesno_array = [
|
||||
'-1' => 'ALL',
|
||||
'0' => 'InActive',
|
||||
'1' => 'Active'
|
||||
];
|
||||
|
||||
if (!empty($custom_options)) {
|
||||
foreach ($custom_options as $key => $val) {
|
||||
if (array_key_exists($key ,$yesno_array)) {
|
||||
$yesno_array[$key] = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getYesNoComboWithAll($option_name, $curVal) {
|
||||
$yesno_array = [
|
||||
'-1' => 'ALL',
|
||||
'0' => 'No',
|
||||
'1' => 'Yes'
|
||||
];
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getStatusComboFromZeroToNine($option_name, $curVal) {
|
||||
$status_array = range(0, 9);
|
||||
$status_array['-1'] = 'ALL';
|
||||
ksort($status_array);
|
||||
|
||||
$option_value = $this->optionValueArray($status_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getStatusComboFromZeroToOne($option_name, $curVal) {
|
||||
$status_array = range(0, 1);
|
||||
$status_array['-1'] = 'ALL';
|
||||
ksort($status_array);
|
||||
|
||||
$option_value = $this->optionValueArray($status_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardImageCategoryCombo($option_name, $curVal) {
|
||||
$q = $this->db
|
||||
->order_by('description')
|
||||
->get('card_image_category');
|
||||
|
||||
$option_value = $this->optionValueObject($q->result(), "id", "description", $curVal);
|
||||
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCountryComboWithoutFilter($option_name, $curVal) {
|
||||
$q = $this
|
||||
->db
|
||||
->order_by('country', 'ASC')
|
||||
->get('country');
|
||||
|
||||
$option_value = $this->optionValueObject($q->result(), "code", "country", $curVal);
|
||||
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getQuoteSourceCombo($option_name, $curVal) {
|
||||
$yesno_array = [
|
||||
'' => 'All',
|
||||
0 => 'Application',
|
||||
1 => 'Automatic'
|
||||
];
|
||||
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCompletedCombo($option_name, $curVal)
|
||||
{
|
||||
$yesno_array = [
|
||||
'-1' => 'All',
|
||||
'0' => 'Pending',
|
||||
'1' => 'Complete'
|
||||
];
|
||||
|
||||
$option_value = $this->optionValueArray($yesno_array, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardActivityScreen($option_name, $curVal)
|
||||
{
|
||||
$opts = [];
|
||||
for ($i = 1; $i <= 5; $i++) {
|
||||
$opts[$i] = 'Screen ' . $i;
|
||||
}
|
||||
$option_value = $this->optionValueArray($opts, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardShowArea($option_name, $curVal)
|
||||
{
|
||||
$opts = [
|
||||
0 => 'Default',
|
||||
1 => 'Main Feed Only',
|
||||
2 => 'Activity Screen Only',
|
||||
];
|
||||
$option_value = $this->optionValueArray($opts, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getScreenNames($option_name, $curVal)
|
||||
{
|
||||
$opts = [
|
||||
'' => 'Select',
|
||||
'activity-transactional-table' => 'activity-transactional-table',
|
||||
'activity-monthly-spent' => 'activity-monthly-spent',
|
||||
'activity-time-traveled' => 'activity-time-traveled',
|
||||
'activity-emissions' => 'activity-emissions',
|
||||
'activity-personality' => 'activity-personality',
|
||||
];
|
||||
$option_value = $this->optionValueArray($opts, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getTriggerIds($option_name, $curVal)
|
||||
{
|
||||
$q = $this
|
||||
->db
|
||||
->order_by('e_trigger', 'ASC')
|
||||
->get('email_trigger');
|
||||
$option_value = $this->optionValueObject($q->result(), "e_trigger", "e_trigger", $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getCardExpiration($option_name, $curVal)
|
||||
{
|
||||
$opts = [
|
||||
0 => 'Default',
|
||||
100 => 'One time click',
|
||||
];
|
||||
$option_value = $this->optionValueArray($opts, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
public function getCountriesHasAccount($option_name, $curVal){
|
||||
$sql = "SELECT code, country
|
||||
FROM country
|
||||
WHERE EXISTS (SELECT * FROM members WHERE country = country.code)
|
||||
ORDER BY code ASC";
|
||||
$vals = $this->db->query($sql)->result_array();
|
||||
$opts = [
|
||||
'' => '- All Countries -'
|
||||
];
|
||||
foreach ($vals as $val){
|
||||
$opts[$val['code']] = ''.$val['code'].' - '.$val['country'];
|
||||
}
|
||||
$opts['unknown'] = 'unknown';
|
||||
$option_value = $this->optionValueArray($opts, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getPointKeyUsed($option_name, $curVal) {
|
||||
$sql = "
|
||||
SELECT mp.point_key, ps.name as point_name
|
||||
FROM members_points mp
|
||||
INNER JOIN points_settings ps ON ps.point_key = mp.point_key
|
||||
WHERE mp.points > 0
|
||||
GROUP BY mp.point_key, ps.name";
|
||||
|
||||
$vals = $this->db->query($sql)->result_array();
|
||||
$opts = [
|
||||
'' => '- All Point Keys -'
|
||||
];
|
||||
|
||||
foreach ($vals as $val){
|
||||
$opts[$val['point_key']] = $val['point_key'] . ' - ' . $val['point_name'];
|
||||
}
|
||||
|
||||
$option_value = $this->optionValueArray($opts, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
|
||||
public function getPointValueUsed($option_name, $curVal) {
|
||||
$sql = "
|
||||
SELECT points as point_value
|
||||
FROM members_points mp
|
||||
WHERE points > 0
|
||||
GROUP BY points";
|
||||
|
||||
$vals = $this->db->query($sql)->result_array();
|
||||
$opts = [
|
||||
'' => '- All Point Value -'
|
||||
];
|
||||
|
||||
foreach ($vals as $val){
|
||||
$opts[$val['point_value']] = $val['point_value'];
|
||||
}
|
||||
|
||||
$option_value = $this->optionValueArray($opts, $curVal);
|
||||
return $this->comboFrame($option_name, $option_value);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Country_model extends CI_Model
|
||||
{
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function getAll()
|
||||
{
|
||||
$this->read_replica->order_by('country', 'ASC');
|
||||
$query = $this->read_replica->get('country');
|
||||
return $query->result();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Crash_log_model extends CI_Model
|
||||
{
|
||||
public function __constructor()
|
||||
{
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function getLogQuery($params = [])
|
||||
{
|
||||
$whereQuery = ' WHERE 1 = 1 ';
|
||||
|
||||
if (!empty($params['member_id_filter'])) {
|
||||
$whereQuery .= " AND a.member_id = " . pg_escape_string(trim($params['member_id_filter'])) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['username_filter'])) {
|
||||
$whereQuery .= " AND b.username ILIKE '%" . pg_escape_string(trim($params['username_filter'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['ip_address_filter'])) {
|
||||
$whereQuery .= " AND a.ip = '" . pg_escape_string(trim($params['ip_address_filter'])) . "' ";
|
||||
}
|
||||
|
||||
if (!empty($params['number_filter'])) {
|
||||
$whereQuery .= " AND a.number ILIKE '%" . pg_escape_string(trim($params['number_filter'])) . "%' ";
|
||||
}
|
||||
|
||||
|
||||
if (!empty($params['added_filter'])) {
|
||||
// added_filter format: 2020-02-03 - 2020-03-01
|
||||
$fromToArray = explode(' - ', $params['added_filter']);
|
||||
$fromDate = $fromToArray[0];
|
||||
$toDate = $fromToArray[1];
|
||||
|
||||
$whereQuery .= " AND to_char(a.added, 'YYYY-MM-DD') >= '" . pg_escape_string($fromDate) . "'
|
||||
AND to_char(a.added, 'YYYY-MM-DD') <= '" . pg_escape_string($toDate) . "'
|
||||
";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
'<button type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"return viewCrash(' || a.id || ',''' || a.number || ''')\">View</button>' AS edit,
|
||||
a.member_id,
|
||||
b.username,
|
||||
a.ip,
|
||||
a.number,
|
||||
a.added
|
||||
FROM
|
||||
crash_log a
|
||||
LEFT JOIN members b ON (b.id = a.member_id)
|
||||
" . $whereQuery . "
|
||||
ORDER BY
|
||||
a.added DESC
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
|
||||
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Credit_card_benefit_model extends CI_Model
|
||||
{
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function insert($data) {
|
||||
$data_insert = [];
|
||||
|
||||
foreach($data['benefits[]'] as $key => $val) {
|
||||
$data_insert[] = [
|
||||
'credit_card_id' => $data['credit_card_id'],
|
||||
'benefit' => $val,
|
||||
'expired_date' => (empty($data['expired_date[]'][$key])
|
||||
? null
|
||||
: $data['expired_date[]'][$key])
|
||||
];
|
||||
}
|
||||
|
||||
if ($data_insert) {
|
||||
$this->db->insert_batch('credit_card_benefits', $data_insert);
|
||||
}
|
||||
}
|
||||
|
||||
public function delete($data) {
|
||||
$this->db->where('credit_card_id', $data['credit_card_id']);
|
||||
$this->db->delete('credit_card_benefits');
|
||||
}
|
||||
|
||||
public function getBenefitByCardID($id) {
|
||||
$this->read_replica->select([
|
||||
'id',
|
||||
'benefit',
|
||||
'DATE(expired_date) AS expired_date'
|
||||
]);
|
||||
$this->read_replica->from('credit_card_benefits');
|
||||
$this->read_replica->where('credit_card_id', $id);
|
||||
$this->read_replica->order_by('benefit ASC');
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function update($data) {
|
||||
$data_update = [];
|
||||
|
||||
foreach($data['benefit_id'] as $key => $val) {
|
||||
$data_update[] = [
|
||||
'id' => $val,
|
||||
'benefit' => $data['benefit'][$key],
|
||||
'expired_date' => (empty($data['expired_date'][$key])
|
||||
? null
|
||||
: $data['expired_date'][$key])
|
||||
];
|
||||
}
|
||||
|
||||
if ($data_update) {
|
||||
$this->db->update_batch('credit_card_benefits', $data_update, 'id');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class credit_card_model extends CI_Model
|
||||
{
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function getData(
|
||||
$filters,
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
$string_array = [
|
||||
'bank_name_filter' => 'b.bank_name',
|
||||
'card_name_filter' => 'cc.card_name',
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'b.id AS bank_id',
|
||||
'cc.id AS credit_card_id',
|
||||
'COALESCE(b.bank_name, \'\') AS bank_name',
|
||||
'COALESCE(cc.card_name, \'\') AS card_name',
|
||||
]);
|
||||
|
||||
$this->read_replica->from('banks b');
|
||||
$this->read_replica->join('credit_cards cc', 'cc.bank_id = b.id');
|
||||
|
||||
foreach ($filters as $key => $value) {
|
||||
if (array_key_exists($key, $string_array)) {
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', mb_strtolower($value, 'UTF-8'));
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('b.bank_name ASC, cc.id DESC');
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function insert($data) {
|
||||
$data_insert = [
|
||||
'bank_id' => $data['bank_id'],
|
||||
'card_name' => $data['card_name']
|
||||
];
|
||||
|
||||
$this->db->insert('credit_cards', $data_insert);
|
||||
return $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function update($data) {
|
||||
$this->db->set('bank_id', $data['bank_id']);
|
||||
$this->db->set('card_name', $data['card_name']);
|
||||
$this->db->where('id', $data['credit_card_id']);
|
||||
$this->db->update('credit_cards');
|
||||
}
|
||||
|
||||
public function delete($data) {
|
||||
$this->db->where('id', $data['credit_card_id']);
|
||||
$this->db->delete('credit_cards');
|
||||
}
|
||||
|
||||
public function count_credit_card($data) {
|
||||
$this->read_replica->select('count(*) as all_count');
|
||||
$this->read_replica->from('credit_cards');
|
||||
$this->read_replica->where('bank_id', $data['bank_id']);
|
||||
|
||||
return $this->read_replica->get()->result_array()[0]['all_count'];
|
||||
}
|
||||
|
||||
public function countRecordsByBankAndCardName($data) {
|
||||
$this->read_replica->select('count(b.id) as all_count');
|
||||
$this->read_replica->from('banks b');
|
||||
$this->read_replica->join('credit_cards cc', 'cc.bank_id = b.id');
|
||||
$this->read_replica->where('lower(b.bank_name)', mb_strtolower($data['bank_name'], 'UTF-8'));
|
||||
$this->read_replica->where('lower(cc.card_name)', mb_strtolower($data['card_name'], 'UTF-8'));
|
||||
return $this->read_replica->get()->result_array()[0]['all_count'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,404 @@
|
||||
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Decision_model extends CI_Model {
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function get_decision_logic_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
|
||||
$combo_array = [
|
||||
'status' => 'status',
|
||||
'survey' => 'survey'
|
||||
];
|
||||
|
||||
$numberic_array = [
|
||||
'from_weight' => 'weight >=',
|
||||
'to_weight' => 'weight <='
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'logic' => 'logic',
|
||||
'description' => 'description'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'id',
|
||||
'lorder',
|
||||
'logic',
|
||||
'description',
|
||||
'CASE WHEN status = 1 THEN \'Active\' ELSE \'Inactive\' END AS status',
|
||||
'CASE WHEN survey = 1 THEN \'Yes\' ELSE \'No\' END AS survey',
|
||||
'\'<input type="text" class="form-control" style="width:60px;"
|
||||
aria-label="Weight" value="\'||weight||\'">\' AS Weight',
|
||||
'\'<button type="button" class="btn btn-primary btn-sm">update</button>\' AS updt'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('decision_logic');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numberic_array)) {
|
||||
|
||||
$this->read_replica->where($numberic_array[$key], $val);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('id');
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function get_personalty_name_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
|
||||
$combo_array = [
|
||||
'status' => 'status',
|
||||
];
|
||||
|
||||
$numberic_array = [
|
||||
'from_offer' => 'offers_count >=',
|
||||
'to_offer' => 'offers_count <='
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'dkey' => 'dkey',
|
||||
'description' => 'description',
|
||||
'personality' => 'personality'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'id',
|
||||
'lorder',
|
||||
'dkey',
|
||||
'CASE WHEN status = 1 THEN \'Active\' ELSE \'Inactive\' END AS status',
|
||||
'description',
|
||||
|
||||
'\'<input maxlength="49" type="text" id="txt\'||dkey||\'"
|
||||
class="form-control" style="width:260px;" aria-label="Personality"
|
||||
value="\'||personality||\'">\' AS Personality',
|
||||
|
||||
'\'<input maxlength="5" type="text" id="ofc\'||dkey||\'"
|
||||
class="form-control" style=\"width:60px;" aria-label="Personality"
|
||||
value="\'||offers_count||\'">\' AS OfferCount',
|
||||
|
||||
'\'<button onclick="updatePersonaltyName(\'||id||\',\'\'\'||dkey||\'\'\');"
|
||||
type="button" class="btn btn-info btn-sm">Update</button>\' AS updt'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('decision_group');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numberic_array)) {
|
||||
|
||||
$this->read_replica->where($numberic_array[$key], $val);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('lorder');
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function get_member_report_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
|
||||
$combo_array = [
|
||||
];
|
||||
|
||||
$numberic_array = [
|
||||
'from_count' => 'temp.count >=',
|
||||
'to_count' => 'temp.count <='
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'decision_group' => 'temp.decision_group',
|
||||
'description' => 'temp.description',
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'count(m.id) AS count',
|
||||
'm.decision_group AS decision_group',
|
||||
'd.description AS description'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('members AS m');
|
||||
$this->read_replica->join('decision_group AS d', 'd.dkey = m.decision_group', 'LEFT');
|
||||
|
||||
$this->read_replica->where('m.id > 0');
|
||||
|
||||
$this->read_replica->group_by([
|
||||
'm.decision_group',
|
||||
'd.description'
|
||||
]);
|
||||
|
||||
$sub_query = $this->read_replica->get_compiled_select();
|
||||
|
||||
$this->read_replica->select([
|
||||
'temp.count',
|
||||
'temp.decision_group',
|
||||
'temp.description'
|
||||
]);
|
||||
$this->read_replica->from('('.$sub_query.') AS temp');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numberic_array)) {
|
||||
|
||||
$this->read_replica->where($numberic_array[$key], $val);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
}
|
||||
|
||||
$select_query = str_replace('""', '"', $this->read_replica->get_compiled_select());
|
||||
|
||||
return $this->read_replica->query($select_query)->result_array();
|
||||
}
|
||||
|
||||
public function get_refresh_report_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
|
||||
$combo_array = [
|
||||
];
|
||||
|
||||
$numberic_array = [
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
];
|
||||
|
||||
$sub_query =
|
||||
'SELECT \'Members with No group\' AS description,
|
||||
count(id) AS count
|
||||
FROM members
|
||||
WHERE id > 0 AND decision_group IS NULL
|
||||
UNION
|
||||
SELECT \'Members with decision not refreshed in 30 minutes\' AS description,
|
||||
count(id) AS count
|
||||
FROM members
|
||||
WHERE id > 0
|
||||
AND decision_group IS NOT NULL
|
||||
AND now() > decision_updated + \'30 minute\'';
|
||||
|
||||
$this->read_replica->select([
|
||||
'temp.count',
|
||||
'temp.description',
|
||||
]);
|
||||
|
||||
$this->read_replica->from('('.$sub_query.') AS temp');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numberic_array)) {
|
||||
|
||||
$this->read_replica->where($numberic_array[$key], $val);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
}
|
||||
|
||||
$select_query = str_replace('""', '"', $this->read_replica->get_compiled_select());
|
||||
|
||||
return $this->read_replica->query($select_query)->result_array();
|
||||
}
|
||||
|
||||
public function get_card_list_records($data) {
|
||||
$query_params =
|
||||
[
|
||||
'select' => [
|
||||
'c.name||\' <b>\'||c.button1_action||\'</b><br>\'||c.id||\' - \'|| c.title AS Card',
|
||||
'c.card_country AS card_country'
|
||||
],
|
||||
'order_by' => [
|
||||
'c.id DESC'
|
||||
]
|
||||
];
|
||||
|
||||
return $this
|
||||
->read_replica
|
||||
->query($this->get_card_list_query($query_params, $data))
|
||||
->result_array();
|
||||
}
|
||||
|
||||
public function get_card_group_records($data) {
|
||||
$query_params =
|
||||
[
|
||||
'select' => [
|
||||
'c.button1_action',
|
||||
'count(c.id) AS count'
|
||||
],
|
||||
'group_by' => [
|
||||
'c.button1_action'
|
||||
]
|
||||
];
|
||||
|
||||
return $this
|
||||
->read_replica
|
||||
->query($this->get_card_list_query($query_params, $data))
|
||||
->result_array();
|
||||
}
|
||||
|
||||
public function get_card_country_records($data) {
|
||||
$query_params =
|
||||
[
|
||||
'select' => [
|
||||
'c.card_country AS card_country',
|
||||
'count(c.id) AS count'
|
||||
],
|
||||
'group_by' => [
|
||||
'c.card_country'
|
||||
]
|
||||
];
|
||||
|
||||
return $this
|
||||
->read_replica
|
||||
->query($this->get_card_list_query($query_params, $data))
|
||||
->result_array();
|
||||
}
|
||||
|
||||
public function get_card_list_query($query_params, $data) {
|
||||
$this->read_replica->select(['id AS id'])
|
||||
->from('decision_group')
|
||||
->where('dkey', $data['dkey']);
|
||||
$sub_query = $this->read_replica->get_compiled_select();
|
||||
|
||||
$this->read_replica->select($query_params['select'])
|
||||
->from('decision_cards d')
|
||||
->join('main_cards c', 'c.id=d.card_id', 'LEFT')
|
||||
->where('d.status', '1') // Active
|
||||
->where("d.decision_id = ($sub_query)");
|
||||
|
||||
if (isset($query_params['group_by'])) {
|
||||
$this->read_replica->group_by($query_params['group_by'][0]);
|
||||
}
|
||||
|
||||
if (isset($query_params['order_by'])) {
|
||||
$this->read_replica->order_by($query_params['order_by'][0]);
|
||||
}
|
||||
|
||||
return $this->read_replica->get_compiled_select();
|
||||
}
|
||||
|
||||
public function get_personalty_card_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
$combo_array = [
|
||||
'status' => 'status'
|
||||
];
|
||||
|
||||
$numberic_array = [
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'dkey' => 'dkey',
|
||||
'description' => 'description',
|
||||
'personality' => 'personality'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'id',
|
||||
'lorder',
|
||||
'dkey',
|
||||
'CASE WHEN status = 1 THEN \'Active\' ELSE \'Inactive\' END AS status',
|
||||
'description',
|
||||
'personality'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('decision_group');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numberic_array)) {
|
||||
|
||||
$this->read_replica->where($numberic_array[$key], $val);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('lorder');
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
<?php
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class Emission_Average_model extends CI_Model
|
||||
{
|
||||
|
||||
const PERPAGE = 100;
|
||||
|
||||
// table associate
|
||||
protected $table = 'emission_avrg_commute';
|
||||
|
||||
// validate rules config
|
||||
public $rules = array(
|
||||
array(
|
||||
'field' => 'mkey',
|
||||
'label' => 'Mkey',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'gramskm_perc',
|
||||
'label' => 'Gramskm_perc',
|
||||
'rules' => 'required'
|
||||
),
|
||||
array(
|
||||
'field' => 'country',
|
||||
'label' => 'Country',
|
||||
'rules' => 'required|max_length[2]'
|
||||
)
|
||||
);
|
||||
|
||||
// read only database
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Emission Avrg Commute query string
|
||||
* @return string
|
||||
*/
|
||||
public function getEmissionAvrgQuery()
|
||||
{
|
||||
$this->read_replica->select('
|
||||
e.id,
|
||||
em.transport_mode,
|
||||
e.country,
|
||||
e.state,
|
||||
e.city,
|
||||
e.gramskm_perc,
|
||||
(c.avrg_commute*e.gramskm_perc*0.01) as A,
|
||||
(c.avrg_commute*e.gramskm_perc*0.01*em.grams_km/em.passengers) as B,
|
||||
');
|
||||
$this->read_replica->from(sprintf('%s e', $this->table));
|
||||
$this->read_replica->join('country c', 'e.country = c.code');
|
||||
$this->read_replica->join('emission_model em', 'em.mkey = e.mkey');
|
||||
// $this->read_replica->limit(self::PERPAGE, $paged);
|
||||
$query = $this->read_replica->get_compiled_select();
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getTotalCount()
|
||||
{
|
||||
// retreive emission avrg query string
|
||||
$query = $this->getEmissionAvrgQuery();
|
||||
$results = $this->read_replica->query($query);
|
||||
if (!$results) {
|
||||
return;
|
||||
}
|
||||
return $results->num_rows();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get emission avrg results and pagination links
|
||||
* @param int $page current page
|
||||
* @return array
|
||||
*/
|
||||
public function index($page = 1)
|
||||
{
|
||||
try {
|
||||
// pagination
|
||||
$results_count = $this->getTotalCount();
|
||||
$pagingUrl = base_url() . 'emission';
|
||||
$links = initPagination(self::PERPAGE, $results_count, $page, $pagingUrl);
|
||||
|
||||
// get results per page
|
||||
$query = $this->getEmissionAvrgQuery();
|
||||
|
||||
$results = sprintf('%s LIMIT %d OFFSET %d', $query, self::PERPAGE, self::PERPAGE * ($page - 1));
|
||||
$results = $this->read_replica->query($results);
|
||||
|
||||
return array(
|
||||
'results' => $results,
|
||||
'charts' => $this->getChart($results->result_array()),
|
||||
'pagination' => $links
|
||||
);
|
||||
} catch (Exception $e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public function getChart($emission_results)
|
||||
{
|
||||
$charts = [];
|
||||
foreach ($emission_results as $item) {
|
||||
$charts[$item['country']]['label'][] = $item['transport_mode'];
|
||||
$charts[$item['country']]['data'][] = $item['gramskm_perc'];
|
||||
}
|
||||
return $charts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get emission avrg details
|
||||
* @param int $id emission id
|
||||
* @return array emission details
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$result = $this->read_replica->get_where($this->table, array('id' => $id));
|
||||
// get only first matching
|
||||
$result = $result->row_array();
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Store emission avrg
|
||||
* @param arrat $data form request
|
||||
* @return bool
|
||||
*/
|
||||
public function store($data)
|
||||
{
|
||||
try {
|
||||
$this->db->insert($this->table, $data);
|
||||
return $this->db->insert_id();
|
||||
} catch (Exception $e) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update emission avrg by id
|
||||
* @param int $id emission id
|
||||
* @param array $data form request
|
||||
* @return bool
|
||||
*/
|
||||
public function update($id, $data)
|
||||
{
|
||||
try {
|
||||
$this->db->where('id', $id);
|
||||
$this->db->update($this->table, $data);
|
||||
return $this->db->affected_rows();
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete emission avrg record
|
||||
* @param int $id emission id
|
||||
* @return int affected rows index
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$this->db->where('id', $id);
|
||||
$this->db->delete($this->table);
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' );
|
||||
|
||||
class Emission_model extends CI_Model {
|
||||
|
||||
const PERPAGE = "20";
|
||||
|
||||
// table associate
|
||||
protected $table = 'emission_model';
|
||||
// read only database
|
||||
private $read_replica;
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* get Emission records
|
||||
* @param int $paged pagination number
|
||||
* @return array
|
||||
*/
|
||||
public function getData($paged = 0) {
|
||||
$this->read_replica->select('*');
|
||||
$this->read_replica->from($this->table);
|
||||
$this->read_replica->order_by('lorder', 'ASC');
|
||||
$this->read_replica->limit(self::PERPAGE, $paged);
|
||||
$query = $this->read_replica->get();
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Farm_record_model extends CI_Model
|
||||
{
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function get_farm_records(
|
||||
$filters
|
||||
) {
|
||||
$query =
|
||||
"SELECT
|
||||
a.*,
|
||||
b.total AS success,
|
||||
CASE
|
||||
WHEN a.total > 0 THEN round(100.0 * b.total / a.total, 2)
|
||||
ELSE 0.0 END AS success_rate
|
||||
FROM
|
||||
(
|
||||
SELECT
|
||||
date_trunc('day', aa.created) AS created,
|
||||
count(*) AS total
|
||||
FROM
|
||||
quotes aa
|
||||
LEFT JOIN address ab ON
|
||||
ab.id = aa.location_start_id
|
||||
WHERE
|
||||
aa.created>now() - interval '9 days'
|
||||
AND ab.country = '{$filters['country']}'
|
||||
GROUP BY
|
||||
date_trunc('day', aa.created)
|
||||
) AS a
|
||||
LEFT JOIN
|
||||
(
|
||||
SELECT
|
||||
date_trunc('day', ba.created) AS created,
|
||||
count(*) AS total
|
||||
FROM
|
||||
quotes ba
|
||||
LEFT JOIN address bb ON
|
||||
bb.id = ba.location_start_id
|
||||
WHERE
|
||||
ba.created > now() - interval '9 days'
|
||||
AND ba.cost > 0
|
||||
AND bb.country = '{$filters['country']}'
|
||||
GROUP BY
|
||||
date_trunc('day', created)
|
||||
) AS b
|
||||
ON (b.created = a.created)
|
||||
ORDER BY
|
||||
a.created DESC
|
||||
";
|
||||
|
||||
return $this->read_replica->query($query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Geofence_area_anchor_model extends CI_Model
|
||||
{
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
// Fetch records
|
||||
public function getGeoAreaAnchorRecord($filters = null, $limit = null, $offset = null)
|
||||
{
|
||||
$this->read_replica->select('gaa.id,
|
||||
gaa.geofence_area_id,
|
||||
gaa.address_id,
|
||||
gaa.title,
|
||||
ga.name,
|
||||
add.address,
|
||||
gac.id AS city_id');
|
||||
$this->read_replica->from('geofence_area_anchor gaa');
|
||||
$this->read_replica->join('geofence_area ga', 'ga.id = gaa.geofence_area_id');
|
||||
$this->read_replica->join('address add', 'add.id = gaa.address_id');
|
||||
$this->read_replica->join('geofence_area_city gac', 'gac.id = ga.city_id');
|
||||
$this->read_replica->join('country c', 'c.code = gac.country');
|
||||
|
||||
if (isset($filters['geo_area_id'])) {
|
||||
$this->read_replica->where('ga.id', $filters['geo_area_id']);
|
||||
}
|
||||
if (isset($filters['city_id'])) {
|
||||
$this->read_replica->where('gac.id', $filters['city_id']);
|
||||
}
|
||||
if (isset($filters['country_code'])) {
|
||||
$this->read_replica->where('c.code', $filters['country_code']);
|
||||
}
|
||||
|
||||
$this->read_replica->order_by('id');
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function getLocationByID($id) {
|
||||
$this->read_replica->select('*');
|
||||
$this->read_replica->from('geofence_area_anchor');
|
||||
$this->read_replica->where('id', $id);
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function insertGeoAreaAnchor($data) {
|
||||
$this->db->insert('geofence_area_anchor', $data);
|
||||
|
||||
return $this->db->affected_rows() > 0;
|
||||
}
|
||||
|
||||
public function updateGeoAreaAnchor($data) {
|
||||
$this->db->where('id', $data['id']);
|
||||
unset($data['id']);
|
||||
|
||||
$this->db->update('geofence_area_anchor', $data);
|
||||
|
||||
return $this->db->affected_rows() > 0;
|
||||
}
|
||||
|
||||
public function getRecordByGeoAreaAndAddress($data) {
|
||||
$this->read_replica->select('id');
|
||||
$this->read_replica->from('geofence_area_anchor');
|
||||
$this->read_replica->where('geofence_area_id', $data['geofence_area_id']);
|
||||
$this->read_replica->where('address_id', $data['address_id']);
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
|
||||
public function deleteGeoAreaAnchor($id) {
|
||||
$this->db->where('id', $id);
|
||||
$this->db->delete('geofence_area_anchor');
|
||||
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,276 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Geofence_area_city_model extends CI_Model
|
||||
{
|
||||
// city status
|
||||
const ACTIVE_STATUS = 1;
|
||||
const INACTIVE_STATUS = 0;
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function getAllWithPagination($page = 1, $perPage = 10, $filterData = [])
|
||||
{
|
||||
$offset = ($page - 1) * $perPage;
|
||||
if ($offset < 0) {
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
$whereQuery = 'WHERE 1=1';
|
||||
if (!empty($filterData)) {
|
||||
if (!empty($filterData['country_code'])) {
|
||||
$whereQuery .= ' AND geo.country = ' . $this->read_replica->escape(strtoupper($filterData['country_code'])) . ' ';
|
||||
}
|
||||
if (!empty($filterData['search_text'])) {
|
||||
$search_text = $this->read_replica->escape_like_str($filterData['search_text']);
|
||||
$whereQuery .= ' AND geo.city ILIKE \'%' . $search_text . '%\'';
|
||||
}
|
||||
if (isset($filterData['status']) && $filterData['status'] != "all") {
|
||||
$status = $this->read_replica->escape($filterData['status']);
|
||||
$whereQuery .= ' AND geo.status =' . $status;
|
||||
}
|
||||
}
|
||||
|
||||
$totalQueryString =
|
||||
'SELECT
|
||||
geo.id, geo.city as city_name, geo.country as country_code, geo.latitude, geo.longitude, geo.radius,
|
||||
country.country as country_name, geo.status
|
||||
FROM
|
||||
geofence_area_city as geo
|
||||
JOIN country ON country.code = geo.country
|
||||
' . $whereQuery;
|
||||
//echo $totalQueryString;exit;
|
||||
$queryString =
|
||||
'SELECT
|
||||
geo.id, geo.city as city_name, geo.country as country_code, geo.latitude, geo.longitude, geo.radius,
|
||||
country.country as country_name, geo.status
|
||||
FROM
|
||||
geofence_area_city as geo
|
||||
JOIN country ON country.code = geo.country
|
||||
' . $whereQuery . '
|
||||
ORDER BY id DESC
|
||||
LIMIT ' . pg_escape_string($perPage) . ' OFFSET ' . pg_escape_string($offset);
|
||||
|
||||
$totalQuery = $this->read_replica->query($totalQueryString);
|
||||
$query = $this->read_replica->query($queryString);
|
||||
|
||||
return [
|
||||
'total' => count($totalQuery->result()),
|
||||
'data' => $query->result(),
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
||||
public function getItem($id)
|
||||
{
|
||||
$queryString =
|
||||
'SELECT
|
||||
geo.id, geo.city as city_name, geo.country as country_code, geo.latitude, geo.longitude, geo.radius,
|
||||
country.country as country_name, geo.status
|
||||
FROM
|
||||
geofence_area_city as geo
|
||||
JOIN country ON country.code = geo.country
|
||||
WHERE
|
||||
geo.id = ?
|
||||
LIMIT 1
|
||||
';
|
||||
|
||||
$query = $this->read_replica->query($queryString, $id);
|
||||
return $query->row_array();
|
||||
}
|
||||
|
||||
public function create($inputData)
|
||||
{
|
||||
$this->db->insert('geofence_area_city', $inputData);
|
||||
$insertId = $this->db->insert_id();
|
||||
|
||||
// update location field
|
||||
$this->db->query("UPDATE geofence_area_city SET location = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326) WHERE id = {$insertId} ");
|
||||
}
|
||||
|
||||
public function update($id, $inputData)
|
||||
{
|
||||
$this->db->where('id', $id);
|
||||
$this->db->update('geofence_area_city', $inputData);
|
||||
|
||||
// update location field
|
||||
$this->db->query("UPDATE geofence_area_city SET location = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326) WHERE id = {$id} ");
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$this->db->delete('geofence_area_city', ['id' => $id]);
|
||||
}
|
||||
|
||||
public function getCities($condtions = '')
|
||||
{
|
||||
if ($condtions != '') {
|
||||
$q = "SELECT id, city FROM geofence_area_city WHERE ".$condtions." ORDER BY id ASC";
|
||||
$r = pg_query($q);
|
||||
$query = $this->read_replica->query($q);
|
||||
return $query->result();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function getDuplicatedCities()
|
||||
{
|
||||
$q = "SELECT city, country, count(*)
|
||||
FROM geofence_area_city
|
||||
GROUP BY city,
|
||||
country
|
||||
HAVING count(*)>1
|
||||
ORDER BY count(*) DESC";
|
||||
$query = $this->read_replica->query($q);
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function updateAddresses($condition,$data)
|
||||
{
|
||||
$this->db->where($condition);
|
||||
$this->db->update('address', $data);
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
|
||||
public function deleteUnusedCities()
|
||||
{
|
||||
global $conn;
|
||||
$q = "DELETE
|
||||
FROM geofence_area_city
|
||||
WHERE id NOT IN (SELECT DISTINCT city_id FROM address);";
|
||||
$this->db->query($q);
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
|
||||
public function getCityIDByName($city_name) {
|
||||
$q = $this->read_replica->select('id')
|
||||
->from('geofence_area_city')
|
||||
->where('lower(city)', strtolower($city_name))
|
||||
->get();
|
||||
|
||||
return $q->result_array() ? $q->result_array()['id'] : NULL;
|
||||
}
|
||||
|
||||
public function getCityByCoordindates($params) {
|
||||
$res = SQEAPI::get('geofencearea/api/geofencearea/cityApi', $params);
|
||||
|
||||
if (isset($res['error'])) {
|
||||
return ['success' => false, 'error' => $res['error']];
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($res['data'] as $addr) {
|
||||
$data[] = (array)($addr);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getCityWithFilter($params)
|
||||
{
|
||||
$page = $params['page'] ?? 1;
|
||||
$per_page = $params['per_page'] ?? 20;
|
||||
|
||||
$offset = ($page - 1) * $per_page;
|
||||
if ($offset < 0) {
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
$whereQuery = ' WHERE 1 = 1 ';
|
||||
if (!empty($params)) {
|
||||
if (!empty($params['city_name'])) {
|
||||
$search_text = $this->read_replica->escape_like_str($params['city_name']);
|
||||
$whereQuery .= ' AND city ILIKE \'%' . $search_text . '%\'';
|
||||
}
|
||||
}
|
||||
|
||||
$totalQueryString = '
|
||||
SELECT id
|
||||
FROM geofence_area_city
|
||||
' . $whereQuery;
|
||||
|
||||
$queryString = '
|
||||
SELECT *
|
||||
FROM geofence_area_city
|
||||
' . $whereQuery . '
|
||||
ORDER BY city ASC
|
||||
LIMIT ' . pg_escape_string($per_page) . ' OFFSET ' . pg_escape_string($offset);
|
||||
|
||||
$totalQuery = $this->read_replica->query($totalQueryString);
|
||||
$query = $this->read_replica->query($queryString);
|
||||
|
||||
return [
|
||||
'total' => count($totalQuery->result()),
|
||||
'data' => $query->result(),
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
||||
public function getRecordByCityAndCountry($data) {
|
||||
$this->read_replica
|
||||
->select('id')
|
||||
->from('geofence_area_city')
|
||||
->where('city', $data['city'])
|
||||
->where('country', $data['country']);
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function getCityQueryWithFilter($filters = [], $count_record = true)
|
||||
{
|
||||
$numeric_array = [
|
||||
'status' => 'status',
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'search_text' => 'city',
|
||||
'country_code' => 'country'
|
||||
];
|
||||
|
||||
$count_record ?
|
||||
$this->read_replica->select(['count(*) AS all_count']) :
|
||||
$this->read_replica->select([
|
||||
'id',
|
||||
'city',
|
||||
'country',
|
||||
'latitude',
|
||||
'longitude',
|
||||
'location',
|
||||
'radius',
|
||||
'status',
|
||||
]);
|
||||
|
||||
$this->read_replica->from('geofence_area_city');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
if (array_key_exists($key, $numeric_array)) {
|
||||
$this->read_replica->where($numeric_array[$key], $val);
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
}
|
||||
}
|
||||
|
||||
if ($count_record === false) {
|
||||
$this->read_replica->order_by('id ASC');
|
||||
}
|
||||
|
||||
return $this->read_replica->get_compiled_select();
|
||||
}
|
||||
|
||||
public function getCountryByCode($data){
|
||||
$this->read_replica
|
||||
->select('code')
|
||||
->from('country')
|
||||
->where('code', $data['country']);
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Geofence_area_city_settings_model extends CI_Model
|
||||
{
|
||||
// city status
|
||||
const ACTIVE_STATUS = 1;
|
||||
const INACTIVE_STATUS = 0;
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function getAllWithPagination($filterData, $pagination = null)
|
||||
{
|
||||
$paginationQuery = '';
|
||||
$page = $pagination['page'] ?? 1;
|
||||
if ($pagination) {
|
||||
$perPage = $pagination['itemPerPage'] ?? 10;
|
||||
$offset = ($page - 1) * $perPage;
|
||||
if ($offset < 0) {
|
||||
$offset = 0;
|
||||
}
|
||||
$paginationQuery = 'LIMIT ' . pg_escape_string($perPage) . ' OFFSET ' . pg_escape_string($offset);
|
||||
}
|
||||
|
||||
$q = 'SELECT settings.*, geofence_city.city, geofence_city.country, geofence_city.latitude, geofence_city.longitude FROM geofence_area_city_settings AS settings LEFT JOIN geofence_area_city AS geofence_city ON geofence_city.id = settings.geofence_area_city';
|
||||
$totalQueryString = 'SELECT COUNT(*) FROM geofence_area_city_settings as settings LEFT JOIN geofence_area_city as geofence_city ON settings.geofence_area_city = geofence_city.id';
|
||||
|
||||
$lat = $filterData['lat'] ?? NULL;
|
||||
$lng = $filterData['lng'] ?? NULL;
|
||||
$radius = $filterData['radius'] ?? NULL;
|
||||
|
||||
// Update query with search by radius
|
||||
if (!empty($lat) && !empty($lng) && !empty($radius)) {
|
||||
$earth_radius = 6371;
|
||||
$km_per_degree_lat = 111.2;
|
||||
$pi = 3.14/180;
|
||||
$latitude = $lat;
|
||||
$longitude = $lng;
|
||||
$distance_in_km = $radius;
|
||||
|
||||
$q = "FROM (
|
||||
SELECT (
|
||||
$earth_radius * acos(
|
||||
cos( radians( {$latitude}) )
|
||||
* cos( radians( latitude ) )
|
||||
* cos( radians( longitude ) - radians( {$longitude} ) )
|
||||
+ sin( radians( {$latitude}) )
|
||||
* sin( radians( latitude ) ))
|
||||
) AS distance,
|
||||
id,
|
||||
city,
|
||||
country,
|
||||
latitude,
|
||||
longitude
|
||||
FROM geofence_area_city
|
||||
WHERE latitude BETWEEN "
|
||||
. ($latitude - ($distance_in_km / $km_per_degree_lat))
|
||||
. " AND " . ($latitude + ($distance_in_km / $km_per_degree_lat));
|
||||
|
||||
$delta = round($distance_in_km / ($km_per_degree_lat * COS(deg2rad($longitude))), 10);
|
||||
|
||||
// Bounding box for speed - latitude within range (longtitude to km not linear)
|
||||
if (cos($longitude * $pi) > 0) {
|
||||
$from = $longitude - $delta;
|
||||
$to = $longitude + $delta;
|
||||
|
||||
$q .=
|
||||
" AND longitude" .
|
||||
" BETWEEN " . $from .
|
||||
" AND " . $to;
|
||||
|
||||
} else {
|
||||
$from = $longitude + $delta;
|
||||
$to = $longitude - $delta;
|
||||
|
||||
$q .=
|
||||
" AND longitude" .
|
||||
" BETWEEN " . $from .
|
||||
" AND " . $to;
|
||||
}
|
||||
|
||||
// distance limit for circle
|
||||
$q .= " ) geofence_city JOIN geofence_area_city_settings AS settings ON geofence_city.id = settings.geofence_area_city WHERE distance < " . $distance_in_km;
|
||||
|
||||
$totalQueryString = 'SELECT COUNT(settings.id) ' .$q; // Count query
|
||||
$q = 'SELECT settings.*, geofence_city.city, geofence_city.country, geofence_city.latitude, geofence_city.longitude ' .$q;
|
||||
}
|
||||
// End update query with search by radius
|
||||
|
||||
$whereQuery = [];
|
||||
if (!empty($filterData)) {
|
||||
if (!empty($filterData['country_code'])) {
|
||||
$whereQuery[] = 'geofence_city.country = ' . $this->read_replica->escape(strtoupper($filterData['country_code'])) . ' ';
|
||||
}
|
||||
if (!empty($filterData['search_text'])) {
|
||||
$search_text = $this->read_replica->escape_like_str($filterData['search_text']);
|
||||
$whereQuery[] = 'geofence_city.city ILIKE \'%' . $search_text . '%\'';
|
||||
}
|
||||
if (isset($filterData['status']) && $filterData['status'] != "all") {
|
||||
$status = $this->read_replica->escape($filterData['status']);
|
||||
$whereQuery[] = 'settings.status =' . $status;
|
||||
}
|
||||
}
|
||||
|
||||
if (count($whereQuery) > 0) {
|
||||
$where = implode(" AND ", $whereQuery);
|
||||
if (!empty($lat) && !empty($lng) && !empty($radius)) {
|
||||
$q .= ' AND ' . $where;
|
||||
$totalQueryString .= ' AND ' . $where;
|
||||
} else {
|
||||
$q .= ' WHERE ' . $where;
|
||||
$totalQueryString .= ' WHERE ' . $where;
|
||||
}
|
||||
}
|
||||
|
||||
$q .= ' ORDER BY settings.id ASC ' . $paginationQuery;
|
||||
$totalQuery = $this->read_replica->query($totalQueryString);
|
||||
$results = $this->read_replica->query($q);
|
||||
|
||||
return [
|
||||
'total' => intval($totalQuery->result()[0]->count),
|
||||
'data_export_csv' => $this->db->query($q),
|
||||
'data' => $results->result(),
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
||||
public function getItem($id)
|
||||
{
|
||||
$queryString =
|
||||
'SELECT
|
||||
settings.*, geo.id as city, city as city_name
|
||||
FROM
|
||||
geofence_area_city_settings as settings LEFT JOIN geofence_area_city as geo ON geo.id = settings.geofence_area_city
|
||||
WHERE
|
||||
settings.id = ?
|
||||
';
|
||||
|
||||
$query = $this->read_replica->query($queryString, $id);
|
||||
return $query->row_array();
|
||||
}
|
||||
|
||||
public function create($inputData)
|
||||
{
|
||||
$this->db->insert('geofence_area_city_settings', $inputData);
|
||||
$insertId = $this->db->insert_id();
|
||||
}
|
||||
|
||||
public function update($id, $inputData)
|
||||
{
|
||||
$this->db->where('id', $id);
|
||||
$this->db->update('geofence_area_city_settings', $inputData);
|
||||
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$this->db->delete('geofence_area_city_settings', ['id' => $id]);
|
||||
}
|
||||
|
||||
public function getCitySettingByCityID($cityID)
|
||||
{
|
||||
$this->read_replica
|
||||
->select('id, status, image_url, is_fectched_data')
|
||||
->from('geofence_area_city_settings')
|
||||
->where('geofence_area_city', $cityID);
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Geofence_area_country_model extends CI_Model
|
||||
{
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function getAllWithPagination($page = 1, $perPage = 10)
|
||||
{
|
||||
$offset = ($page - 1) * $perPage;
|
||||
if ($offset < 0) {
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
$totalQueryString =
|
||||
'SELECT
|
||||
geo.id, geo.country as country_code, geo.latitude, geo.longitude, geo.radius,
|
||||
country.country as country_name
|
||||
FROM
|
||||
geofence_area_country as geo
|
||||
JOIN country ON country.code = geo.country
|
||||
';
|
||||
|
||||
$queryString =
|
||||
'SELECT
|
||||
geo.id, geo.country as country_code, geo.latitude, geo.longitude, geo.radius,
|
||||
country.country as country_name
|
||||
FROM
|
||||
geofence_area_country as geo
|
||||
JOIN country ON country.code = geo.country
|
||||
ORDER BY id DESC
|
||||
LIMIT ' . pg_escape_string($perPage) . ' OFFSET ' . pg_escape_string($offset);
|
||||
|
||||
$totalQuery = $this->read_replica->query($totalQueryString);
|
||||
$query = $this->read_replica->query($queryString);
|
||||
|
||||
return [
|
||||
'total' => count($totalQuery->result()),
|
||||
'data' => $query->result(),
|
||||
'page' => $page
|
||||
];
|
||||
}
|
||||
|
||||
public function getItem($id)
|
||||
{
|
||||
$queryString =
|
||||
'SELECT
|
||||
geo.id, geo.country as country_code, geo.latitude, geo.longitude, geo.radius,
|
||||
country.country as country_name
|
||||
FROM
|
||||
geofence_area_country as geo
|
||||
JOIN country ON country.code = geo.country
|
||||
WHERE
|
||||
geo.id = ?
|
||||
LIMIT 1
|
||||
';
|
||||
|
||||
$query = $this->read_replica->query($queryString, $id);
|
||||
return $query->row_array();
|
||||
}
|
||||
|
||||
public function create($inputData)
|
||||
{
|
||||
$this->db->insert('geofence_area_country', $inputData);
|
||||
|
||||
$insertId= $this->db->insert_id();
|
||||
|
||||
// update location field
|
||||
$this->db->query("UPDATE geofence_area_country SET location = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326) WHERE id = {$insertId} ");
|
||||
}
|
||||
|
||||
public function update($id, $inputData)
|
||||
{
|
||||
$this->db->where('id', $id);
|
||||
$this->db->update('geofence_area_country', $inputData);
|
||||
|
||||
// update location field
|
||||
$this->db->query("UPDATE geofence_area_country SET location = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326) WHERE id = {$id} ");
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$this->db->delete('geofence_area_country', ['id' => $id]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,328 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Geofence_area_model extends CI_Model
|
||||
{
|
||||
const GEOFENCING_AREA_TYPES = [
|
||||
'postal',
|
||||
'radius',
|
||||
'polygon'
|
||||
];
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function getAllWithPagination($page = 1, $perPage = 10, $filterData = [])
|
||||
{
|
||||
$offset = ($page - 1) * $perPage;
|
||||
if ($offset < 0) {
|
||||
$offset = 0;
|
||||
}
|
||||
|
||||
$whereQuery = '';
|
||||
if (!empty($filterData)) {
|
||||
if (!empty($filterData['city_id'])) {
|
||||
$whereQuery .= ' WHERE geo_city.id = ' . $this->read_replica->escape($filterData['city_id']) . ' ';
|
||||
}
|
||||
}
|
||||
|
||||
$totalQueryString =
|
||||
'SELECT
|
||||
geo.id, geo.name, geo.area, geo_city.city as city_name, geo_city.id as city_id, geo.type,
|
||||
geo.country as country_code, geo.latitude, geo.longitude, geo.boundaries,
|
||||
country.country as country_name
|
||||
FROM
|
||||
geofence_area as geo
|
||||
JOIN country ON country.code = geo.country
|
||||
JOIN geofence_area_city as geo_city ON geo_city.id = geo.city_id
|
||||
' . $whereQuery;
|
||||
|
||||
$queryString =
|
||||
'SELECT
|
||||
geo.id, geo.name, geo.area, geo_city.city as city_name, geo_city.id as city_id, geo.type,
|
||||
geo.country as country_code, geo.latitude, geo.longitude, geo.boundaries,
|
||||
country.country as country_name
|
||||
FROM
|
||||
geofence_area as geo
|
||||
JOIN country ON country.code = geo.country
|
||||
JOIN geofence_area_city as geo_city ON geo_city.id = geo.city_id
|
||||
' . $whereQuery . '
|
||||
ORDER BY id DESC
|
||||
LIMIT ' . pg_escape_string($perPage) . ' OFFSET ' . pg_escape_string($offset);
|
||||
|
||||
$totalQuery = $this->read_replica->query($totalQueryString);
|
||||
$query = $this->read_replica->query($queryString);
|
||||
|
||||
return [
|
||||
'total' => count($totalQuery->result()),
|
||||
'data' => $query->result(),
|
||||
'page' => $page
|
||||
];
|
||||
}
|
||||
|
||||
public function getAllAreas()
|
||||
{
|
||||
$query = "SELECT
|
||||
geofence_area.id, geofence_area.name, geofence_area_city.city, geofence_area.latitude, geofence_area.longitude,
|
||||
geofence_area.location, geofence_area.type, geofence_area.boundaries
|
||||
FROM
|
||||
geofence_area
|
||||
JOIN geofence_area_city ON geofence_area_city.id = geofence_area.city_id
|
||||
";
|
||||
|
||||
$query = $this->read_replica->query($query);
|
||||
|
||||
return $query->result();
|
||||
}
|
||||
|
||||
public function getItem($id)
|
||||
{
|
||||
$queryString =
|
||||
'SELECT
|
||||
geo.id, geo.name, geo.area, geo_city.city as city_name, geo_city.id as city_id, geo.type,
|
||||
geo.country as country_code, geo.latitude, geo.longitude, geo.boundaries,
|
||||
country.country as country_name
|
||||
FROM
|
||||
geofence_area as geo
|
||||
JOIN country ON country.code = geo.country
|
||||
JOIN geofence_area_city as geo_city ON geo_city.id = geo.city_id
|
||||
WHERE
|
||||
geo.id = ?
|
||||
LIMIT 1
|
||||
';
|
||||
|
||||
$query = $this->read_replica->query($queryString, $id);
|
||||
return $query->row_array();
|
||||
}
|
||||
|
||||
public function create($inputData)
|
||||
{
|
||||
$test = $this->db->insert('geofence_area', $inputData);
|
||||
$insertId= $this->db->insert_id();
|
||||
|
||||
// update location field
|
||||
$this->db->query("UPDATE geofence_area SET location = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326) WHERE id = {$insertId} ");
|
||||
}
|
||||
|
||||
public function update($id, $inputData)
|
||||
{
|
||||
$this->db->where('id', $id);
|
||||
$this->db->update('geofence_area', $inputData);
|
||||
|
||||
// update location field
|
||||
$this->db->query("UPDATE geofence_area SET location = ST_SetSRID(ST_MakePoint(longitude, latitude), 4326) WHERE id = {$id} ");
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$this->db->delete('geofence_area', ['id' => $id]);
|
||||
}
|
||||
|
||||
public function priceComparison($startAreaId, $endAreaId)
|
||||
{
|
||||
// validate id
|
||||
if (!is_numeric($startAreaId) || !is_numeric($endAreaId)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 1) Define geofenced areas, get list of areas
|
||||
$startArea = $this->getArea($startAreaId);
|
||||
$endArea = $this->getArea($endAreaId);
|
||||
|
||||
if (!$startArea || !$endArea) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Can not find area.'
|
||||
];
|
||||
}
|
||||
|
||||
// 2. Select trips where "from" falls into origin area and "to" falls into destination area
|
||||
$whereQuery = '';
|
||||
$startBoundaries = json_decode($startArea['boundaries'], true);
|
||||
$endBoundaries = json_decode($endArea['boundaries'], true);
|
||||
if ($startArea['type'] === 'radius') {
|
||||
if (isset($startBoundaries['radius'])) {
|
||||
$radius = $startBoundaries['radius'];
|
||||
$condition = " ST_DWithin('" . $startArea['location'] . "', startAddr.geometry, " . $radius . ") ";
|
||||
$whereQuery = $this->checkCondition($condition, $whereQuery);
|
||||
} else {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Missing radius in boundaries field.'
|
||||
];
|
||||
}
|
||||
} else if ($startArea['type'] === 'postal') {
|
||||
if (is_array($startBoundaries) && array_key_exists("postal_code",$startBoundaries) && is_array($startBoundaries["postal_code"]) && count($startBoundaries["postal_code"]) > 0) {
|
||||
$condition = "";
|
||||
foreach ($startBoundaries['postal_code'] as $code) {
|
||||
if ($condition != "") {
|
||||
$condition .= " OR ";
|
||||
}
|
||||
$condition .= " LEFT(startAddr.postal, " . strlen($code) . ") = '${code}' ";
|
||||
}
|
||||
|
||||
$condition = "(${condition})";
|
||||
$whereQuery = $this->checkCondition($condition, $whereQuery);
|
||||
} else {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Missing postal_code in boundaries field.'
|
||||
];
|
||||
}
|
||||
} else if ($startArea['type'] === 'polygon') {
|
||||
if (isset($startBoundaries['polygon'])) {
|
||||
$polygon = $startBoundaries['polygon'];
|
||||
|
||||
$polygonCoords = [];
|
||||
foreach ($polygon as $coord) {
|
||||
$polygonCoords[] = "$coord[0] $coord[1]";
|
||||
}
|
||||
$polygonCoordsString = implode(",", $polygonCoords);
|
||||
|
||||
$condition = " ST_Contains(ST_GeomFromText('POLYGON((${polygonCoordsString}))', 4326), startAddr.geometry::geometry) ";
|
||||
$whereQuery = $this->checkCondition($condition, $whereQuery);
|
||||
} else {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Missing polygon in boundaries field.'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if ($endArea['type'] === 'radius') {
|
||||
if (isset($endBoundaries['radius'])) {
|
||||
$radius = $endBoundaries['radius'];
|
||||
$condition = " ST_DWithin('" . $endArea['location'] . "', endAddr.geometry, " . $radius . ") ";
|
||||
$whereQuery = $this->checkCondition($condition, $whereQuery);
|
||||
} else {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Missing radius in boundaries field.'
|
||||
];
|
||||
}
|
||||
} else if ($endArea['type'] === 'postal') {
|
||||
if (is_array($endBoundaries) && array_key_exists("postal_code",$endBoundaries) && is_array($endBoundaries["postal_code"]) && count($endBoundaries["postal_code"]) > 0) {
|
||||
$condition = "";
|
||||
foreach ($endBoundaries['postal_code'] as $code) {
|
||||
if ($condition != "") {
|
||||
$condition .= " OR ";
|
||||
}
|
||||
$condition .= " LEFT(endAddr.postal, " . strlen($code) . ") = '${code}' ";
|
||||
}
|
||||
|
||||
$condition = "(${condition})";
|
||||
$whereQuery = $this->checkCondition($condition, $whereQuery);
|
||||
} else {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Missing postal_code in boundaries field.'
|
||||
];
|
||||
}
|
||||
} else if ($endArea['type'] === 'polygon') {
|
||||
if (isset($endBoundaries['polygon'])) {
|
||||
$polygon = $endBoundaries['polygon'];
|
||||
|
||||
$polygonCoords = [];
|
||||
foreach ($polygon as $coord) {
|
||||
$polygonCoords[] = "$coord[0] $coord[1]";
|
||||
}
|
||||
$polygonCoordsString = implode(",", $polygonCoords);
|
||||
|
||||
$condition = " ST_Contains(ST_GeomFromText('POLYGON((${polygonCoordsString}))', 4326), endAddr.geometry::geometry) ";
|
||||
$whereQuery = $this->checkCondition($condition, $whereQuery);
|
||||
} else {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => 'Missing polygon in boundaries field.'
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Filter pricing by transport_provider_id and calculate average within last year
|
||||
|
||||
// only get trips within last year
|
||||
$numberOfDays = 365;
|
||||
$condition = " parsedemail_item.travel_date BETWEEN NOW() - INTERVAL '" . $numberOfDays . " days' AND NOW() ";
|
||||
$whereQuery = $this->checkCondition($condition, $whereQuery);
|
||||
|
||||
$tripQuery =
|
||||
"SELECT
|
||||
ROUND(AVG(parsedemail_item.cost), 2) as avg_price, parsedemail_item.transport_provider_id,
|
||||
transport_providers.name as transport_provider_name
|
||||
FROM
|
||||
parsedemail_item
|
||||
JOIN transport_providers ON transport_providers.id = parsedemail_item.transport_provider_id
|
||||
JOIN address AS startAddr ON (startAddr.id = parsedemail_item.location_start_id AND transport_provider_id IS NOT NULL
|
||||
AND LOWER(startAddr.country) = '" . strtolower($startArea['country_code']) . "')
|
||||
JOIN address AS endAddr ON (endAddr.id = parsedemail_item.location_end_id
|
||||
AND LOWER(endAddr.country) = '" . strtolower($endArea['country_code']) . "')
|
||||
" . $whereQuery . "
|
||||
GROUP BY parsedemail_item.transport_provider_id, transport_providers.name
|
||||
";
|
||||
|
||||
$query = $this->read_replica->query($tripQuery);
|
||||
|
||||
$result = [
|
||||
'success' => true,
|
||||
'from_area' => $startArea,
|
||||
'to_area' => $endArea,
|
||||
'price_comparison' => $query->result_array() ?: []
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private function checkCondition($condition, $query)
|
||||
{
|
||||
if (strpos($query, 'WHERE') === false) {
|
||||
$query .= " WHERE $condition";
|
||||
} else {
|
||||
$query .= " AND $condition";
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getArea($id)
|
||||
{
|
||||
$query = "SELECT
|
||||
geofence_area.id, geofence_area.name, geofence_area.country as country_code, geofence_area.latitude, geofence_area.longitude,
|
||||
geofence_area.location, geofence_area.type, geofence_area.boundaries
|
||||
FROM
|
||||
geofence_area
|
||||
WHERE
|
||||
geofence_area.id = $id
|
||||
LIMIT 1
|
||||
";
|
||||
|
||||
$query = $this->read_replica->query($query);
|
||||
$data = $query->result_array();
|
||||
|
||||
return !empty($data) ? $data[0] : null;
|
||||
}
|
||||
|
||||
public function getLocationByID($id) {
|
||||
$this->read_replica->select('*');
|
||||
$this->read_replica->from('geofence_area');
|
||||
$this->read_replica->where('id', $id);
|
||||
|
||||
$query = $this->read_replica->get();
|
||||
|
||||
return $query->result_array();
|
||||
}
|
||||
|
||||
public function getLocationByCityID($city_id) {
|
||||
$this->read_replica->select('ga.id AS id, ga.name AS geo_area_name');
|
||||
$this->read_replica->from('geofence_area ga');
|
||||
$this->read_replica->join('geofence_area_city gac', 'gac.id = ga.city_id');
|
||||
$this->read_replica->where('gac.id', $city_id);
|
||||
$this->read_replica->order_by('geo_area_name');
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Global_setting_model extends CI_Model {
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
// Fetch records
|
||||
public function getData($rowno, $rowperpage, $filters = []) {
|
||||
|
||||
$this->read_replica->select('*');
|
||||
$this->read_replica->from('global_settings');
|
||||
$this->read_replica->order_by('key');
|
||||
foreach($filters as $key => $value) {
|
||||
if ($key === 'key_filter') {
|
||||
|
||||
$this->read_replica->like('lower(key)', strtolower($value));
|
||||
|
||||
} else if ($key === 'description_filter') {
|
||||
|
||||
$this->read_replica->like('lower(description)', strtolower($value));
|
||||
|
||||
} else if ($key === 'card_status_filter') {
|
||||
|
||||
$this->read_replica->where('status', $value);
|
||||
|
||||
}
|
||||
}
|
||||
$this->read_replica->limit($rowperpage, $rowno);
|
||||
$query = $this->read_replica->get();
|
||||
|
||||
return $query->result_array();
|
||||
}
|
||||
|
||||
// Select total records
|
||||
public function getrecordCount($filters = []) {
|
||||
$this->read_replica->select('count(*) as allcount');
|
||||
$this->read_replica->from('global_settings');
|
||||
foreach($filters as $key => $value) {
|
||||
if ($key === 'key_filter') {
|
||||
|
||||
$this->read_replica->like('lower(key)', strtolower($value));
|
||||
|
||||
} else if ($key === 'description_filter') {
|
||||
|
||||
$this->read_replica->like('lower(description)', strtolower($value));
|
||||
|
||||
} else if ($key === 'card_status_filter') {
|
||||
|
||||
$this->read_replica->where('status', $value);
|
||||
|
||||
}
|
||||
}
|
||||
$query = $this->read_replica->get();
|
||||
$result = $query->result_array();
|
||||
|
||||
return $result[0]['allcount'];
|
||||
}
|
||||
|
||||
public function insertGlobalSetting($data) {
|
||||
|
||||
try {
|
||||
|
||||
unset($data['old_key']);
|
||||
$this->db->insert('global_settings', $data);
|
||||
return $this->db->insert_id();
|
||||
|
||||
} catch (Exception $ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function updateGlobalSetting($id, $data) {
|
||||
|
||||
try {
|
||||
|
||||
unset($data['old_key']);
|
||||
$this->db->where('id',$id);
|
||||
$this->db->update('global_settings', $data);
|
||||
return $this->db->affected_rows();
|
||||
|
||||
} catch (Exception $ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function deleteGlobalSettingById($id) {
|
||||
|
||||
try {
|
||||
|
||||
$this->db->delete('global_settings', $id);
|
||||
return $this->db->affected_rows();
|
||||
|
||||
} catch (Exception $ex) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function getGlobalSettingsByID($id) {
|
||||
try {
|
||||
|
||||
return $this->read_replica->get_where('global_settings', $id)->num_rows();
|
||||
|
||||
} catch (Exception $ex) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,432 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Main_cards_model extends CI_Model {
|
||||
|
||||
public function __constructor() {
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function getCardsQuery($params = []) {
|
||||
$whereQuery = '';
|
||||
|
||||
if (!empty($params['card_category'])) {
|
||||
$whereQuery .= " AND main_cards.button1_action='" . pg_escape_string($params['card_category']) . "' ";
|
||||
}
|
||||
|
||||
if (!empty($params['filter_name']) && !empty($params['filter_value'])) {
|
||||
$filter_name = $params['filter_name'];
|
||||
$filter_value = trim($params['filter_value']);
|
||||
|
||||
if ($filter_name == 'name') {
|
||||
$whereQuery .= " AND main_cards.name ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'title') {
|
||||
$whereQuery .= " AND main_cards.title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'short_title') {
|
||||
$whereQuery .= " AND main_cards.short_title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'description') {
|
||||
$whereQuery .= " AND main_cards.description ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'button1_action') {
|
||||
$whereQuery .= " AND main_cards.button1_action ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
}elseif( empty($params['filter_name']) && !empty($params['filter_value']) ){
|
||||
// find all
|
||||
$filter_value = trim($params['filter_value']);
|
||||
$fields_like = [
|
||||
'name' => 'main_cards.name',
|
||||
'title' => 'main_cards.title',
|
||||
'short_title' => 'main_cards.short_title',
|
||||
'description' => 'main_cards.description',
|
||||
'button1_action'=> 'main_cards.button1_action'
|
||||
];
|
||||
$whereQuery .= " AND concat(".implode(',',array_values($fields_like)).") ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT '<button id=\"acc'||main_cards.id||'\" type=\"button\" class=\"btn btn-primary btn-xs\" block onclick=\"viewCard('||main_cards.id||');\">View-'||main_cards.id||'</button>' ||'<br><hr>'|| "
|
||||
. "'<button id=\"edit'||main_cards.id||'\" type=\"button\" class=\"btn btn-warning btn-xs\" block onclick=\"editCard('||main_cards.id||');\">Edit-'||main_cards.id||'</button>' AS Edit,"
|
||||
. " '<b>Name: </b>'|| main_cards.name||'<br><b>Title: </b>'||title||'<br><b>Short Title: </b>'||short_title||'<br><b>Desc: </b>'||description
|
||||
||'<br><b>Button: </b>'||button1||'<br><b>Button Text: </b>'
|
||||
||button1_text||'<br><b>Action:</>'||button1_action AS description,
|
||||
(CASE WHEN main_cards.template = 7 THEN
|
||||
'<div onclick=\"viewCard('||main_cards.id||');\" style=\"width:120px; height:120px; background-color:#'||main_cards.background_color||'\"></div><br>
|
||||
<div id=\"del_form'||main_cards.id||'\"><a href=\"#\" onclick=\"deleteCard('||main_cards.id||');\" class=\"text-danger\">archive</a></div> '
|
||||
ELSE
|
||||
'<img onclick=\"viewCard('||main_cards.id||');\" style=\"height:120px; \" src=\"'||background_picture||'\" ><br>
|
||||
<div id=\"del_form'||main_cards.id||'\"><a href=\"#\" onclick=\"deleteCard('||main_cards.id||');\" class=\"text-danger\">archive</a></div> '
|
||||
END) As button,
|
||||
card_country
|
||||
FROM main_cards
|
||||
WHERE
|
||||
status = 1
|
||||
AND main_cards.deleted IS NULL
|
||||
AND main_cards.button1_action NOT IN ('SURVEYA')
|
||||
" . $whereQuery . "
|
||||
ORDER BY main_cards.id DESC
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get expired cards
|
||||
* @return array
|
||||
*/
|
||||
public function getCardsExpired( $params = array() ) {
|
||||
$whereQuery = '';
|
||||
|
||||
if (!empty($params['card_category'])) {
|
||||
$whereQuery .= " AND button1_action='" . pg_escape_string($params['card_category']) . "' ";
|
||||
}
|
||||
|
||||
if (!empty($params['filter_name']) && !empty($params['filter_value'])) {
|
||||
$filter_name = $params['filter_name'];
|
||||
$filter_value = trim($params['filter_value']);
|
||||
|
||||
if ($filter_name == 'name') {
|
||||
$whereQuery .= " AND name ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'title') {
|
||||
$whereQuery .= " AND title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'short_title') {
|
||||
$whereQuery .= " AND short_title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'description') {
|
||||
$whereQuery .= " AND description ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'button1_action') {
|
||||
$whereQuery .= " AND button1_action ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
}elseif( empty($params['filter_name']) && !empty($params['filter_value']) ){
|
||||
// find all
|
||||
$filter_value = trim($params['filter_value']);
|
||||
$fields_like = [
|
||||
'name',
|
||||
'title',
|
||||
'short_title',
|
||||
'description',
|
||||
'button1_action'
|
||||
];
|
||||
$whereQuery .= " AND concat(".implode(',',$fields_like).") ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
$viewButton = "'<button id=\"acc'||id||'\" type=\"button\" class=\"btn btn-primary btn-xs\" block onClick=\"viewCard('||id||');\">View-'||id||'</button>'";
|
||||
$details = "'<b>Name: </b>'||name||'<br><b>Title: </b>'||title||'<br><b>Short Title: </b>'||short_title||'<br><b>Desc: </b>'||description ||'<br><b>Button: </b>'||button1||'<br><b>Button Text: </b>'||button1_text||'<br><b>Action: </>'||button1_action AS description";
|
||||
$image = "'<img onclick=\"viewCard('||id||');\" style=\"height:120px; \" src=\"'||background_picture||'\" ><br> <div id=\"del_form'||id||'\"><a href=\"#\" onclick=\"returnCard('||id||');\" class=\"text-danger\">make Inactive</a></div> ' As button";
|
||||
$del = "'<div id=\"xd_form'||id||'\"><button id=\"xd'||id||'\" type=\"button\" class=\"btn btn-danger btn-xs\" block onclick=\"deleteCard('||id||');\">Delete</button></div>' AS button2";
|
||||
$sql = sprintf('
|
||||
SELECT
|
||||
%s, %s, %s, %s
|
||||
from main_cards
|
||||
where
|
||||
card_canexpire = 1
|
||||
and now() > card_expiration
|
||||
%s
|
||||
order by id desc
|
||||
', $viewButton, $details, $image, $del, $whereQuery);
|
||||
|
||||
return $sql;
|
||||
}
|
||||
|
||||
public function getCardsOrderQuery($params = []) {
|
||||
$whereQuery = '';
|
||||
|
||||
if (!empty($params['card_category'])) {
|
||||
$whereQuery .= " AND main_cards.button1_action='" . pg_escape_string($params['card_category']) . "' ";
|
||||
}
|
||||
|
||||
if (!empty($params['filter_name']) && !empty($params['filter_value'])) {
|
||||
$filter_name = $params['filter_name'];
|
||||
$filter_value = trim($params['filter_value']);
|
||||
|
||||
if ($filter_name == 'name') {
|
||||
$whereQuery .= " AND main_cards.name ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'title') {
|
||||
$whereQuery .= " AND main_cards.title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'short_title') {
|
||||
$whereQuery .= " AND main_cards.short_title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'description') {
|
||||
$whereQuery .= " AND main_cards.description ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'button1_action') {
|
||||
$whereQuery .= " AND main_cards.button1_action ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT main_cards.card_order AS card_order,main_cards.id AS card_id,"
|
||||
. " '<b>Name:</b>'|| main_cards.name||'<br><b>Title:</b>'||title||'<br><b>Short Title</b>'||short_title||'<br><b>Desc :</b>'||description
|
||||
AS description,
|
||||
'<img onclick=\"viewCard('||main_cards.id||');\" style=\"height:120px; \" src=\"'||background_picture||'\" ><br>
|
||||
<div id=\"del_form'||main_cards.id||'\"><a href=\"#\" onclick=\"deleteCard('||main_cards.id||');\" class=\"text-danger\">archive</a></div> ' As button,
|
||||
card_country
|
||||
FROM main_cards
|
||||
WHERE
|
||||
status = 1
|
||||
AND main_cards.deleted IS NULL
|
||||
" . $whereQuery . "
|
||||
ORDER BY main_cards.card_order DESC
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getDeletedCardsQuery($params = []) {
|
||||
$whereQuery = '';
|
||||
|
||||
if (!empty($params['card_category'])) {
|
||||
$whereQuery .= " AND button1_action='" . pg_escape_string($params['card_category']) . "' ";
|
||||
}
|
||||
|
||||
if (!empty($params['filter_name']) && !empty($params['filter_value'])) {
|
||||
$filter_name = $params['filter_name'];
|
||||
$filter_value = trim($params['filter_value']);
|
||||
|
||||
if ($filter_name == 'name') {
|
||||
$whereQuery .= " AND name ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'title') {
|
||||
$whereQuery .= " AND title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'short_title') {
|
||||
$whereQuery .= " AND short_title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'description') {
|
||||
$whereQuery .= " AND description ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'button1_action') {
|
||||
$whereQuery .= " AND button1_action ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT '<button id=\"acc'||id||'\" type=\"button\" class=\"btn btn-primary btn-xs\" block onclick=\"viewCard('||id||');\">View-'||id||'</button>' ||'<br><hr>'|| "
|
||||
. "'-' AS Edit,"
|
||||
. " '<b>Name:</b>'|| name||'<br><b>Title:</b>'||title||'<br><b>Short Title</b>'||short_title||'<br><b>Desc :</b>'||description
|
||||
||'<br><b>Button :</b>'||button1||'<br><b>Button Text :</b>'
|
||||
||button1_text||'<br><b>Action :</>'||button1_action AS description,
|
||||
'<img onclick=\"viewCard('||id||');\" style=\"height:120px; \" src=\"'||background_picture||'\" ><br>
|
||||
<div id=\"del_form'||id||'\"><a href=\"#\" onclick=\"returnCard('||id||');\" class=\"text-danger\">make Inactive</a></div> ' As button
|
||||
FROM
|
||||
main_cards
|
||||
WHERE
|
||||
deleted IS NOT NULL
|
||||
" . $whereQuery . "
|
||||
ORDER BY deleted DESC
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getSurveyCardsQuery($params = []) {
|
||||
$whereQuery = '';
|
||||
|
||||
if (!empty($params['card_category'])) {
|
||||
$whereQuery .= " AND button1_action='" . pg_escape_string($params['card_category']) . "' ";
|
||||
}
|
||||
|
||||
if (!empty($params['filter_name']) && !empty($params['filter_value'])) {
|
||||
$filter_name = $params['filter_name'];
|
||||
$filter_value = trim($params['filter_value']);
|
||||
|
||||
if ($filter_name == 'name') {
|
||||
$whereQuery .= " AND name ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'title') {
|
||||
$whereQuery .= " AND title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'short_title') {
|
||||
$whereQuery .= " AND short_title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'description') {
|
||||
$whereQuery .= " AND description ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'button1_action') {
|
||||
$whereQuery .= " AND button1_action ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
}elseif( empty($params['filter_name']) && !empty($params['filter_value']) ){
|
||||
// find all
|
||||
$filter_value = trim($params['filter_value']);
|
||||
$fields_like = [
|
||||
'name',
|
||||
'title',
|
||||
'short_title',
|
||||
'description',
|
||||
'button1_action'
|
||||
];
|
||||
$whereQuery .= " AND concat(".implode(',',$fields_like).") ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT '<button id=\"acc'||id||'\" type=\"button\" class=\"btn btn-primary btn-xs\" block onclick=\"viewCard('||id||');\">View-'||id||'</button>' ||'<br><hr>'|| "
|
||||
. "'<button id=\"edit'||id||'\" type=\"button\" class=\"btn btn-warning btn-xs\" block onclick=\"editCard('||id||');\">Edit-'||id||'</button>' AS Edit,"
|
||||
. " '<b>Card ID:</b>'||name||'<br><b>Question:</b>'||title||'<br><b>Short Title</b>'||short_title||'<br><b>Answers Options :</b>'||description
|
||||
||'<br><b>Button :</b>'||button1||'<br><b>Button Text :</b>'
|
||||
||button1_text||'<br><b>Action :</>'||button1_action AS description,
|
||||
'<img onclick=\"viewCard('||id||');\" style=\"height:120px; \" src=\"'||background_picture||'\" ><br>
|
||||
<div id=\"del_form'||id||'\"><a href=\"#\" onclick=\"deleteCard('||id||');\" class=\"text-danger\">archive</a></div> ' As button
|
||||
FROM
|
||||
main_cards
|
||||
WHERE
|
||||
status = 1
|
||||
" . $whereQuery . "
|
||||
ORDER BY id DESC
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getArchivedCardsQuery($params = []) {
|
||||
$whereQuery = '';
|
||||
|
||||
if (!empty($params['card_category'])) {
|
||||
$whereQuery .= " AND button1_action='" . pg_escape_string($params['card_category']) . "' ";
|
||||
}
|
||||
|
||||
if (!empty($params['filter_name']) && !empty($params['filter_value'])) {
|
||||
$filter_name = $params['filter_name'];
|
||||
$filter_value = trim($params['filter_value']);
|
||||
|
||||
if ($filter_name == 'name') {
|
||||
$whereQuery .= " AND name ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'title') {
|
||||
$whereQuery .= " AND title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'short_title') {
|
||||
$whereQuery .= " AND short_title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'description') {
|
||||
$whereQuery .= " AND description ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'button1_action') {
|
||||
$whereQuery .= " AND button1_action ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
}elseif( empty($params['filter_name']) && !empty($params['filter_value']) ){
|
||||
// find all
|
||||
$filter_value = trim($params['filter_value']);
|
||||
$fields_like = [
|
||||
'name',
|
||||
'title',
|
||||
'short_title',
|
||||
'description',
|
||||
'button1_action'
|
||||
];
|
||||
$whereQuery .= " AND concat(".implode(',',$fields_like).") ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT '<button id=\"acc'||id||'\" type=\"button\" class=\"btn btn-primary btn-xs\" block onclick=\"viewCard('||id||');\">View-'||id||'</button>' ||'<br><hr>'|| "
|
||||
. "'-' AS Edit,"
|
||||
. " '<b>Name:</b>'|| name||'<br><b>Title:</b>'||title||'<br><b>Short Title</b>'||short_title||'<br><b>Desc :</b>'||description
|
||||
||'<br><b>Button :</b>'||button1||'<br><b>Button Text :</b>'
|
||||
||button1_text||'<br><b>Action :</>'||button1_action AS description,
|
||||
'<img onclick=\"viewCard('||id||');\" style=\"height:120px; \" src=\"'||background_picture||'\" ><br>
|
||||
<div id=\"del_form'||id||'\"><a href=\"#\" onclick=\"activateCard('||id||');\" class=\"text-danger\">Activate</a></div> ' As button,
|
||||
'<div id=\"xd_form'||id||'\"><button id=\"xd'||id||'\" type=\"button\" class=\"btn btn-danger btn-xs\" block onclick=\"deleteCard('||id||');\">Delete</button></div>' AS button2
|
||||
FROM
|
||||
main_cards
|
||||
WHERE
|
||||
status <> 1
|
||||
AND deleted IS NULL
|
||||
" . $whereQuery . "
|
||||
ORDER BY id DESC
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getDynamicCardsQuery($params = []) {
|
||||
$whereQuery = '';
|
||||
|
||||
if (!empty($params['card_category'])) {
|
||||
$whereQuery .= " AND button1_action='" . pg_escape_string($params['card_category']) . "' ";
|
||||
}
|
||||
|
||||
if (!empty($params['filter_name']) && !empty($params['filter_value'])) {
|
||||
$filter_name = $params['filter_name'];
|
||||
$filter_value = trim($params['filter_value']);
|
||||
|
||||
if ($filter_name == 'name') {
|
||||
$whereQuery .= " AND name ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'title') {
|
||||
$whereQuery .= " AND title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'short_title') {
|
||||
$whereQuery .= " AND short_title ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'description') {
|
||||
$whereQuery .= " AND description ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
|
||||
if ($filter_name == 'button1_action') {
|
||||
$whereQuery .= " AND button1_action ILIKE '%" . pg_escape_string($filter_value) . "%' ";
|
||||
}
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT '<b>Card ID:</b>'||name||'<br><b>Question:</b>'||title||'<br><b>Short Title</b>'||short_title||'<br><b>Answers Options :</b>'||description
|
||||
||'<br><b>Button :</b>'||button1||'<br><b>Button Text :</b>'
|
||||
||button1_text||'<br><b>Action :</>'||button1_action AS description,
|
||||
'<img onclick=\"viewCard('||id||');\" style=\"height:120px; \" src=\"'||background_picture||'\" ><br>
|
||||
<div id=\"del_form'||id||'\"><a href=\"#\" onclick=\"deleteCard('||id||');\" class=\"text-danger\">archive</a></div> ' As button,
|
||||
'<button id=\"acc'||id||'\" type=\"button\" class=\"btn btn-primary btn-xs\" block onclick=\"viewCard('||id||');\">View-'||id||'</button>' ||'<br><hr>'|| '<button id=\"edit'||id||'\" type=\"button\" class=\"btn btn-warning btn-xs\" block onclick=\"editCard('||id||');\">Edit-'||id||'</button>' AS Edit
|
||||
FROM
|
||||
main_cards
|
||||
WHERE
|
||||
status = 1
|
||||
" . $whereQuery . "
|
||||
ORDER BY id DESC
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
public function getDefaultCardPictureValue(){
|
||||
global $savvyext;
|
||||
$storage = $savvyext->cfgReadChar('system.storage_url');
|
||||
$sql = "SELECT '{$storage}cards/'||uniqueid||'.'||format AS id,"
|
||||
. " id||' ['|| file_size*0.01 ||'kb] -{$storage}cards/'||uniqueid||'.'||format AS val FROM card_images limit 1";
|
||||
$q = (array)$this->db->query($sql)->row();
|
||||
return $q['id']??'';
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,455 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Member_model extends CI_Model
|
||||
{
|
||||
|
||||
const FIND_SELECT = [
|
||||
'email' => 'Email',
|
||||
'firstname' => 'Firstname',
|
||||
'lastname' => 'Lastname',
|
||||
'id' => 'ID',
|
||||
// 'location' => 'Location',
|
||||
'phone' => 'Phone',
|
||||
'username' => 'Username',
|
||||
'loc' => 'Loc',
|
||||
'decision_group' => 'Decistion Group'
|
||||
];
|
||||
|
||||
const COMBO_FIND_MEMBER = [
|
||||
'status' => 'status',
|
||||
'test' => 'test',
|
||||
'alert_notification' => 'alert_notification',
|
||||
'alert_email' => 'alert_email',
|
||||
'country' => 'country'
|
||||
];
|
||||
|
||||
const NUMERIC_FIND_MEMBER = [
|
||||
'from_min_budget' => 'min_budget >=',
|
||||
'to_min_budget' => 'min_budget <=',
|
||||
'from_max_budget' => 'max_budget >=',
|
||||
'to_max_budget' => 'max_budget <=',
|
||||
'from_points' => 'points >=',
|
||||
'to_points' => 'points <=',
|
||||
'from_count_acct' => 'count_acct >=',
|
||||
'to_count_acct' => 'count_acct <=',
|
||||
'from_count_email' => 'count_email >=',
|
||||
'to_count_email' => 'count_email <=',
|
||||
'from_login_failures' => 'login_failures >=',
|
||||
'to_login_failures' => 'login_failures <='
|
||||
];
|
||||
|
||||
const DATE_FIND_MEMBER = [
|
||||
'from_added' => 'DATE(added) >=',
|
||||
'to_added' => 'DATE(added) <=',
|
||||
'from_last_login' => 'DATE(last_login) >=',
|
||||
'to_last_login' => 'DATE(last_login) <=',
|
||||
'from_last_acct' => 'DATE(last_acct) >=',
|
||||
'to_last_acct' => 'DATE(last_acct) <=',
|
||||
'from_last_email' => 'DATE(last_email) >=',
|
||||
'to_last_email' => 'DATE(last_email) <=',
|
||||
'from_last_audit' => 'DATE(last_audit) >=',
|
||||
'to_last_audit' => 'DATE(last_audit) <=',
|
||||
'from_points_updated' => 'DATE(points_updated) >=',
|
||||
'to_points_updated' => 'DATE(points_updated) <=',
|
||||
'from_updated' => 'DATE(updated) >=',
|
||||
'to_updated' => 'DATE(updated) <=',
|
||||
'from_decision_updated' => 'DATE(decision_updated) >=',
|
||||
'to_decision_updated' => 'DATE(decision_updated) <=',
|
||||
'from_gps_enabled' => 'DATE(gps_enabled) >=',
|
||||
'to_gps_enabled' => 'DATE(gps_enabled) <=',
|
||||
];
|
||||
|
||||
const STRING_FIND_MEMBER = [
|
||||
'city' => 'city'
|
||||
];
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function getmemberLocationTracking($member_id, $start_date, $end_date, $limit = null, $page = null)
|
||||
{
|
||||
|
||||
$gps = $this->load->database('gps', TRUE);
|
||||
$mysql = "SELECT
|
||||
'<button type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"viewTracked('||traked_group||');\" >View</button>' AS view ,traked_group, count(id)
|
||||
FROM members_tracking
|
||||
WHERE member_id = $member_id
|
||||
AND traked_group IS NOT NULL";
|
||||
|
||||
if ($start_date) {
|
||||
$mysql .= " AND ttime::timestamp::date >= '" . pg_escape_string($start_date) . "'";
|
||||
}
|
||||
|
||||
if ($end_date) {
|
||||
$mysql .= " AND ttime::timestamp::date <= '" . pg_escape_string($end_date) . "'";
|
||||
}
|
||||
|
||||
$mysql .= " GROUP BY traked_group";
|
||||
|
||||
if ($limit) {
|
||||
$mysql .= " LIMIT " . $limit . " OFFSET " . $page;
|
||||
}
|
||||
|
||||
return $gps->query($mysql)->result_array();
|
||||
}
|
||||
public function getMemberMessagelReport($member_id, &$data)
|
||||
{
|
||||
|
||||
$this->load->library('table');
|
||||
$this->table->set_template($this->template);
|
||||
|
||||
$mysql = "SELECT '<button id=\"trip'||cp.id||'\" type=\"button\" class=\"btn btn-primary btn-xs\" block onclick=\"viewCarpool('||cp.id||');\">View</button>' AS view, "
|
||||
. "cp.pool,mc.title,mc.id AS card_id,cp.added,cp.updated,cp.status "
|
||||
. "FROM members_carpool cp "
|
||||
. "LEFT JOIN members m ON m.id = cp.member_id "
|
||||
. "LEFT JOIN main_cards mc ON mc.id=cp.card_id WHERE cp.member_id=" . $member_id;
|
||||
|
||||
$query = $this->read_replica->query($mysql);
|
||||
$data['carpool_table'] = $this->table->generate($query);
|
||||
$data["page_title"] = "Carpool Report";
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function get_all_record_member_tracking($filters, $limit = null, $offset = null, $is_export_mode = false)
|
||||
{
|
||||
$gps = $this->load->database('gps', TRUE);
|
||||
$gps->select('traked_group, count(id) AS count');
|
||||
$gps->from('members_tracking');
|
||||
|
||||
foreach ($filters as $key => $value) {
|
||||
if ($key === 'start_date') {
|
||||
$gps->where('DATE(ttime) >=', $value);
|
||||
} else if ($key === 'end_date') {
|
||||
$gps->where('DATE(ttime) <=', $value);
|
||||
} else {
|
||||
$gps->where($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
$gps->group_by('traked_group');
|
||||
|
||||
if ($limit && !$is_export_mode) {
|
||||
$gps->limit($limit, $offset);
|
||||
}
|
||||
if($is_export_mode){
|
||||
return $gps->get();
|
||||
}
|
||||
return $gps->get()->result_array();
|
||||
}
|
||||
|
||||
public function get_all_record_member_tracking_by_tracked_group($filters, $limit = null, $offset = null)
|
||||
{
|
||||
$gps = $this->load->database('gps', TRUE);
|
||||
|
||||
$gps->select('*');
|
||||
|
||||
if (isset($filters['radius'])) {
|
||||
$gps->from("( {$this->withinDistanceFromLatLng($filters['lat'],$filters['lng'],$filters['radius'])} ) AS members_tracking");
|
||||
|
||||
unset($filters['radius']);
|
||||
unset($filters['lat']);
|
||||
unset($filters['lng']);
|
||||
} else {
|
||||
$gps->from('members_tracking');
|
||||
}
|
||||
|
||||
foreach ($filters as $key => $value) {
|
||||
if ($key === 'start_date') {
|
||||
$gps->where('DATE(ttime) >=', $value);
|
||||
} else if ($key === 'end_date') {
|
||||
$gps->where('DATE(ttime) <=', $value);
|
||||
} else {
|
||||
$gps->where($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$gps->limit($limit, $offset);
|
||||
$gps->order_by('id DESC');
|
||||
}
|
||||
|
||||
return array_map(function ($ele) {
|
||||
return array_map(function ($val) {
|
||||
return is_null($val) ? "" : $val;
|
||||
}, $ele);
|
||||
}, $gps->get()->result_array());
|
||||
}
|
||||
|
||||
function withinDistanceFromLatLng($latitude, $longitude, $distance_in_km)
|
||||
{
|
||||
$earth_radius = 6371;
|
||||
$km_per_degree_lat = 111.2;
|
||||
$pi = 3.14 / 180;
|
||||
|
||||
$query = "SELECT * FROM (
|
||||
SELECT (
|
||||
$earth_radius * acos(
|
||||
cos( radians( {$latitude}) )
|
||||
* cos( radians( lat ) )
|
||||
* cos( radians( lng ) - radians( {$longitude} ) )
|
||||
+ sin( radians( {$latitude}) )
|
||||
* sin( radians( lat ) )
|
||||
)
|
||||
) AS distance_filter
|
||||
, *
|
||||
FROM members_tracking
|
||||
WHERE lat BETWEEN " . ($latitude - ($distance_in_km / $km_per_degree_lat)) .
|
||||
" AND " . ($latitude + ($distance_in_km / $km_per_degree_lat));
|
||||
|
||||
$delta = round($distance_in_km / ($km_per_degree_lat * COS(deg2rad($longitude))), 10);
|
||||
|
||||
// Bounding box for speed - latitude within range (longtitude to km not linear)
|
||||
if (cos($longitude * $pi) > 0) {
|
||||
|
||||
$from = $longitude - $delta;
|
||||
$to = $longitude + $delta;
|
||||
|
||||
$query .=
|
||||
" AND lng" .
|
||||
" BETWEEN " . $from .
|
||||
" AND " . $to;
|
||||
} else {
|
||||
|
||||
$from = $longitude + $delta;
|
||||
$to = $longitude - $delta;
|
||||
|
||||
$query .=
|
||||
" AND lng" .
|
||||
" BETWEEN " . $from .
|
||||
" AND " . $to;
|
||||
}
|
||||
|
||||
// distance limit for circle
|
||||
$query .= " ) members_tracking
|
||||
WHERE distance_filter <= " . $distance_in_km;
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function get_all_record_members_bankimport($filters, $limit = null, $offset = null)
|
||||
{
|
||||
$this->read_replica->select('*');
|
||||
$this->read_replica->from('members_bankimport');
|
||||
|
||||
$array_date = [
|
||||
'start_date' => 'DATE(time) >=',
|
||||
'end_date' => 'DATE(time) <=',
|
||||
];
|
||||
|
||||
$array_string = [
|
||||
'provider_category' => 'provider_category',
|
||||
'merchant_name' => 'merchant_name',
|
||||
'category' => 'category',
|
||||
];
|
||||
|
||||
$array_numeric = [
|
||||
'currency' => 'currency',
|
||||
'member_id' => 'member_id'
|
||||
];
|
||||
|
||||
|
||||
foreach ($filters as $key => $value) {
|
||||
if (in_array($key, $array_date)) {
|
||||
|
||||
$this->read_replica->where($array_date[$key], $value);
|
||||
} else if (in_array($key, $array_string)) {
|
||||
|
||||
$this->read_replica->like('lower(' . $key . ')', strtolower($value));
|
||||
} else if (in_array($key, $array_numeric)) {
|
||||
|
||||
$this->read_replica->where($array_numeric[$key], $value);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('time DESC');
|
||||
}
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function get_all_record_saved_trips($filters, $limit = null, $offset = null)
|
||||
{
|
||||
$this->read_replica->select('*');
|
||||
$this->read_replica->from('members_trips');
|
||||
|
||||
foreach ($filters as $key => $value) {
|
||||
if ($key === 'start_date') {
|
||||
$this->read_replica->where('DATE(trip_date) >=', $value);
|
||||
} else if ($key === 'end_date') {
|
||||
$this->read_replica->where('DATE(trip_date) <=', $value);
|
||||
} else if (
|
||||
strpos($key, 'trip') !== FALSE ||
|
||||
strpos($key, 'country') !== FALSE
|
||||
) {
|
||||
$this->read_replica->like('lower(' . $key . ')', strtolower($value));
|
||||
} else {
|
||||
$this->read_replica->where($key, $value);
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('trip_name DESC');
|
||||
}
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function get_member_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
|
||||
$this->read_replica->select([
|
||||
'\'<a class="btn btn-warning btn-sm"
|
||||
href="/member/viewLocateMember?member_id=\'||id||\'" >Select</a>\' AS select',
|
||||
'id',
|
||||
'username',
|
||||
'firstname',
|
||||
'lastname',
|
||||
'last_login',
|
||||
'added',
|
||||
'loc',
|
||||
'\'<button style="padding:3px;" type="button" class="btn btn-info btn-xs" onclick="viewMember(\'||id||\');" >View</button>\' AS ACT'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('members');
|
||||
|
||||
$this->read_replica->where('id > 0');
|
||||
foreach ($filters as $key => $value) {
|
||||
|
||||
if (array_key_exists($key, self::NUMERIC_FIND_MEMBER)) {
|
||||
|
||||
$this->read_replica->where(self::NUMERIC_FIND_MEMBER[$key], $value);
|
||||
|
||||
} else if (array_key_exists($key, self::STRING_FIND_MEMBER)) {
|
||||
|
||||
$this->read_replica->where(self::STRING_FIND_MEMBER[$key], $value);
|
||||
|
||||
} else if (array_key_exists($key, self::DATE_FIND_MEMBER)) {
|
||||
|
||||
$this->read_replica->where(self::DATE_FIND_MEMBER[$key], $value);
|
||||
|
||||
} else if (array_key_exists($key, self::FIND_SELECT)) {
|
||||
|
||||
switch($key) {
|
||||
case 'id':
|
||||
|
||||
$this->read_replica->where($key, $value);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
$key = ($key === 'loc' ? "TEXT($key)" : $key);
|
||||
$key = 'lower(' . $key . ')';
|
||||
$this->read_replica->like($key, strtolower($value));
|
||||
|
||||
}
|
||||
|
||||
} else if (array_key_exists($key, self::COMBO_FIND_MEMBER)) {
|
||||
|
||||
$this->read_replica->where(self::COMBO_FIND_MEMBER[$key], $value);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('id');
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function get_tracked_email_record(
|
||||
$filters = [],
|
||||
$count_record = true,
|
||||
$limit = null,
|
||||
$offset = null) {
|
||||
|
||||
$in_array = [
|
||||
'member_id_list' => 'member_id',
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'subject' => 'lower(subject)',
|
||||
'message_from' => 'lower(message_from)'
|
||||
];
|
||||
|
||||
$date_array = [
|
||||
'start_created' => 'DATE(created) >=',
|
||||
'end_created' => 'DATE(created) <=',
|
||||
'start_message_date' => 'DATE(message_date) >=',
|
||||
'end_message_date' => 'DATE(message_date) <=',
|
||||
];
|
||||
|
||||
if ($count_record) {
|
||||
|
||||
$this->read_replica->select([
|
||||
'count(*) AS all_count'
|
||||
]);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->select([
|
||||
'id',
|
||||
'member_id',
|
||||
'subject',
|
||||
'created',
|
||||
'message_from',
|
||||
'hash',
|
||||
'date_parsed',
|
||||
'oauth2_pull_job_id',
|
||||
'message_date',
|
||||
'message'
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
$this->read_replica->from('trackedemail_item');
|
||||
$this->read_replica->where('1 = 1');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $in_array)) {
|
||||
|
||||
$this->read_replica->where_in($in_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $date_array)) {
|
||||
|
||||
$this->read_replica->where($date_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
|
||||
$this->read_replica->like($string_array[$key], strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$limit = " LIMIT ${limit} OFFSET ${offset}";
|
||||
}
|
||||
|
||||
$query = $this->read_replica->get_compiled_select();
|
||||
|
||||
if (isset($filters['sql_raw'])) {
|
||||
$query .= ' AND ' . pg_escape_string($filters['sql_raw']);
|
||||
}
|
||||
|
||||
$query .= $limit;
|
||||
|
||||
return $this->read_replica->query($query);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Members_notification_model extends CI_Model
|
||||
{
|
||||
const PENDING_STATUS = 1;
|
||||
const COMPLETED_STATUS = 5;
|
||||
const EXPIRED_STATUS = 2;
|
||||
const CANCELLED_STATUS = 3;
|
||||
|
||||
public function __constructor()
|
||||
{
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function getNotifications($params = [])
|
||||
{
|
||||
$condition = ' WHERE true ';
|
||||
if (isset($params['from_to']) && !empty($params['from_to'])) {
|
||||
// from_to format: 2020-02-03 - 2020-03-01
|
||||
$fromToArray = explode(' - ', $params['from_to']);
|
||||
$fromDate = $fromToArray[0];
|
||||
$toDate = $fromToArray[1];
|
||||
$condition .= " AND to_char(n.added, 'YYYY-MM-DD') >= '" . pg_escape_string($fromDate) . "' AND to_char(n.added, 'YYYY-MM-DD') <= '" . pg_escape_string($toDate) . "' ";
|
||||
}
|
||||
if (isset($params['status']) && $params['status'] !== '') {
|
||||
$condition .= " AND n.status = " . pg_escape_string((int)$params['status']);
|
||||
}
|
||||
if (isset($params['notice_type']) && !empty($params['notice_type'])) {
|
||||
$condition .= " AND n.notice_type = '" . pg_escape_string($params['notice_type']) . "'";
|
||||
}
|
||||
if (isset($params['account_email']) && !empty($params['account_email'])) {
|
||||
$condition .= " AND m.email ILIKE '%" . pg_escape_string($params['account_email']) . "%' ";
|
||||
}
|
||||
if (isset($params['trigger_key']) && !empty($params['trigger_key'])) {
|
||||
$condition .= " AND n.trigger_key ILIKE '%" . pg_escape_string($params['trigger_key']) . "%' ";
|
||||
}
|
||||
if (isset($params['email_msg']) && !empty($params['email_msg'])) {
|
||||
$condition .= " AND n.msg ILIKE '%" . pg_escape_string($params['email_msg']) . "%' ";
|
||||
}
|
||||
if (isset($params['mode']) && !empty($params['mode'])) {
|
||||
$condition .= " AND n.mmode ILIKE '%" . pg_escape_string($params['mode']) . "%' ";
|
||||
}
|
||||
return "SELECT m.id AS member_id , m.email,"
|
||||
. "CASE WHEN m.alert_notification=1 THEN 'Yes' ELSE 'No' END AS NotificationAlert ,n.trigger_key,"
|
||||
. "( CASE WHEN m.alert_email=1 THEN 'Yes' ELSE 'No' END) AS EmailAlert ,"
|
||||
. " n.notice_type,n.msg,"
|
||||
. " ( CASE WHEN n.status=1 THEN 'Pending' WHEN n.status=5 THEN 'Completed' WHEN n.status=2 THEN 'Expired' WHEN n.status=3 THEN 'Cancelled' ELSE 'No' END) AS msg_status, "
|
||||
. " n.added,n.mmode ,"
|
||||
. "'<button type=\"button\" onclick=\"pushNotification('||n.id||','||m.id||');\" class=\"btn btn-danger\" id=\"acc'||n.id||'\">Send</button> <button type=\"button\" onclick=\"pushCard('||n.id||','||m.id||');\" class=\"btn btn-info\" id=\"acc'||n.id||'\">Card</button> <div id=\"msgl'||n.id||'\"></div>' AS Send "
|
||||
. " FROM members_notification n LEFT JOIN members m On m.id=n.member_id " . $condition . " ORDER BY n.added DESC";
|
||||
}
|
||||
|
||||
protected function checkCondition($condition, $query)
|
||||
{
|
||||
if (strpos($query, 'WHERE') === false) {
|
||||
$query .= " WHERE $condition";
|
||||
} else {
|
||||
$query .= " AND $condition";
|
||||
}
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Myfloat_version_model extends CI_Model
|
||||
{
|
||||
public function __constructor()
|
||||
{
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function getVersionQuery($params = [])
|
||||
{
|
||||
$whereQuery = ' WHERE 1 = 1 ';
|
||||
|
||||
if (!empty($params['platform_filter'])) {
|
||||
$whereQuery .= " AND platform_id = " . pg_escape_string(trim($params['platform_filter'])) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['text_filter'])) {
|
||||
$whereQuery .= " AND (name ILIKE '%" . $params['text_filter'] . "%' OR notes ILIKE '%" . $params['text_filter'] . "%' OR url ILIKE '%" . $params['text_filter'] . "%') ";
|
||||
}
|
||||
|
||||
if (!empty($params['rev_count_filter'])) {
|
||||
$whereQuery .= " AND mv.rev_count = " . pg_escape_string(trim($params['rev_count_filter'])) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['short_hash_filter'])) {
|
||||
$whereQuery .= " AND mv.short_hash ILIKE '%" . pg_escape_string(trim($params['short_hash_filter'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['released_filter'])) {
|
||||
// released_filter format: 2020-02-03 - 2020-03-01
|
||||
$fromToArray = explode(' - ', $params['released_filter']);
|
||||
$fromDate = $fromToArray[0];
|
||||
$toDate = $fromToArray[1];
|
||||
|
||||
$whereQuery .= " AND to_char(mv.released, 'YYYY-MM-DD') >= '" . pg_escape_string($fromDate) . "'
|
||||
AND to_char(mv.released, 'YYYY-MM-DD') <= '" . pg_escape_string($toDate) . "'
|
||||
";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
*,
|
||||
mv.id AS id
|
||||
FROM
|
||||
myfloat_version mv
|
||||
JOIN members_device_platforms mdp ON mv.platform_id = mdp.id
|
||||
" . $whereQuery . "
|
||||
ORDER BY
|
||||
mv.id ASC
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Notification_model extends CI_Model {
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function updateDescription($data) {
|
||||
$this->db->set('action_detail', $data['description']);
|
||||
$this->db->where('id', (int)$data['id']);
|
||||
$this->db->update('email_trigger');
|
||||
|
||||
return $this->db->affected_rows();
|
||||
}
|
||||
|
||||
|
||||
public function get_all_record_notifications(
|
||||
$filters,
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
$this->read_replica->select(
|
||||
'mn.added AS added,
|
||||
mn.expire AS expire,
|
||||
(CASE WHEN m.alert_notification=1 THEN \'Yes\' ELSE \'No\' END) AS sendAlert,
|
||||
(CASE WHEN m.alert_email=1 THEN \'Yes\' ELSE \'No\' END) AS emailAlert,
|
||||
mn.trigger_key AS trigger_key,
|
||||
mn.notice_type AS notice_type,
|
||||
mn.msg AS msg,
|
||||
(
|
||||
CASE
|
||||
WHEN mn.status=1 THEN \'Pending\'
|
||||
WHEN mn.status=5 THEN \'Completed\'
|
||||
WHEN mn.status=2 THEN \'Expired\'
|
||||
WHEN mn.status=3 THEN \'Cancelled\'
|
||||
ELSE \'No\' END
|
||||
) AS msg_status,
|
||||
mn.mmode AS mmode,
|
||||
mn.id AS id_members_notification,
|
||||
m.id AS id_members'
|
||||
);
|
||||
|
||||
$this->read_replica->from('members_notification mn');
|
||||
$this->read_replica->join('members m', 'm.id = mn.member_id', 'left');
|
||||
|
||||
foreach ($filters as $key => $value) {
|
||||
if ($key === 'member_id') {
|
||||
$this->read_replica->where('mn.member_id', $value);
|
||||
} else if ($key === 'start_date') {
|
||||
$this->read_replica->where('DATE(mn.added) >=', $value);
|
||||
} else if ($key === 'end_date') {
|
||||
$this->read_replica->where('DATE(mn.added) <=', $value);
|
||||
} else if ($key === 'msg_status') {
|
||||
$this->read_replica->where('mn.status =', $value);
|
||||
} else {
|
||||
$this->read_replica->like('lower(' . $key . ')', strtolower($value));
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('mn.added DESC');
|
||||
}
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Oauth2_model extends CI_Model
|
||||
{
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function get_all_record_oauth2_tokens(
|
||||
$filters,
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
$this->read_replica->select(
|
||||
'ot.email,
|
||||
ot.name,
|
||||
op.name AS provider,
|
||||
ot.created,
|
||||
ot.updated,
|
||||
ot.expires_in,
|
||||
op.access_type'
|
||||
);
|
||||
$this->read_replica->from('oauth2_tokens ot');
|
||||
$this->read_replica->join('oauth2_providers op', 'op.id=ot.oauth2_provider_id');
|
||||
|
||||
foreach ($filters as $key => $value) {
|
||||
if ($key === 'member_id') {
|
||||
$this->read_replica->where('ot.member_id', $value);
|
||||
} else if ($key === 'start_date') {
|
||||
$this->read_replica->where('DATE(ot.updated) >=', $value);
|
||||
} else if ($key === 'end_date') {
|
||||
$this->read_replica->where('DATE(ot.updated) <=', $value);
|
||||
} else {
|
||||
$this->read_replica->like('lower(' . $key . ')', strtolower($value));
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('ot.created DESC');
|
||||
}
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function get_all_record_oauth2_pull_jobs(
|
||||
$filters,
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
$this->read_replica->select(
|
||||
'created,
|
||||
started,
|
||||
completed'
|
||||
);
|
||||
$this->read_replica->from('oauth2_pull_jobs');
|
||||
|
||||
$this->read_replica->where('started IS NOT NULL');
|
||||
foreach ($filters as $key => $value) {
|
||||
if ($key === 'member_id') {
|
||||
$this->read_replica->where('member_id', $value);
|
||||
} else if ($key === 'start_date') {
|
||||
$this->read_replica->where('DATE(completed) >=', $value);
|
||||
} else if ($key === 'end_date') {
|
||||
$this->read_replica->where('DATE(completed) <=', $value);
|
||||
} else {
|
||||
$this->read_replica->like('lower(' . $key . ')', strtolower($value));
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('started DESC');
|
||||
}
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
|
||||
public function get_all_record_oauth2_pull_threads(
|
||||
$filters,
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
$this->read_replica->select(
|
||||
'pjt.created AS created,
|
||||
pjt.started AS started,
|
||||
pjt.completed AS completed ,
|
||||
pjt.item_count AS item_count,
|
||||
pjt.search_term AS search_term,
|
||||
pjt.search_from AS search_from,
|
||||
pjt.failed AS failed'
|
||||
);
|
||||
$this->read_replica->from('oauth2_pull_job_threads pjt');
|
||||
$this->read_replica->join('oauth2_pull_jobs pj', 'pjt.id = pjt.oauth2_pull_job_id');
|
||||
|
||||
foreach ($filters as $key => $value) {
|
||||
if ($key === 'member_id') {
|
||||
$this->read_replica->where('pj.member_id', $value);
|
||||
} else if ($key === 'start_date') {
|
||||
$this->read_replica->where('DATE(pjt.completed) >=', $value);
|
||||
} else if ($key === 'end_date') {
|
||||
$this->read_replica->where('DATE(pjt.completed) <=', $value);
|
||||
} else {
|
||||
$this->read_replica->like('lower(' . $key . ')', strtolower($value));
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('pjt.id');
|
||||
}
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Onboarding_survey_model extends CI_Model {
|
||||
|
||||
public function __constructor() {
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function getOnboardingSurvey($params = null, $page = 0, $limit = 10) {
|
||||
$queryString = 'SELECT id, group_key, answers_key, answers FROM onboarding_survey';
|
||||
$countString = 'SELECT COUNT(*) FROM onboarding_survey';
|
||||
$whereString = ' WHERE 1=1';
|
||||
$orderByString = ' ORDER BY id ASC';
|
||||
$offset = $page * $limit;
|
||||
$paginationString = " LIMIT $limit OFFSET $offset";
|
||||
|
||||
if (empty($params)) {
|
||||
$queryString .= $orderByString . $paginationString;
|
||||
$query = $this->db->query($queryString);
|
||||
$countQuery = $this->db->query($countString);
|
||||
|
||||
$data = [
|
||||
'result' => $query->result_array(),
|
||||
'total' => $countQuery->result_array()[0]['count'],
|
||||
'pageSize' => $limit,
|
||||
'pageNo' => $page
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
if(!empty($params['answersKey'])) {
|
||||
$whereString .= " AND answers_key = '" . pg_escape_string($params['answersKey']) . "' ";
|
||||
}
|
||||
|
||||
if(!empty($params['answers'])) {
|
||||
$whereString .= " AND answers ILIKE '%" . pg_escape_string($params['answers']) . "%' ";
|
||||
}
|
||||
|
||||
$queryString .= $whereString . $orderByString . $paginationString;
|
||||
|
||||
$countString .= $whereString;
|
||||
|
||||
$query = $this->db->query($queryString);
|
||||
$countQuery = $this->db->query($countString);
|
||||
|
||||
$data = [
|
||||
'result' => $query->result_array(),
|
||||
'total' => $countQuery->result_array()[0]['count'],
|
||||
'pageSize' => $limit,
|
||||
'pageNo' => $page
|
||||
];
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getAvailableAndAssignedSurveyCards($params)
|
||||
{
|
||||
$answersKey = $params['answersKey'];
|
||||
$cardCat = $params['cardCat'];
|
||||
$search = $params['search'] ?? '';
|
||||
$cardCatFilter = '';
|
||||
|
||||
if ($cardCat !== '') {
|
||||
$cardCatFilter .= " AND mc.button1_action = '$cardCat'";
|
||||
}
|
||||
if ($search !== '') {
|
||||
$cardCatFilter .= " AND (mc.name ILIKE '%" . pg_escape_string($search) . "%' OR mc.title ILIKE '%" . pg_escape_string($search) . "%') ";
|
||||
}
|
||||
|
||||
$assignedCardsQueryString = "SELECT mc.id, mc.name, mc.title, TO_CHAR(mc.added, 'YYYY-MM-DD HH24:MI') as added
|
||||
FROM onboarding_survey_cards osc
|
||||
LEFT JOIN main_cards mc ON mc.id = osc.card_id
|
||||
WHERE answers_key = '".pg_escape_string($answersKey)."' $cardCatFilter ORDER BY mc.added ASC";
|
||||
$assignedCardsQuery = $this->db->query($assignedCardsQueryString);
|
||||
$assignedCards = $assignedCardsQuery->result_array();
|
||||
|
||||
$assignedCardsID = [0];
|
||||
|
||||
foreach ($assignedCards as $assignedCard) {
|
||||
if (!empty($assignedCard['id'])) {
|
||||
array_push($assignedCardsID, $assignedCard['id']);
|
||||
}
|
||||
}
|
||||
|
||||
$availableCardsQueryString = "SELECT mc.id, mc.name, mc.title FROM main_cards mc
|
||||
WHERE id NOT IN ( '" . implode("', '", $assignedCardsID) . "' )
|
||||
AND status = 1 AND deleted IS NULL " . $cardCatFilter . " ORDER BY mc.id ASC";
|
||||
$availableCardsQuery = $this->db->query($availableCardsQueryString);
|
||||
$availableCards = $availableCardsQuery->result_array();
|
||||
|
||||
$result = ['assignedCards' => $assignedCards, 'availableCards' => $availableCards];
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function assignSurveyCard($params) {
|
||||
$cardID = $params['id'];
|
||||
$answersKey = $params['answersKey'];
|
||||
|
||||
$surveyData = [
|
||||
'answers_key' => $answersKey,
|
||||
'card_id' => $cardID
|
||||
];
|
||||
|
||||
return $this->db->insert('onboarding_survey_cards', $surveyData);
|
||||
}
|
||||
|
||||
public function unassignSurveyCard($params) {
|
||||
$this->db->where('answers_key', $params['answersKey']);
|
||||
$this->db->where('card_id', $params['id']);
|
||||
return $this->db->delete('onboarding_survey_cards');
|
||||
}
|
||||
|
||||
public function updateSurvey($id, $data) {
|
||||
$this->db->where('id', $id);
|
||||
$this->db->update('onboarding_survey', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Onesignal_model extends CI_Model {
|
||||
|
||||
|
||||
public function __constructor() {
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function sendmemberMessage($member_id, $player_id_array, $message, $arrayData) {
|
||||
$ic = 0;
|
||||
$player_id_string = "";
|
||||
// print_r($player_id_array);
|
||||
|
||||
if (is_array($player_id_array) && $message != "" && count($player_id_array) > 0 && is_array($arrayData)) {
|
||||
|
||||
|
||||
foreach ($player_id_array as $pl) {
|
||||
$sprt = "";
|
||||
if ($pl != '') {
|
||||
$player_id_array = array($pl);
|
||||
$result = $this->postOneSignal($player_id_array, $message, $arrayData);
|
||||
var_dump($result);
|
||||
}
|
||||
}
|
||||
// $player_id_array = $stack;
|
||||
// $player_id_array = array("fba1b598-0197-4ae6-b57b-0e19e671904d","1160d56c-d22b-4222-b072-af05be86787c");
|
||||
// echo $player_id_string;
|
||||
// print_r($arrayData);
|
||||
// print_r($player_id_array);
|
||||
// $result = $this->postOneSignal($player_id_array, $message, $arrayData);
|
||||
// var_dump($result);
|
||||
} else {
|
||||
echo "Invalid PLAYER_ID and/or MESSAGE!";
|
||||
}
|
||||
}
|
||||
|
||||
private function postOneSignal($player_id_array, $message, $arrayData) {
|
||||
global $savvyext;
|
||||
$url = $savvyext->cfgReadChar('onesignal.url');
|
||||
$app_id = $savvyext->cfgReadChar('onesignal.app_id');
|
||||
|
||||
$url = "https://onesignal.com/api/v1/notifications";
|
||||
$app_id = "e9a7bb38-0a27-4250-9fb7-9bd7871d7b63";
|
||||
|
||||
$data = [
|
||||
'app_id' => $app_id,
|
||||
'contents' => ['en' => $message],
|
||||
'headings' => ['en' => 'Float Activities'],
|
||||
'subtitle' => ['en' => 'Your account activities message from Float.'],
|
||||
'content_available' => true,
|
||||
'mutable_content' => true,
|
||||
'include_player_ids' => $player_id_array,
|
||||
'data' => $arrayData
|
||||
];
|
||||
$opts = array(
|
||||
'http' => array(
|
||||
'method' => "POST",
|
||||
'header' =>
|
||||
"Content-Type: application/json; charset=utf-8\r\n" .
|
||||
"Accept: application/json\r\n",
|
||||
'content' => json_encode($data)
|
||||
)
|
||||
);
|
||||
$context = stream_context_create($opts);
|
||||
$body = file_get_contents($url, false, $context);
|
||||
error_log($body);
|
||||
$result = json_decode($body, true);
|
||||
return $result;
|
||||
}
|
||||
|
||||
// 'subtitle' => ['en' => 'You\'ve got push from Float'],
|
||||
}
|
||||
@@ -0,0 +1,196 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ParsedEmailItem_model extends CI_Model
|
||||
{
|
||||
|
||||
public $id;
|
||||
public $travel_date;
|
||||
public $duration;
|
||||
public $cost_raw;
|
||||
public $trackedemail_item_id;
|
||||
public $cost;
|
||||
public $updated;
|
||||
public $distance;
|
||||
public $transport_provider_id;
|
||||
public $scheduled;
|
||||
public $travel_date_end;
|
||||
public $dup_id;
|
||||
public $location_start_id;
|
||||
public $location_end_id;
|
||||
public $private;
|
||||
|
||||
public function __contstruct()
|
||||
{
|
||||
parrent::__contstruct();
|
||||
}
|
||||
|
||||
public function ParsedEmailItem($item)
|
||||
{
|
||||
return [
|
||||
'id' => $item->id,
|
||||
'travel_date' => Carbon::parse($item->travel_date)->format('Y-m-d'),
|
||||
'travel_date_end' => Carbon::parse($item->travel_date_end)->format('Y-m-d'),
|
||||
'location_start_id' => $item->location_start_id,
|
||||
'location_end_id' => $item->location_end_id,
|
||||
'distance' => $item->distance,
|
||||
'cost' => $item->cost,
|
||||
'duration' => $item->duration,
|
||||
'cost_raw' => $item->cost_raw,
|
||||
'trackedemail_item_id' => $item->trackedemail_item_id,
|
||||
'transport_provider_id' => $item->transport_provider_id,
|
||||
];
|
||||
}
|
||||
|
||||
public function getParsedEmailItemList($params = [])
|
||||
{
|
||||
$res = SQEAPI::get('trip/api/trip/all', $params);
|
||||
|
||||
if (isset($res['error'])) {
|
||||
return ['success' => false, 'error' => $res['error']];
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($res['data'] as $trip) {
|
||||
$data[] = $this->ParsedEmailItem($trip);
|
||||
}
|
||||
|
||||
$itemTotal = isset($res['total']) ? $res['total'] : 0;
|
||||
$page = isset($res['page']) ? $res['page'] : 0;
|
||||
|
||||
return [
|
||||
'list' => $data,
|
||||
'itemTotal' => $itemTotal,
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
||||
public function getParsedEmailItem($id, $params = [])
|
||||
{
|
||||
$res = SQEAPI::get('trip/api/trip/' . $id, $params);
|
||||
|
||||
$data = $this->ParsedEmailItem($res['data']);
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function createParsedEmailItem($inputData)
|
||||
{
|
||||
return SQEAPI::post('trip/api/trip/new', $inputData);
|
||||
}
|
||||
|
||||
public function updateParsedEmailItem($id, $inputData)
|
||||
{
|
||||
// convert input array to query string format
|
||||
$data = http_build_query($inputData);
|
||||
|
||||
return SQEAPI::put('trip/api/trip/' . $id, $data);
|
||||
}
|
||||
|
||||
public function deleteParsedEmailItem($id)
|
||||
{
|
||||
return SQEAPI::delete("trip/api/trip/$id");
|
||||
}
|
||||
|
||||
public function getSureReportQuery($params = [])
|
||||
{
|
||||
$whereQuery = '';
|
||||
|
||||
if (!empty($params['travel_date'])) {
|
||||
// travel_date format: 2020-02-03 - 2020-03-01
|
||||
$fromToArray = explode(' - ', $params['travel_date']);
|
||||
$fromDate = $fromToArray[0];
|
||||
$toDate = $fromToArray[1];
|
||||
|
||||
$whereQuery .= " AND to_char(p.travel_date, 'YYYY-MM-DD') >= '" . pg_escape_string($fromDate) . "'
|
||||
AND to_char(p.travel_date, 'YYYY-MM-DD') <= '" . pg_escape_string($toDate) . "'";
|
||||
}
|
||||
|
||||
if (!empty($params['duration_from'])) {
|
||||
$whereQuery .= " AND p.duration >= " . pg_escape_string($params['duration_from']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['duration_to'])) {
|
||||
$whereQuery .= " AND p.duration <= " . pg_escape_string($params['duration_to']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['distance_from'])) {
|
||||
$whereQuery .= " AND p.distance >= " . pg_escape_string($params['distance_from']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['distance_to'])) {
|
||||
$whereQuery .= " AND p.distance <= " . pg_escape_string($params['distance_to']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['cost_from'])) {
|
||||
$whereQuery .= " AND p.cost >= " . pg_escape_string($params['cost_from']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['cost_to'])) {
|
||||
$whereQuery .= " AND p.cost <= " . pg_escape_string($params['cost_to']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['email'])) {
|
||||
// email format (comma separated): tet1@gmail.com, test2@gmail
|
||||
$emails = $params['email'];
|
||||
|
||||
// remove space
|
||||
$emails = preg_replace("/\s+/", '', $emails);
|
||||
|
||||
// remove empty value
|
||||
$emailArray = explode(',', $emails);
|
||||
$emailArray = array_filter($emailArray, function($v, $k) {
|
||||
return !empty($v);
|
||||
}, ARRAY_FILTER_USE_BOTH);
|
||||
|
||||
//convert to format: ('tet1@gmail.com', 'test2@gmail')
|
||||
$emails = implode("','", $emailArray);
|
||||
$emails = "('" . $emails . "')";
|
||||
|
||||
$whereQuery .= " AND m.email IN " . $emails . " ";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
p.id,
|
||||
m.id AS member_id,
|
||||
m.email,
|
||||
p.travel_date,
|
||||
p.duration,
|
||||
p.cost_raw,
|
||||
p.trackedemail_item_id,
|
||||
p.cost,
|
||||
p.updated,
|
||||
p.distance,
|
||||
CASE WHEN e.id IS NULL THEN
|
||||
'No'
|
||||
ELSE
|
||||
'Yes'
|
||||
END AS surge_price,
|
||||
CASE WHEN (f.id IS NOT NULL
|
||||
AND f.cost > f.average) THEN
|
||||
ROUND(f.average / f.cost, 2)
|
||||
ELSE
|
||||
0
|
||||
END AS cheaper_alternative,
|
||||
'<a class=\"showTripInsights\" onclick=\"showTripInsights('||t.member_id||','||p.trackedemail_item_id||', this);\" href=\"javascript:void(0);\">Insights</a>' AS Insights
|
||||
FROM
|
||||
parsedemail_item p
|
||||
LEFT JOIN trackedemail_item t ON t.id = p.trackedemail_item_id
|
||||
LEFT JOIN trip_surge_price e ON (e.data_source_id = p.id
|
||||
AND e.data_source = 1)
|
||||
LEFT JOIN trip_price_comparison f ON (f.data_source_id = p.id
|
||||
AND e.data_source = 1)
|
||||
LEFT JOIN members m ON m.id = t.member_id
|
||||
WHERE
|
||||
e.id IS NOT NULL " . $whereQuery . "
|
||||
ORDER BY
|
||||
t.id DESC
|
||||
";
|
||||
|
||||
return $query;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Parsed_item_payment_model extends CI_Model
|
||||
{
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function get_parsed_item_payment_record(
|
||||
$filters = [],
|
||||
$count_record = true,
|
||||
$limit = null,
|
||||
$offset = null) {
|
||||
|
||||
$string_array = [
|
||||
'category' => 'lower(tp.category)',
|
||||
'email' => 'm.email',
|
||||
];
|
||||
|
||||
$date_array = [
|
||||
'from_date' => 'DATE(receipt_datetime) >=',
|
||||
'to_date' => 'DATE(receipt_datetime) <=',
|
||||
];
|
||||
|
||||
$number_array = [
|
||||
'transport_provider_id' => 'transport_provider_id'
|
||||
];
|
||||
|
||||
if ($count_record) {
|
||||
|
||||
$this->read_replica->select([
|
||||
'count(*) AS all_count'
|
||||
]);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->select([
|
||||
'pit.member_id',
|
||||
'm.email',
|
||||
'tp.name',
|
||||
'pit.receipt_datetime',
|
||||
'pit.created',
|
||||
'pit.amount',
|
||||
'pit.amount_currency',
|
||||
'pit.transport_provider_id',
|
||||
'pit.trackedemail_item_id',
|
||||
'tp.category'
|
||||
]);
|
||||
$this->read_replica->order_by('pit.receipt_datetime','DESC');
|
||||
}
|
||||
|
||||
$this->read_replica
|
||||
->from('parsedemail_item_payment pit')
|
||||
->join('transport_providers tp', 'pit.transport_provider_id = tp.id', 'left')
|
||||
->join('members m', 'm.id = pit.member_id', 'left');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
if (array_key_exists($key, $date_array)) {
|
||||
|
||||
$this->read_replica->where($date_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
|
||||
$this->read_replica->like($string_array[$key], strtolower($val));
|
||||
|
||||
} else if (array_key_exists($key, $number_array)) {
|
||||
|
||||
$this->read_replica->where($number_array[$key], $val);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Phone_farm_phone_model extends CI_Model
|
||||
{
|
||||
public function __constructor()
|
||||
{
|
||||
parent::__constructor();
|
||||
}
|
||||
|
||||
public function phone_farm_phone($data)
|
||||
{
|
||||
return (array) $data;
|
||||
}
|
||||
|
||||
public function getPhones($params)
|
||||
{
|
||||
$res = AutomaticServerAPI::get('phone-farm-phones', $params);
|
||||
|
||||
if (isset($res['error'])) {
|
||||
return ['success' => false, 'error' => $res['error']];
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($res['data'] as $addr) {
|
||||
$data[] = $this->parse_phone($addr);
|
||||
}
|
||||
|
||||
$totalPage = isset($res['total']) ? $res['total'] : 0;
|
||||
$page = isset($res['page']) ? $res['page'] : 0;
|
||||
|
||||
return [
|
||||
'list' => $data,
|
||||
'totalItems' => $totalPage,
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
||||
public function getPhoneById($id) {
|
||||
$res = AutomaticServerAPI::get("phone-farm-phones/$id", NULL);
|
||||
$res['data'] = $this->parse_phone($res['data']);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function createPhone($params)
|
||||
{
|
||||
return AutomaticServerAPI::post('phone-farm-phones', $params);
|
||||
}
|
||||
|
||||
public function removePhoneById($phoneId)
|
||||
{
|
||||
return AutomaticServerAPI::delete("phone-farm-phones/$phoneId");
|
||||
}
|
||||
|
||||
public function updatePhoneById($phoneId, $params)
|
||||
{
|
||||
return AutomaticServerAPI::put("phone-farm-phones/$phoneId", $params);
|
||||
}
|
||||
|
||||
private function parse_phone($originData)
|
||||
{
|
||||
return $this->phone_farm_phone($originData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,197 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Point_model extends CI_Model {
|
||||
|
||||
public function __constructor() {
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function getSystemicPointsSummary()
|
||||
{
|
||||
$query_arr = [
|
||||
'last_24_hrs' => "AND m.id > 0 AND m.email != '' AND mp.added BETWEEN NOW() - INTERVAL '24 HOURS' AND NOW()",
|
||||
'last_7_days' => "AND m.id > 0 AND m.email != '' AND mp.added BETWEEN '" . date('Y-m-d', strtotime('-6 days')) . "' AND '" . date('Y-m-d') . "'",
|
||||
'last_14_days' => "AND m.id > 0 AND m.email != '' AND mp.added BETWEEN '" . date('Y-m-d', strtotime('-13 days')) . "' AND '" . date('Y-m-d') . "'",
|
||||
'last_30_days' => "AND m.id > 0 AND m.email != '' AND mp.added BETWEEN '" . date('Y-m-d', strtotime('-29 days')) . "' AND '" . date('Y-m-d') . "'",
|
||||
'all_time' => "",
|
||||
];
|
||||
|
||||
$countries = [];
|
||||
|
||||
foreach ($query_arr as $key => $value) {
|
||||
$sql = "SELECT COUNT(*) AS total_assigned_times,
|
||||
CASE WHEN m.country IS NULL THEN 'Unknown' ELSE m.country END AS location
|
||||
FROM members_points AS mp
|
||||
LEFT JOIN members AS m ON m.id = mp.member_id
|
||||
WHERE mp.points > 0 $value
|
||||
GROUP BY CASE WHEN m.country IS NULL THEN 'Unknown' ELSE m.country END
|
||||
ORDER BY total_assigned_times DESC";
|
||||
|
||||
$query = $this->db->query($sql);
|
||||
|
||||
$countries[$key] = $query->result_array();
|
||||
}
|
||||
|
||||
foreach ($countries['all_time'] as &$country) {
|
||||
foreach ($countries['last_30_days'] as $tempCountry) {
|
||||
if ($tempCountry['location'] === $country['location']) {
|
||||
$country['last_30_days'] = $tempCountry['total_assigned_times'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach ($countries['last_14_days'] as $tempCountry) {
|
||||
if ($tempCountry['location'] === $country['location']) {
|
||||
$country['last_14_days'] = $tempCountry['total_assigned_times'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach ($countries['last_7_days'] as $tempCountry) {
|
||||
if ($tempCountry['location'] === $country['location']) {
|
||||
$country['last_7_days'] = $tempCountry['total_assigned_times'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
foreach ($countries['last_24_hrs'] as $tempCountry) {
|
||||
if ($tempCountry['location'] === $country['location']) {
|
||||
$country['last_24_hrs'] = $tempCountry['total_assigned_times'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
$country['last_30_days'] = $country['last_30_days'] ?? 0;
|
||||
$country['last_14_days'] = $country['last_14_days'] ?? 0;
|
||||
$country['last_7_days'] = $country['last_7_days'] ?? 0;
|
||||
$country['last_24_hrs'] = $country['last_24_hrs'] ?? 0;
|
||||
}
|
||||
|
||||
return $countries['all_time'];
|
||||
}
|
||||
|
||||
public function getSystemicPointsDatatables($postData, $mode = 'search')
|
||||
{
|
||||
## Save param for CSV
|
||||
$this->load->library('session');
|
||||
$this->session->set_userdata("SPR_PARAM", $postData);
|
||||
## Read value
|
||||
; $from = DateTime::createFromFormat('m/d/Y', '1/1/1970');
|
||||
$to = (new DateTime());
|
||||
$date_range = $postData['date_range'] ?? '';
|
||||
if (!empty($date_range)) {
|
||||
$date_range_part = array_map('trim', explode('-', $date_range));
|
||||
$from = DateTime::createFromFormat('m/d/Y', $date_range_part[0]);
|
||||
$to = DateTime::createFromFormat('m/d/Y', $date_range_part[1]);
|
||||
}
|
||||
$draw = $postData['draw'] ?? 0;
|
||||
$start = $postData['start'];
|
||||
$rowperpage = $postData['length']; // Rows display per page
|
||||
$columnIndex = $postData['order'][0]['column'] ?? 0; // Column index
|
||||
$columnName = $postData['columns'][$columnIndex]['data'] ?? ''; // Column name
|
||||
$columnSortOrder = $postData['order'][0]['dir']; // asc or desc
|
||||
|
||||
$searchValue = $postData['email'] ?? ''; // Search value
|
||||
$pointKey = $postData['point_key'] ?? ''; // Point key
|
||||
$pointValue = $postData['point_value'] ?? ''; // Point key
|
||||
|
||||
$where = " m.id>0 AND m.email!='' AND mp.points > 0";
|
||||
$where .= " AND date(m.added) >='" . $from->format('Y-m-d') . "' and date(m.added)<='" . $to->format('Y-m-d') . "' ";
|
||||
|
||||
if (!empty($postData['country_filter'])) {
|
||||
if (strtolower($postData['country_filter']) === 'unknown') {
|
||||
$where .= " AND (m.country = '' or m.country IS NULL) ";
|
||||
} else {
|
||||
$where .= " AND m.country = '" . pg_escape_string($postData['country_filter']) . "' ";
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($searchValue)) {
|
||||
$searchStr = pg_escape_string($searchValue);
|
||||
$where .= " AND m.email ILIKE '%" . $searchStr . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($pointKey)) {
|
||||
$searchStr = pg_escape_string($pointKey);
|
||||
$where .= " AND mp.point_key = '" . $searchStr . "' ";
|
||||
}
|
||||
|
||||
if (!empty($pointValue)) {
|
||||
$searchStr = pg_escape_string($pointValue);
|
||||
$where .= " AND mp.points = '" . $searchStr . "' ";
|
||||
}
|
||||
|
||||
$map_order_by = [
|
||||
'allocation_date' => 'mp.added',
|
||||
'sign_up_date' => 'm.added',
|
||||
'country' => 'm.country',
|
||||
'member_id' => 'mp.member_id',
|
||||
];
|
||||
|
||||
if (isset($map_order_by[$columnName])) {
|
||||
$order_by = ' ORDER BY ' . $map_order_by[$columnName] . ' ' . $columnSortOrder;
|
||||
} else {
|
||||
$order_by = ' ORDER BY ' . $map_order_by['sign_up_date'] . ' DESC';
|
||||
}
|
||||
|
||||
$limit = $mode === 'search' ? " LIMIT $rowperpage OFFSET $start" : '';
|
||||
|
||||
$mysql = "SELECT
|
||||
to_char(mp.added, 'MM/DD/YYYY HH24:MI:SS') as allocation_date,
|
||||
to_char(m.added, 'MM/DD/YYYY HH24:MI:SS') as sign_up_date,
|
||||
CASE WHEN m.country IS NOT NULL THEN m.country ELSE 'Unknown' END as country,
|
||||
mp.member_id, m.email, mp.point_key, ps.name, mp.points
|
||||
FROM members_points mp
|
||||
INNER JOIN members m on m.id = mp.member_id INNER JOIN points_settings ps on ps.point_key = mp.point_key
|
||||
WHERE $where
|
||||
$order_by $limit";
|
||||
# Response Search or CSV
|
||||
if ($mode === 'export_csv') {
|
||||
$report = $this->db->query($mysql);
|
||||
$this->exportToCSV($report, 'systemic-points-report-' . date("Y-m-d") . '.csv');
|
||||
exit;
|
||||
}
|
||||
$report = $this->db->query($mysql)->result_array();
|
||||
$mysql_count = "SELECT COUNT(*)
|
||||
FROM members_points mp
|
||||
INNER JOIN members m on m.id = mp.member_id INNER JOIN points_settings ps on ps.point_key = mp.point_key
|
||||
WHERE $where;";
|
||||
$totalRecords = $this->db->query($mysql_count)->row_array()['count'];
|
||||
$totalRecordwithFilter = $totalRecords;
|
||||
$response = array(
|
||||
"draw" => intval($draw),
|
||||
"iTotalRecords" => $totalRecords,
|
||||
"iTotalDisplayRecords" => $totalRecordwithFilter,
|
||||
"aaData" => $report
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function exportToCSV($data, $file_name)
|
||||
{
|
||||
set_time_limit(0);
|
||||
header('Content-Type: application/vnd.ms-excel');
|
||||
header('Content-Disposition: attachment;filename='.$file_name);
|
||||
header('Cache-Control: max-age=0');
|
||||
if (ob_get_contents())
|
||||
ob_end_clean();
|
||||
$fp = fopen('php://output', 'w');
|
||||
$i = 0;
|
||||
while ($row = $data->unbuffered_row()) {
|
||||
// header
|
||||
if ($i == 0) {
|
||||
fputcsv($fp, array_keys((array)$row));
|
||||
}
|
||||
// records
|
||||
fputcsv($fp, (array)$row);
|
||||
$i++;
|
||||
}
|
||||
fclose($fp);
|
||||
exit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Quote_Estimate_model extends CI_Model
|
||||
{
|
||||
private $id;
|
||||
private $price;
|
||||
private $surge_price;
|
||||
private $trip_time;
|
||||
private $distance;
|
||||
private $is_holiday;
|
||||
private $day_of_week;
|
||||
private $weather_conditions;
|
||||
private $created_at;
|
||||
private $updated_at;
|
||||
|
||||
public function __constructor()
|
||||
{
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function QuoteEstimate()
|
||||
{
|
||||
$result = [
|
||||
'id' => 1,
|
||||
'price' => 50,
|
||||
'surge_price' => 33.57,
|
||||
'trip_time' => '3300',
|
||||
'distance' => 7900,
|
||||
'is_holiday' => true,
|
||||
'day_of_week' => 5,
|
||||
'weather_conditions' => [
|
||||
'temperature' => 30,
|
||||
'status' => 'cloudy',
|
||||
],
|
||||
'created_at' => '2019-10-07T03:29:14.676Z',
|
||||
'updated_at' => null,
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getQuoteEstimates()
|
||||
{
|
||||
$response = array();
|
||||
|
||||
// TODO: Get address items from sqeAPI
|
||||
for ($i = 0; $i < 30; $i++) {
|
||||
$response[] = $this->QuoteEstimate();
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Quote_model extends CI_Model
|
||||
{
|
||||
private $id;
|
||||
private $transport_provider_id;
|
||||
private $automation_id;
|
||||
private $cost_raw;
|
||||
private $cost;
|
||||
private $created;
|
||||
private $completed;
|
||||
private $member_id;
|
||||
private $location_start_id;
|
||||
private $location_end_id;
|
||||
private $quote_group_id;
|
||||
private $travel_date;
|
||||
|
||||
public function __constructor()
|
||||
{
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function Quote()
|
||||
{
|
||||
$result = [
|
||||
'id' => 1,
|
||||
'transport_provider_id' => 3,
|
||||
'automation_id' => 5,
|
||||
'cost_raw' => 70,
|
||||
'cost' => 100,
|
||||
'created' => '04-10-2019 10:44:22',
|
||||
'completed' => '04-10-2019 12:45:00',
|
||||
'member_id' => 12,
|
||||
'location_start_id' => 6,
|
||||
'location_end_id' => 10,
|
||||
'quote_group_id' => 25,
|
||||
'travel_date' => '04-10-2019 05:45:00',
|
||||
];
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function getQuotes()
|
||||
{
|
||||
$response = array();
|
||||
|
||||
// TODO: Get address items from sqeAPI
|
||||
for ($i = 0; $i < 30; $i++) {
|
||||
$response[] = $this->Quote();
|
||||
}
|
||||
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Receipt_advice_model extends CI_Model
|
||||
{
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function getAdviceQuery($params = [])
|
||||
{
|
||||
$whereQuery = '';
|
||||
|
||||
if (!empty($params['travel_date'])) {
|
||||
// travel_date format: 2020-02-03 - 2020-03-01
|
||||
$fromToArray = explode(' - ', $params['travel_date']);
|
||||
$fromDate = $fromToArray[0];
|
||||
$toDate = $fromToArray[1];
|
||||
|
||||
$whereQuery .= " AND (
|
||||
(to_char(a.travel_date, 'YYYY-MM-DD') >= '" . pg_escape_string($fromDate) . "'
|
||||
AND
|
||||
to_char(a.travel_date, 'YYYY-MM-DD') <= '" . pg_escape_string($toDate) . "'
|
||||
)
|
||||
OR
|
||||
(to_char(a.updated, 'YYYY-MM-DD') >= '" . pg_escape_string($fromDate) . "'
|
||||
AND
|
||||
to_char(a.updated, 'YYYY-MM-DD') <= '" . pg_escape_string($toDate) . "'
|
||||
)
|
||||
) ";
|
||||
}
|
||||
|
||||
if (!empty($params['duration_from'])) {
|
||||
$whereQuery .= " AND a.duration >= " . pg_escape_string($params['duration_from']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['duration_to'])) {
|
||||
$whereQuery .= " AND a.duration <= " . pg_escape_string($params['duration_to']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['distance_from'])) {
|
||||
$whereQuery .= " AND a.distance >= " . pg_escape_string($params['distance_from']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['distance_to'])) {
|
||||
$whereQuery .= " AND a.distance <= " . pg_escape_string($params['distance_to']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['location_start_id'])) {
|
||||
$whereQuery .= " AND a.location_start_id = " . pg_escape_string($params['location_start_id']) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['location_end_id'])) {
|
||||
$whereQuery .= " AND a.location_end_id = " . pg_escape_string($params['location_end_id']) . " ";
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT a.id,a.travel_date||'<br/>'||a.updated As \"Date/Updated\",a.duration,a.distance,
|
||||
b.address||'<br/>'||c.address as \"From and To\",
|
||||
'<input type=\"button\" class=\"btn btn-info btn-xs\" onclick=\"return viewAdvice('||a.id||');\" value=\"View\" />' AS \"View\"
|
||||
FROM parsedemail_item a
|
||||
LEFT JOIN address b ON b.id = a.location_start_id
|
||||
LEFT JOIN address c ON c.id = a.location_end_id
|
||||
WHERE a.transport_provider_id>0 AND a.dup_id IS NULL AND a.private='f' " . $whereQuery . " ORDER BY a.travel_date DESC
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function get_query_parsed_email_quote_records($filters, $count_record = true)
|
||||
{
|
||||
$combo_array = [];
|
||||
|
||||
$numeric_array = [
|
||||
'duration_from' => 'a.duration >=',
|
||||
'duration_to' => 'a.duration <=',
|
||||
'distance_from' => 'a.distance >=',
|
||||
'distance_to' => 'a.distance <=',
|
||||
'location_start_id' => 'a.location_start_id',
|
||||
'location_end_id' => 'a.location_end_id',
|
||||
];
|
||||
|
||||
$string_array = [];
|
||||
|
||||
$boolean_array = [];
|
||||
|
||||
if ($count_record) {
|
||||
|
||||
$this->read_replica->select([
|
||||
'count(*) AS all_count'
|
||||
]);
|
||||
} else {
|
||||
|
||||
$this->read_replica->select([
|
||||
'a.travel_date',
|
||||
'a.duration',
|
||||
'a.cost_raw',
|
||||
'a.cost',
|
||||
'a.updated',
|
||||
'a.distance',
|
||||
'a.transport_provider_id',
|
||||
'a.travel_date_end',
|
||||
'a.location_start_id',
|
||||
'a.location_end_id',
|
||||
'b.address AS location_start_address',
|
||||
'b.latitude AS location_start_lat',
|
||||
'b.longitude AS location_start_lng',
|
||||
'b.postal AS location_start_postal',
|
||||
'b.country AS location_start_country',
|
||||
'b.description AS location_start_description',
|
||||
'd.timezone AS location_start_tz',
|
||||
'c.address AS location_end_address',
|
||||
'c.latitude AS location_end_lat',
|
||||
'c.longitude AS location_end_lng',
|
||||
'c.postal AS location_end_postal',
|
||||
'c.country AS location_end_country',
|
||||
'c.description AS location_end_description',
|
||||
'e.timezone AS location_end_tz'
|
||||
]);
|
||||
}
|
||||
|
||||
$this->read_replica->from('parsedemail_item a');
|
||||
$this->read_replica->join('address b', 'b.id=a.location_start_id', 'LEFT');
|
||||
$this->read_replica->join('address c', 'c.id=a.location_end_id', 'LEFT');
|
||||
$this->read_replica->join('address_timezone d', 'b.timezone=d.id', 'LEFT');
|
||||
$this->read_replica->join('address_timezone e', 'c.timezone=e.id', 'LEFT');
|
||||
|
||||
$this->read_replica->where('a.transport_provider_id>0');
|
||||
$this->read_replica->where('a.dup_id IS NULL');
|
||||
$this->read_replica->where('a.private', 'f');
|
||||
|
||||
foreach ($filters as $key => $val) {
|
||||
|
||||
if ($key === 'travel_date') {
|
||||
|
||||
$fromToArray = explode(' - ', $val);
|
||||
$this->read_replica->group_start()
|
||||
->group_start()
|
||||
->where('DATE(a.travel_date) >=', $fromToArray[0]) // start date
|
||||
->where('DATE(a.travel_date) <=', $fromToArray[1]) // end date
|
||||
->group_end()
|
||||
->or_group_start()
|
||||
->where('DATE(a.updated) >=', $fromToArray[0]) // start date
|
||||
->where('DATE(a.updated) <=', $fromToArray[1]) // end date
|
||||
->group_end()
|
||||
->group_end();
|
||||
} else if ($key === 'location_start_ids') {
|
||||
|
||||
$this->read_replica->where_in('a.location_start_id', $val);
|
||||
} else if ($key === 'location_end_ids') {
|
||||
|
||||
$this->read_replica->where_in('a.location_end_id', $val);
|
||||
} else if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
} else if (array_key_exists($key, $numeric_array)) {
|
||||
|
||||
$this->read_replica->where($numeric_array[$key], $val);
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
} else if (array_key_exists($key, $boolean_array)) {
|
||||
|
||||
$this->read_replica->where($boolean_array[$key], $val);
|
||||
}
|
||||
}
|
||||
|
||||
if ($count_record === false) {
|
||||
|
||||
$this->read_replica->order_by('a.travel_date DESC');
|
||||
}
|
||||
|
||||
return $this->read_replica->get_compiled_select();
|
||||
}
|
||||
|
||||
public function count_parsedemail_item_record()
|
||||
{
|
||||
return $this->read_replica->select(['count(id) AS all_count'])
|
||||
->from('parsedemail_item')
|
||||
->get()
|
||||
->result_array()[0]['all_count'];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,309 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Report_model extends CI_Model
|
||||
{
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getPriceComparisonTrend(array $params)
|
||||
{
|
||||
$errors = [];
|
||||
$whereQuery = ' ';
|
||||
|
||||
if (!empty($params['start_date']) && !empty($params['end_date'])) {
|
||||
$whereQuery .= " AND to_char(a.travel_date, 'YYYY-MM-DD') >= '" . pg_escape_string($params['start_date']) . "'
|
||||
AND to_char(a.travel_date, 'YYYY-MM-DD') <= '" . pg_escape_string($params['end_date']) . "' ";
|
||||
} else {
|
||||
$errors[] = 'Start date, end date are required.';
|
||||
}
|
||||
|
||||
if (!empty($params['transport_providers'])) {
|
||||
$transport_providers = '(' . implode(',', $params['transport_providers']) . ')';
|
||||
$whereQuery .= " AND CASE WHEN a.data_source = 1 THEN
|
||||
parsedemail_item.transport_provider_id IN $transport_providers
|
||||
WHEN a.data_source = 2 THEN
|
||||
quotes.transport_provider_id IN $transport_providers
|
||||
END ";
|
||||
} else {
|
||||
$errors[] = 'Transport provider is required.';
|
||||
}
|
||||
|
||||
if (!empty($errors)) {
|
||||
return [
|
||||
'success' => false,
|
||||
'message' => $errors[0]
|
||||
];
|
||||
}
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
*,
|
||||
count(*) as count
|
||||
FROM (
|
||||
SELECT
|
||||
a.cost,
|
||||
to_char(a.travel_date, 'YYYY-MM-DD') AS travel_date,
|
||||
CASE WHEN a.data_source = 1 THEN
|
||||
parsedemail_item.transport_provider_id
|
||||
WHEN a.data_source = 2 THEN
|
||||
quotes.transport_provider_id
|
||||
END AS transport_provider_id
|
||||
FROM
|
||||
union_trip_and_quote_view_table AS a
|
||||
LEFT JOIN parsedemail_item ON parsedemail_item.id = a.data_source_id
|
||||
AND a.data_source = 1
|
||||
LEFT JOIN quotes ON quotes.id = a.data_source_id
|
||||
AND a.data_source = 2
|
||||
WHERE
|
||||
a.travel_date IS NOT NULL
|
||||
" . $whereQuery . "
|
||||
) AS sub
|
||||
GROUP BY
|
||||
transport_provider_id,
|
||||
travel_date,
|
||||
cost
|
||||
ORDER BY
|
||||
travel_date ASC
|
||||
";
|
||||
|
||||
$query = $this->read_replica->query($query);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'data' => $query->result_array()
|
||||
];
|
||||
}
|
||||
|
||||
public function area_to_area($area1, $area2, $date1, $date2, $t, $c = '#FF0000')
|
||||
{
|
||||
global $pgconn;
|
||||
$data = [];
|
||||
$q = "SELECT * FROM geofence_area WHERE id=${area1}";
|
||||
$query = $this->read_replica->query($q);
|
||||
$area1i = $query->result_array();
|
||||
$boundaries = json_decode($area1i[0]["boundaries"], true);
|
||||
$polygonCoords = [];
|
||||
|
||||
foreach ($boundaries["polygon"] as $coord) {
|
||||
$polygonCoords[] = "$coord[0] $coord[1]";
|
||||
}
|
||||
$polygonCoordsString1 = implode(",", $polygonCoords);
|
||||
|
||||
$q = "SELECT * FROM geofence_area WHERE id=${area2}";
|
||||
$query = $this->read_replica->query($q);
|
||||
$area2i = $query->result_array();
|
||||
|
||||
$boundaries = json_decode($area2i[0]["boundaries"], true);
|
||||
$polygonCoords = [];
|
||||
foreach ($boundaries["polygon"] as $coord) {
|
||||
$polygonCoords[] = "$coord[0] $coord[1]";
|
||||
}
|
||||
$polygonCoordsString2 = implode(",", $polygonCoords);
|
||||
|
||||
$q = "SELECT a.travel_date,a.cost";
|
||||
$q .= ",b.latitude AS location_start_lat,b.longitude AS location_start_lng";
|
||||
$q .= ",c.latitude AS location_end_lat,c.longitude AS location_end_lng";
|
||||
$q .= " FROM quotes a, address b, address c";
|
||||
$q .= " WHERE a.cost>0 AND a.transport_provider_id=${t}";
|
||||
$q .= " AND b.id=a.location_start_id AND c.id=a.location_end_id";
|
||||
$q .= " AND a.travel_date>'${date1} 00:00' AND a.travel_date<'${date2} 23:59'";
|
||||
$q .= " AND ST_Contains(ST_GeomFromText('POLYGON((${polygonCoordsString1}))', 4326), b.geometry::geometry)";
|
||||
$q .= " AND ST_Contains(ST_GeomFromText('POLYGON((${polygonCoordsString2}))', 4326), c.geometry::geometry)";
|
||||
$q .= " ORDER BY a.travel_date";
|
||||
|
||||
|
||||
$query = $this->read_replica->query($q);
|
||||
foreach ($query->result_array() as $f) {
|
||||
$f['origin'] = $area1i[0]['name'];
|
||||
$f['destination'] = $area2i[0]['name'];
|
||||
$f['c'] = $c;
|
||||
$f['time'] = strtotime($f['travel_date']);
|
||||
$data[] = $f;
|
||||
}
|
||||
return [$data, $area1i[0]["name"] . " to " . $area2i[0]["name"], $boundaries["polygon"]];
|
||||
}
|
||||
|
||||
public function getEmailAndBankConnectionReportSummary()
|
||||
{
|
||||
$sql = "SELECT COUNT(*) AS total_account,
|
||||
CASE WHEN members.country IS NULL OR members.country='' THEN 'unknown' ELSE members.country END AS location
|
||||
FROM members
|
||||
WHERE members.id>0 AND members.email != '' AND members.email IS NOT NULL
|
||||
GROUP BY CASE WHEN members.country IS NULL OR members.country='' THEN 'unknown' ELSE members.country END
|
||||
ORDER BY total_account DESC";
|
||||
$countries = $this->read_replica->query($sql)->result_array();
|
||||
foreach ($countries as &$country) {
|
||||
// get Bank Connection Report
|
||||
if ($country['location'] !== 'unknown') {
|
||||
$bank_where = "members.country='" . pg_escape_string($country['location']) . "'";
|
||||
$email_where = "mb.country='" . pg_escape_string($country['location']) . "'";
|
||||
} else {
|
||||
$bank_where = "(members.country IS NULL OR members.country='')";
|
||||
$email_where = "(mb.country IS NULL OR mb.country='')";
|
||||
}
|
||||
// active bank connection
|
||||
$sql = "SELECT count(*) as active_bank_connection FROM members
|
||||
WHERE id>0 AND email!='' AND email IS NOT NULL
|
||||
AND EXISTS(SELECT * from members_bank_accounts where bank_login_status = 'active' and member_id = members.id) and $bank_where";
|
||||
$country['active_bank_connection'] = $this->read_replica->query($sql)->row()->active_bank_connection;
|
||||
|
||||
// inactive bank connection
|
||||
$sql = "SELECT count(*) as inactive_bank_connection FROM members
|
||||
WHERE id>0 AND email!='' AND email IS NOT NULL
|
||||
AND NOT EXISTS (SELECT * from members_bank_accounts where bank_login_status = 'active' and member_id = members.id)
|
||||
AND EXISTS(SELECT * from members_bank_accounts where bank_login_status = 'inactive' and member_id = members.id)
|
||||
and $bank_where";
|
||||
|
||||
$country['inactive_bank_connection'] = $this->read_replica->query($sql)->row()->inactive_bank_connection;
|
||||
|
||||
// active email connection
|
||||
$sql = "SELECT COUNT (*) as total FROM members AS mb
|
||||
WHERE EXISTS (SELECT*FROM oauth2_tokens WHERE member_id=mb.ID AND expires_in>=CURRENT_TIMESTAMP AND email !='' AND email IS NOT NULL)
|
||||
AND mb.email !='' AND mb.email IS NOT NULL AND mb.ID> 0 AND $email_where;";
|
||||
$country['active_email_connection'] = $this->read_replica->query($sql)->row()->total;
|
||||
|
||||
//inactive email connection
|
||||
$country['inactive_email_connection'] = (int)$country['total_account'] - (int)$country['active_email_connection'];
|
||||
$country['no_bank_connected'] = (int)$country['total_account'] - (int)$country['active_bank_connection'] - (int)$country['inactive_bank_connection'];
|
||||
}
|
||||
return $countries;
|
||||
}
|
||||
|
||||
public function getEmailBankConnectionReportDatatables($postData, $mode = 'search')
|
||||
{
|
||||
## Save param for CSV
|
||||
$this->load->library('session');
|
||||
$this->session->set_userdata("EBCRR_PARAM", $postData);
|
||||
## Read value
|
||||
$from = DateTime::createFromFormat('m/d/Y', '1/1/1970');
|
||||
$to = (new DateTime());
|
||||
$date_range = $postData['date_range'] ?? '';
|
||||
if (!empty($date_range)) {
|
||||
$date_range_part = array_map('trim', explode('-', $date_range));
|
||||
$from = DateTime::createFromFormat('m/d/Y', $date_range_part[0]);
|
||||
$to = DateTime::createFromFormat('m/d/Y', $date_range_part[1]);
|
||||
}
|
||||
$draw = $postData['draw'] ?? 0;
|
||||
$start = $postData['start'];
|
||||
$rowperpage = $postData['length']; // Rows display per page
|
||||
$columnIndex = $postData['order'][0]['column'] ?? 0; // Column index
|
||||
$columnName = $postData['columns'][$columnIndex]['data'] ?? ''; // Column name
|
||||
$columnSortOrder = $postData['order'][0]['dir']; // asc or desc
|
||||
|
||||
$searchValue = $postData['email_search']??'';//['value'] ?? ''; // Search value
|
||||
$where = " members.id>0 AND members.email!='' AND members.email IS NOT NULL ";
|
||||
$where .= " AND date(members.added) >='" . $from->format('Y-m-d') . "' and date(members.added)<='" . $to->format('Y-m-d') . "' ";
|
||||
if (!empty($postData['country_filter'])) {
|
||||
if ($postData['country_filter'] == 'unknown') {
|
||||
$where .= " AND (members.country = '' or members.country IS NULL) ";
|
||||
} else {
|
||||
$where .= " AND members.country = '" . pg_escape_string($postData['country_filter']) . "' ";
|
||||
}
|
||||
}
|
||||
// bank connection filter
|
||||
if (!empty($postData['bank_connection_status'])) {
|
||||
if ($postData['bank_connection_status'] == 'active') {
|
||||
$where .= " AND EXISTS (SELECT * FROM members_bank_accounts WHERE member_id = members.id AND bank_login_status = 'active')";
|
||||
} else if ($postData['bank_connection_status'] == 'inactive') {
|
||||
$where .= " AND NOT EXISTS (SELECT * FROM members_bank_accounts WHERE member_id = members.id AND bank_login_status = 'active') ";
|
||||
$where .= " AND EXISTS (SELECT * FROM members_bank_accounts WHERE member_id = members.id AND bank_login_status = 'inactive') ";
|
||||
}
|
||||
}
|
||||
// email connection filter
|
||||
if (!empty($postData['email_connection_status'])) {
|
||||
if ($postData['email_connection_status'] == 'active') {
|
||||
$where .= " AND EXISTS (SELECT ot.email FROM oauth2_tokens AS ot WHERE ot.member_id = members.id AND ot.expires_in IS NOT NULL AND ot.expires_in>=CURRENT_TIMESTAMP
|
||||
ORDER BY ot.expires_in DESC LIMIT 1 )";
|
||||
} else if($postData['email_connection_status'] == 'inactive'){
|
||||
$where .= " AND NOT EXISTS (SELECT ot.email FROM oauth2_tokens AS ot WHERE ot.member_id = members.id AND ot.expires_in IS NOT NULL AND ot.expires_in>=CURRENT_TIMESTAMP
|
||||
ORDER BY ot.expires_in DESC LIMIT 1 )";
|
||||
}
|
||||
}
|
||||
if (!empty($searchValue)) {
|
||||
$searchStr = pg_escape_string($searchValue);
|
||||
$where .= " AND members.email ILIKE '%" . $searchStr . "%' ";
|
||||
}
|
||||
|
||||
$map_order_by = [
|
||||
'sign_up_date' => 'members.added',
|
||||
'location' => 'members.country',
|
||||
'user_id' => 'members.id',
|
||||
];
|
||||
if (isset($map_order_by[$columnName])) {
|
||||
$order_by = ' ORDER BY ' . $map_order_by[$columnName] . ' ' . $columnSortOrder;
|
||||
} else {
|
||||
$order_by = ' ORDER BY ' . $map_order_by['sign_up_date'] . ' DESC';
|
||||
}
|
||||
|
||||
$limit = $mode === 'search' ? " LIMIT $rowperpage OFFSET $start" : '';
|
||||
|
||||
$mysql = "SELECT
|
||||
to_char(members.added, 'MM/DD/YYYY HH24:MI:SS') AS sign_up_date,
|
||||
(CASE WHEN members.country IS NULL THEN 'unknown' ELSE members.country END) AS location,
|
||||
members.id AS user_id,
|
||||
members.email AS user_email,
|
||||
CASE WHEN (SELECT COUNT ( * ) FROM members_bank_accounts WHERE member_id = members.id AND bank_login_status = 'active')>0 THEN 'active' ELSE 'inactive' END AS bank_connection,
|
||||
CASE WHEN (
|
||||
SELECT ot.email FROM oauth2_tokens AS ot WHERE ot.member_id = members.id AND ot.expires_in IS NOT NULL AND ot.expires_in>=CURRENT_TIMESTAMP
|
||||
ORDER BY ot.expires_in DESC LIMIT 1
|
||||
) IS NOT NULL THEN 'active' ELSE 'inactive' END AS email_connection
|
||||
FROM members
|
||||
WHERE $where
|
||||
$order_by $limit";
|
||||
|
||||
# Response Search or CSV
|
||||
if ($mode === 'export_csv') {
|
||||
$report = $this->read_replica->query($mysql);
|
||||
$this->exportToCSV($report, 'email-bank-connection-report-' . date("Y-m-d") . '.csv');
|
||||
exit;
|
||||
}
|
||||
$report = $this->read_replica->query($mysql)->result_array();
|
||||
$mysql_count = "SELECT COUNT(*) FROM members WHERE $where;";
|
||||
$totalRecords = $this->read_replica->query($mysql_count)->row_array()['count'];
|
||||
$totalRecordwithFilter = $totalRecords;
|
||||
$response = array(
|
||||
"draw" => intval($draw),
|
||||
"iTotalRecords" => $totalRecords,
|
||||
"iTotalDisplayRecords" => $totalRecordwithFilter,
|
||||
"aaData" => $report
|
||||
);
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function exportToCSV($data, $file_name)
|
||||
{
|
||||
set_time_limit(0);
|
||||
header('Content-Type: application/vnd.ms-excel');
|
||||
header('Content-Disposition: attachment;filename='.$file_name);
|
||||
header('Cache-Control: max-age=0');
|
||||
if (ob_get_contents())
|
||||
ob_end_clean();
|
||||
$fp = fopen('php://output', 'w');
|
||||
$i = 0;
|
||||
while ($row = $data->unbuffered_row()) {
|
||||
// header
|
||||
if ($i == 0) {
|
||||
fputcsv($fp, array_keys((array)$row));
|
||||
}
|
||||
// records
|
||||
fputcsv($fp, (array)$row);
|
||||
$i++;
|
||||
}
|
||||
fclose($fp);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function getBankAccountDetail($member_id = 0)
|
||||
{
|
||||
$sql = "SELECT * FROM members_bank_accounts WHERE member_id= " . $member_id;
|
||||
$result = $this->read_replica->query($sql)->result_array();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Report_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_report_point_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
$combo_array = [
|
||||
'status' => 'r.status'
|
||||
];
|
||||
|
||||
$numeric_array = [
|
||||
'member_id' => 'r.member_id',
|
||||
'id' => 'm.id',
|
||||
'from_points' => 'r.points >=',
|
||||
'to_points' => 'r.points <='
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'description' => 'a.description'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'm.firstname',
|
||||
'm.lastname',
|
||||
'm.id',
|
||||
'a.description',
|
||||
'r.points',
|
||||
'r.added',
|
||||
'r.status'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('members_points_redeem r');
|
||||
$this->read_replica->join('points_redeem_avialable a', 'a.key=r.redeem_key', 'left');
|
||||
$this->read_replica->join('members m', 'm.id = r.member_id', 'left');
|
||||
|
||||
$this->read_replica->where('r.status > 0');
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$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(r.added) >=', $val);
|
||||
|
||||
} else if (strpos($key, 'to') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(r.added) <=', $val);
|
||||
|
||||
} else {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('r.added DESC');
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Resetpassword_model extends CI_Model {
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function get_resetpassword_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
|
||||
$combo_array = [
|
||||
'status'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'*'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('resetpassword');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
$key = $key === 'loc' ? "TEXT($key)" : $key;
|
||||
|
||||
if (in_array($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($key, $val);
|
||||
|
||||
} else if ($key === 'member_id') {
|
||||
|
||||
$this->read_replica->where($key, $val);
|
||||
|
||||
} else if (strpos($key, 'from') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(created) >=', $val);
|
||||
|
||||
} else if (strpos($key, 'to') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(created) <=', $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();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class screen_cards_model extends CI_Model
|
||||
{
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getQueryAll()
|
||||
{
|
||||
$query = "SELECT id, screen_name, trigger_id,
|
||||
'<div class=\"onoffswitch\">
|
||||
<input type=\"checkbox\" name=\"onoffswitch_'||id||'\" class=\"onoffswitch-checkbox\"
|
||||
onchange=\"fnToggle('||id||', '||status||');\"
|
||||
id=\"myonoffswitch_'||id||'\"'|| CASE WHEN status = 1 THEN 'checked' ELSE '' END || '>
|
||||
<label class=\"onoffswitch-label\" for=\"myonoffswitch_'||id||'\">
|
||||
<span class=\"onoffswitch-inner\"></span>
|
||||
<span class=\"onoffswitch-switch\"></span>
|
||||
</label>
|
||||
</div>'
|
||||
as status,
|
||||
'<a class=\"btn btn-primary\" href=\"javascript:void(0);\" onclick=\"fnShowEdit('||id||')\">Edit</a>' ||
|
||||
'<a class=\"btn btn-danger\" href=\"javascript:void(0);\" onclick=\"fnDelete('||id||')\">Delete</a>'
|
||||
as action
|
||||
FROM screen_cards ORDER By id asc";
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function getById($id)
|
||||
{
|
||||
$this->read_replica->select('id, screen_name, trigger_id, status');
|
||||
$this->read_replica->from('screen_cards');
|
||||
$this->read_replica->where('id', $id);
|
||||
$this->read_replica->order_by('id', 'asc');
|
||||
return $this->read_replica->get()->row();
|
||||
}
|
||||
|
||||
public function toggle($id, $cur_status)
|
||||
{
|
||||
//1. check
|
||||
$this->read_replica->select('status');
|
||||
$this->read_replica->from('screen_cards');
|
||||
$this->read_replica->where('id', $id);
|
||||
$db_status = $this->read_replica->get()->row('status');
|
||||
$this->read_replica->reset_query();
|
||||
//2. update
|
||||
$new_status = $db_status == 1 ? 0 : 1;
|
||||
$data = array(
|
||||
'status' => $new_status,
|
||||
);
|
||||
$this->db->where('id', $id);
|
||||
$rs = $this->db->update('screen_cards', $data);
|
||||
return $rs;
|
||||
}
|
||||
|
||||
public function create_or_update($data)
|
||||
{
|
||||
$is_exists = $this->is_exists($data['id'], $data['screen_name'], $data['trigger_id']);
|
||||
if($is_exists){
|
||||
return false;
|
||||
}
|
||||
if (empty($data['id'])) {
|
||||
$data = array(
|
||||
'screen_name' => $data['screen_name'],
|
||||
'trigger_id' => $data['trigger_id'],
|
||||
'status' => isset($data['status']) && $data['status'] == 1 ? 1 : 0,
|
||||
);
|
||||
$rs = $this->db->insert('screen_cards', $data);
|
||||
} else {
|
||||
$this->db->set('screen_name', $data['screen_name']);
|
||||
$this->db->set('trigger_id', $data['trigger_id']);
|
||||
$this->db->set('status', isset($data['status']) && $data['status'] == 1 ? 1 : 0);
|
||||
$this->db->where('id', $data['id']);
|
||||
$rs = $this->db->update('screen_cards');
|
||||
}
|
||||
return $rs;
|
||||
}
|
||||
|
||||
public function delete($id)
|
||||
{
|
||||
$rs = $this->db->delete('screen_cards', array('id' => $id));
|
||||
return $rs;
|
||||
}
|
||||
public function is_exists($id, $screen_name, $trigger_id){
|
||||
if(!empty($id)){
|
||||
$query = $this->read_replica->query('SELECT EXISTS(SELECT * FROM screen_cards WHERE id != ? AND screen_name = ? AND trigger_id = ?) AS check;', [$id, $screen_name, $trigger_id]);
|
||||
}else{
|
||||
$query = $this->read_replica->query('SELECT EXISTS(SELECT * FROM screen_cards WHERE screen_name = ? AND trigger_id = ?) AS check;', [$screen_name, $trigger_id]);
|
||||
}
|
||||
$rs = (array)$query->row();
|
||||
return $rs['check'] == 't';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Subscription_model extends CI_Model
|
||||
{
|
||||
|
||||
private $read_replica;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
public function get_subscription_report_records(
|
||||
$filters = [], $limit = null, $offset = null
|
||||
)
|
||||
{
|
||||
|
||||
$number_array = [
|
||||
'reciept_count' => 's.reciept_count',
|
||||
];
|
||||
if(!empty($filters['id'])){
|
||||
$number_array['id'] = 'me.id';
|
||||
}
|
||||
|
||||
$date_array = [
|
||||
'from_date' => 'DATE(s.subscribe) >=',
|
||||
'to_date' => 'DATE(s.subscribe) <=',
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'title' => 'm.title',
|
||||
'email' => 'me.email'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'me.id',
|
||||
'\'<a href =/member/viewLocateMember?member_id=\'||me.id||\'>\'||me.firstname||\'</a>\'',
|
||||
'me.lastname',
|
||||
'm.title',
|
||||
's.subscribe',
|
||||
's.status',
|
||||
'm.id AS card_id',
|
||||
'tp.name',
|
||||
's.reciept_count',
|
||||
'CASE WHEN s.reciept_count > 0 THEN \'Yes\' ELSE \'No\' END AS ReadySatus',
|
||||
'\'<button type="button" id="subb\'||s.id||\'"
|
||||
onclick="processSubscription(\'||s.id||\');"
|
||||
class="btn btn-danger"> Process</button>\' AS proc1',
|
||||
's.completed'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('members_card_assign s');
|
||||
$this->read_replica->join('main_cards m', 'm.id = s.card_id', 'left');
|
||||
$this->read_replica->join('members me', 'me.id = s.member_id', 'left');
|
||||
$this->read_replica->join('transport_providers tp', 'CAST(tp.id AS text) = m.card_reciept', 'left');
|
||||
|
||||
$this->read_replica->where('s.subscribe IS NOT NULL');
|
||||
$this->read_replica->where_in('m.button1_action', ['GOOFFERS']);
|
||||
|
||||
if(!empty($filters['card_receipts'])){
|
||||
$this->read_replica->like('LOWER(tp.name)', strtolower($filters['card_receipts']));
|
||||
}
|
||||
foreach ($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $number_array)) {
|
||||
|
||||
$this->read_replica->where($number_array[$key], $val);
|
||||
} else if (array_key_exists($key, $date_array)) {
|
||||
|
||||
$this->read_replica->where($date_array[$key], $val);
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
}
|
||||
}
|
||||
// ready filter
|
||||
if (!empty($filters['ready'])) {
|
||||
$ready_filter_val = @intval($filters['ready']);
|
||||
if ($ready_filter_val === 1) {
|
||||
$this->read_replica->where('s.reciept_count > 0');
|
||||
} elseif ($ready_filter_val === 0) {
|
||||
$this->read_replica->where('(s.reciept_count = 0 OR s.reciept_count IS NULL)');
|
||||
}
|
||||
}
|
||||
// completed filter
|
||||
if (isset($filters['completed'])) {
|
||||
if ($filters['completed'] == 1) { //complete
|
||||
$this->read_replica->where('s.completed IS NOT NULL');
|
||||
} elseif ($filters['completed'] == 0) { //pending
|
||||
$this->read_replica->where('s.completed IS NULL');
|
||||
}
|
||||
}
|
||||
|
||||
// get only active subscription deals
|
||||
$this->read_replica->where('m.status', 1);
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
$this->read_replica->order_by('subscribe DESC');
|
||||
}
|
||||
|
||||
$result = $this->read_replica->get()->result_array();
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
/**
|
||||
* Summary Report Model
|
||||
*/
|
||||
class Summary_report_model extends CI_Model {
|
||||
|
||||
protected $table = 'subscription_summary';
|
||||
|
||||
// read only database
|
||||
private $read_replica;
|
||||
|
||||
function __construct() {
|
||||
parent::__construct();
|
||||
$this->read_replica = $this->load->database('savvy_replica', TRUE);
|
||||
}
|
||||
|
||||
/**
|
||||
* get summary report from worker
|
||||
* @return array
|
||||
*/
|
||||
public function getSummaryReport( $params = array(), $limit = 0, $offset = 0 ) {
|
||||
try {
|
||||
$this->read_replica->select( '
|
||||
mc.id as cardid,
|
||||
mc.name as cardname,
|
||||
sr.country as location,
|
||||
(mc.card_points*50) as points,
|
||||
sr.last_24hours as last_24hours,
|
||||
sr.last_7days as last_7days,
|
||||
sr.last_14days as last_14days,
|
||||
sr.last_30days as last_30days,
|
||||
sr.total_sub as total_sub,
|
||||
sr.total_redeem as total_redeem
|
||||
' );
|
||||
$this->read_replica->from( sprintf( '%s sr', $this->table ) );
|
||||
$this->read_replica->join( 'main_cards mc', 'mc.id = sr.card_id' );
|
||||
// condition
|
||||
if ( isset( $params['card_id'] ) and !empty( $params['card_id'] ) ) {
|
||||
$this->read_replica->where( 'mc.id', $params['card_id'] );
|
||||
}
|
||||
|
||||
if ( isset( $params['name'] ) and !empty( $params['name'] ) ) {
|
||||
$this->read_replica->like( 'lower(mc.name)', strtolower( $params['name'] ) );
|
||||
}
|
||||
|
||||
if ( isset( $params['location'] ) and !empty( $params['location'] ) ) {
|
||||
$this->read_replica->like( 'lower(sr.country)', strtolower( $params['location'] ) );
|
||||
}
|
||||
|
||||
if ( isset( $params['points'] ) and !empty( $params['points'] ) ) {
|
||||
$this->read_replica->where( '(mc.card_points*50)', $params['points'] );
|
||||
}
|
||||
|
||||
if ( $limit ) {
|
||||
$this->read_replica->limit( $limit, $offset );
|
||||
}
|
||||
|
||||
$this->read_replica->order_by( 'last_7days', 'desc' );
|
||||
$results = $this->read_replica->get()->result_array();
|
||||
|
||||
return $results;
|
||||
} catch (Exception $e) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Survey_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_survey_report_records(
|
||||
$filters = [],
|
||||
$limit = null,
|
||||
$offset = null
|
||||
) {
|
||||
|
||||
$combo_array = [
|
||||
'status' => 'ms.status'
|
||||
];
|
||||
|
||||
$numberic_array = [
|
||||
'member_id' => 'ms.member_id'
|
||||
];
|
||||
|
||||
$string_array = [
|
||||
'description' => 'm.title',
|
||||
'answer' => 'ms.answer',
|
||||
'action' => 'm.button1_action'
|
||||
];
|
||||
|
||||
$this->read_replica->select([
|
||||
'ms.id||\':\'||ms.member_id AS id',
|
||||
'\'<a href =/member/viewLocateMember?member_id=\'||ms.member_id||\'>\'||me.firstname||\'</a>\'',
|
||||
'me.lastname',
|
||||
'm.title',
|
||||
'ms.answer',
|
||||
'CASE WHEN ms.status = 1 THEN \'Active\' ELSE \'Deleted\' END AS status',
|
||||
'me.added',
|
||||
'm.button1_action'
|
||||
]);
|
||||
|
||||
$this->read_replica->from('members_survey ms');
|
||||
$this->read_replica->join('main_cards m', 'm.id = ms.card_id', 'left');
|
||||
$this->read_replica->join('members me', 'me.id = ms.member_id', 'left');
|
||||
|
||||
foreach($filters as $key => $val) {
|
||||
|
||||
if (array_key_exists($key, $combo_array)) {
|
||||
|
||||
$this->read_replica->where($combo_array[$key], $val);
|
||||
|
||||
} else if (array_key_exists($key, $numberic_array)) {
|
||||
|
||||
$this->read_replica->where($numberic_array[$key], $val);
|
||||
|
||||
} else if (strpos($key, 'from') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(me.added) >=', $val);
|
||||
|
||||
} else if (strpos($key, 'to') !== FALSE) {
|
||||
|
||||
$this->read_replica->where('DATE(me.added) <=', $val);
|
||||
|
||||
} else if (array_key_exists($key, $string_array)) {
|
||||
|
||||
$this->read_replica->like('lower(' . $string_array[$key] . ')', strtolower($val));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if ($limit) {
|
||||
$this->read_replica->limit($limit, $offset);
|
||||
}
|
||||
|
||||
return $this->read_replica->get()->result_array();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Test_accounts_model extends CI_Model
|
||||
{
|
||||
public function __constructor()
|
||||
{
|
||||
parrent::__constructor();
|
||||
}
|
||||
|
||||
public function getAccountQuery($params = [])
|
||||
{
|
||||
$whereQuery = ' WHERE 1 = 1 ';
|
||||
|
||||
if (!empty($params['mid'])) {
|
||||
$whereQuery .= " AND t.member_id = " . pg_escape_string(trim($params['mid'])) . " ";
|
||||
}
|
||||
|
||||
if (!empty($params['firstname'])) {
|
||||
$whereQuery .= " AND m.firstname ILIKE '%" . pg_escape_string(trim($params['firstname'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['lastname'])) {
|
||||
$whereQuery .= " AND m.lastname ILIKE '%" . pg_escape_string(trim($params['lastname'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['username'])) {
|
||||
$whereQuery .= " AND m.email ILIKE '%" . pg_escape_string(trim($params['username'])) . "%' ";
|
||||
}
|
||||
|
||||
if (!empty($params['group'])) {
|
||||
$whereQuery .= " AND m.decision_group ILIKE '%" . pg_escape_string(trim($params['group'])) . "%' ";
|
||||
}
|
||||
|
||||
if (isset($params['status']) && $params['status'] != -1) {
|
||||
$whereQuery .= " AND t.status = " . pg_escape_string($params['status']) . " ";
|
||||
}
|
||||
|
||||
|
||||
|
||||
$query = "
|
||||
SELECT
|
||||
t.member_id,
|
||||
m.firstname,
|
||||
m.lastname,
|
||||
m.email,
|
||||
m.decision_group,
|
||||
"
|
||||
. " '<div id=\"stat_' || t.id || '\">' || (
|
||||
CASE WHEN t.status = 1 THEN
|
||||
'Active'
|
||||
ELSE
|
||||
'Disabled'
|
||||
END) || '</div>' AS status,
|
||||
"
|
||||
. " '<button type=\"button\" class=\"btn btn-warning\" onclick=\"removeTest(' || t.id || ');\">Disable</button>' AS action
|
||||
FROM
|
||||
test_accounts t
|
||||
LEFT JOIN members m ON m.id = t.member_id
|
||||
" . $whereQuery . "
|
||||
ORDER BY
|
||||
t.id
|
||||
";
|
||||
|
||||
return $query;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Tourist_attraction_model extends CI_Model
|
||||
{
|
||||
public function __constructor()
|
||||
{
|
||||
parent::__constructor();
|
||||
}
|
||||
|
||||
public function create($data) {
|
||||
$sql = $this->db->insert_string('tourist_attraction', $data) .
|
||||
' ON CONFLICT (attraction, address_id) DO NOTHING RETURNING id';
|
||||
$query = $this->db->query($sql);
|
||||
}
|
||||
|
||||
public function create_multiple($data) {
|
||||
// Prepare SQL query for multiple values with ignore conflict
|
||||
$insert_query = 'INSERT INTO tourist_attraction (active, address_id, attraction, city_id, description, feature_image) VALUES ';
|
||||
$values = array_map(function($poi) {
|
||||
$result = '('
|
||||
. $this->db->escape($poi['active']) . ','
|
||||
. $poi['address_id'] . ','
|
||||
. $this->db->escape($poi['attraction']) . ','
|
||||
. $poi['city_id'] . ','
|
||||
. $this->db->escape($poi['description']) . ','
|
||||
. $this->db->escape($poi['feature_image']) . ')';
|
||||
|
||||
return $result;
|
||||
}, $data);
|
||||
$str_values = implode(',', $values);
|
||||
$insert_query .= $str_values . ' ON CONFLICT (attraction, address_id) DO UPDATE ';
|
||||
$insert_query .= 'SET description = EXCLUDED.description, feature_image = EXCLUDED.feature_image, active = EXCLUDED.active WHERE tourist_attraction.active != true';
|
||||
|
||||
// Excute query
|
||||
return $this->db->query($insert_query);
|
||||
}
|
||||
|
||||
public function update_by_id($id, $data) {
|
||||
$this->db->where('id', $id);
|
||||
return $this->db->update('tourist_attraction', $data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Transport_provider_account_model extends CI_Model
|
||||
{
|
||||
public function __constructor()
|
||||
{
|
||||
parent::__constructor();
|
||||
}
|
||||
|
||||
public function transport_provider_accounts($data)
|
||||
{
|
||||
return (array) $data;
|
||||
}
|
||||
|
||||
public function getTransportProviderAccount($params)
|
||||
{
|
||||
$res = AutomaticServerAPI::get('transport-provider-accounts', $params);
|
||||
|
||||
if (isset($res['error'])) {
|
||||
return ['success' => false, 'error' => $res['error']];
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($res['data'] as $addr) {
|
||||
$data[] = $this->parse_transport_provider_accounts($addr);
|
||||
}
|
||||
|
||||
$totalPage = isset($res['total']) ? $res['total'] : 0;
|
||||
$page = isset($res['page']) ? $res['page'] : 0;
|
||||
|
||||
return [
|
||||
'list' => $data,
|
||||
'totalItems' => $totalPage,
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
||||
public function getTransportProviderAccountByID($id) {
|
||||
$res = AutomaticServerAPI::get("transport-provider-accounts/$id", NULL);
|
||||
$res['data'] = $this->parse_transport_provider_accounts($res['data']);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function createTransportProviderAccount($params)
|
||||
{
|
||||
return AutomaticServerAPI::post('transport-provider-accounts', $params);
|
||||
}
|
||||
|
||||
public function removeTransportProviderAccountById($transportProviderAccountID)
|
||||
{
|
||||
return AutomaticServerAPI::delete("transport-provider-accounts/$transportProviderAccountID");
|
||||
}
|
||||
|
||||
public function updateTransportProviderAccountById($transportProviderAccountID, $params)
|
||||
{
|
||||
return AutomaticServerAPI::put("transport-provider-accounts/$transportProviderAccountID", $params);
|
||||
}
|
||||
|
||||
private function parse_transport_provider_accounts($originData)
|
||||
{
|
||||
return $this->transport_provider_accounts($originData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php if (!defined('BASEPATH')) {
|
||||
exit('No direct script access allowed');
|
||||
}
|
||||
|
||||
class Transport_provider_model extends CI_Model
|
||||
{
|
||||
public function __constructor()
|
||||
{
|
||||
parent::__constructor();
|
||||
}
|
||||
|
||||
public function transport_providers($data)
|
||||
{
|
||||
return (array) $data;
|
||||
}
|
||||
|
||||
public function getTransportProvider($params = null)
|
||||
{
|
||||
$res = AutomaticServerAPI::get('transport-providers', $params);
|
||||
|
||||
if (isset($res['error'])) {
|
||||
return ['success' => false, 'error' => $res['error']];
|
||||
}
|
||||
|
||||
$data = array();
|
||||
foreach ($res['data'] as $addr) {
|
||||
$data[] = $this->parse_transport_provider($addr);
|
||||
}
|
||||
|
||||
$totalPage = isset($res['total']) ? $res['total'] : 0;
|
||||
$page = isset($res['page']) ? $res['page'] : 0;
|
||||
|
||||
return [
|
||||
'list' => $data,
|
||||
'totalItems' => $totalPage,
|
||||
'page' => $page,
|
||||
];
|
||||
}
|
||||
|
||||
public function getTransportByID($id) {
|
||||
$res = AutomaticServerAPI::get("transport-providers/$id", NULL);
|
||||
$res['data'] = $this->parse_transport_provider($res['data']);
|
||||
return $res;
|
||||
}
|
||||
|
||||
public function createTransportProvider($params)
|
||||
{
|
||||
return AutomaticServerAPI::post('transport-providers', $params);
|
||||
}
|
||||
|
||||
public function removeTransportProviderById($transportProviderID)
|
||||
{
|
||||
return AutomaticServerAPI::delete("transport-providers/$transportProviderID");
|
||||
}
|
||||
|
||||
public function updateTransportProviderById($transportProviderID, $params)
|
||||
{
|
||||
return AutomaticServerAPI::put("transport-providers/$transportProviderID", $params);
|
||||
}
|
||||
|
||||
private function parse_transport_provider($originData)
|
||||
{
|
||||
return $this->transport_providers($originData);
|
||||
}
|
||||
|
||||
public function getTransportProviderByName($params) {
|
||||
return AutomaticServerAPI::get("transport-providers", $params);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>403 Forbidden</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<p>Directory access is forbidden.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user