Files
FloatBackOfffice/application/models/Geofence_area_anchor_model.php
dev-chiefworks f76abffdcd first commit
2022-05-31 16:21:53 -04:00

91 lines
2.7 KiB
PHP

<?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();
}
}