246 lines
8.0 KiB
PHP
246 lines
8.0 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Geofence_area_city extends Admin_Controller
|
|
{
|
|
const CSV_FIELDS = [
|
|
'id',
|
|
'city',
|
|
'country',
|
|
'latitude',
|
|
'longitude',
|
|
'location',
|
|
'radius',
|
|
'status'
|
|
];
|
|
|
|
public $viewData = array();
|
|
public $pagePerItem = 10;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
// Load model
|
|
$this->load->model('geofence_area_city_model');
|
|
$this->load->model('country_model');
|
|
$this->load->helper('pagination');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
|
|
//get query string filter
|
|
$queryString = $this->input->server('QUERY_STRING');
|
|
$filterData = $this->input->get();
|
|
$page = $this->input->get('page');
|
|
|
|
// remove empty value
|
|
$filterData = array_filter($filterData, function ($v, $k) {
|
|
return $v != '';
|
|
}, ARRAY_FILTER_USE_BOTH);
|
|
|
|
$pagingUrl = empty($queryString) ? uri_string() : uri_string() . '?' . $queryString;
|
|
$pagingUrl = remove_querystring_var($pagingUrl, 'page');
|
|
|
|
$data = $this->geofence_area_city_model->getAllWithPagination($page, $this->pagePerItem, $filterData);
|
|
$this->viewData['list'] = $data['data'];
|
|
$this->viewData['filterData'] = $filterData;
|
|
$this->viewData['countryList'] = $this->country_model->getAll();
|
|
$this->viewData['cityStatus'] = [
|
|
Geofence_area_city_model::ACTIVE_STATUS=>'Active',
|
|
Geofence_area_city_model::INACTIVE_STATUS=>'Inactive' ,
|
|
];
|
|
|
|
$this->viewData['pagination'] = initPagination($this->pagePerItem, $data['total'], $page, $pagingUrl);
|
|
$this->renderAdminPage('geofence_area_city/list', $this->viewData);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->viewData['countryList'] = $this->country_model->getAll();
|
|
$this->viewData['cityStatus'] = [
|
|
'Active' => Geofence_area_city_model::ACTIVE_STATUS,
|
|
'Inactive' => Geofence_area_city_model::INACTIVE_STATUS,
|
|
];
|
|
$this->viewData['item'] = null;
|
|
$this->renderAdminPage('geofence_area_city/create', $this->viewData);
|
|
}
|
|
|
|
public function store()
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->library('form_validation');
|
|
|
|
$this->viewData['item'] = null;
|
|
$this->viewData['countryList'] = $this->country_model->getAll();
|
|
$this->viewData['cityStatus'] = [
|
|
'Active' => Geofence_area_city_model::ACTIVE_STATUS,
|
|
'Inactive' => Geofence_area_city_model::INACTIVE_STATUS,
|
|
];
|
|
|
|
$this->setCreationRules();
|
|
if ($this->form_validation->run() == false) {
|
|
$this->renderAdminPage('geofence_area_city/create', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
$inputData = [
|
|
'city' => $this->input->post('city'),
|
|
'country' => $this->input->post('country_code'),
|
|
'latitude' => $this->input->post('latitude'),
|
|
'longitude' => $this->input->post('longitude'),
|
|
'radius' => $this->input->post('radius'),
|
|
'status' => $this->input->post('status'),
|
|
];
|
|
|
|
$this->geofence_area_city_model->create($inputData);
|
|
|
|
$this->session->set_flashdata('success', 'Created geofence area city successfully.');
|
|
redirect('/geofence_area_city');
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->viewData['item'] = $this->geofence_area_city_model->getItem($id);
|
|
$this->viewData['itemId'] = $id;
|
|
$this->viewData['countryList'] = $this->country_model->getAll();
|
|
$this->viewData['cityStatus'] = [
|
|
'Active' => Geofence_area_city_model::ACTIVE_STATUS,
|
|
'Inactive' => Geofence_area_city_model::INACTIVE_STATUS,
|
|
];
|
|
$this->renderAdminPage('geofence_area_city/edit', $this->viewData);
|
|
}
|
|
|
|
public function update($id)
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->library('form_validation');
|
|
|
|
$this->viewData['item'] = $this->geofence_area_city_model->getItem($id);
|
|
$this->viewData['itemId'] = $id;
|
|
$this->viewData['countryList'] = $this->country_model->getAll();
|
|
$this->viewData['cityStatus'] = [
|
|
'Active' => Geofence_area_city_model::ACTIVE_STATUS,
|
|
'Inactive' => Geofence_area_city_model::INACTIVE_STATUS,
|
|
];
|
|
|
|
$this->setCreationRules();
|
|
if ($this->form_validation->run() == false) {
|
|
$this->renderAdminPage('geofence_area_city/edit', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
$inputData = [
|
|
'city' => $this->input->post('city'),
|
|
'country' => $this->input->post('country_code'),
|
|
'latitude' => $this->input->post('latitude'),
|
|
'longitude' => $this->input->post('longitude'),
|
|
'radius' => $this->input->post('radius'),
|
|
'status' => $this->input->post('status'),
|
|
];
|
|
|
|
$this->geofence_area_city_model->update($id, $inputData);
|
|
|
|
$this->session->set_flashdata('success', 'Updated geofence area city successfully.');
|
|
redirect('/geofence_area_city');
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
$res = $this->geofence_area_city_model->delete($id);
|
|
$this->session->set_flashdata('success', 'Deleted geofence area city successfully.');
|
|
|
|
redirect('/geofence_area_city');
|
|
}
|
|
|
|
protected function renderAdminPage($page_name, $data)
|
|
{
|
|
$this->load->view('admin/view_admin_header', $data);
|
|
$this->load->view($page_name, $data);
|
|
$this->load->view('admin/view_admin_footer', $data);
|
|
}
|
|
|
|
public function getcityAjax()
|
|
{
|
|
if (!$this->input->is_ajax_request()) {
|
|
exit('No direct script access allowed');
|
|
}
|
|
|
|
$result = $this->geofence_area_city_model->getCityWithFilter([
|
|
'city_name' => trim($this->input->get('city_name')),
|
|
'page' => $this->input->get('page')
|
|
]);
|
|
|
|
echo json_encode([
|
|
'data' => $result['data'],
|
|
'total' => $result['total']
|
|
]);
|
|
}
|
|
|
|
private function setCreationRules()
|
|
{
|
|
$config = [
|
|
[
|
|
'field' => 'country_code',
|
|
'label' => 'Country',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'city',
|
|
'label' => 'City name',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'latitude',
|
|
'label' => 'Latitude',
|
|
'rules' => 'required|numeric',
|
|
],
|
|
[
|
|
'field' => 'longitude',
|
|
'label' => 'Longitude',
|
|
'rules' => 'required|numeric',
|
|
],
|
|
[
|
|
'field' => 'radius',
|
|
'label' => 'Radius',
|
|
'rules' => 'required|integer',
|
|
],
|
|
[
|
|
'field' => 'status',
|
|
'label' => 'Status',
|
|
'rules' => 'required|integer',
|
|
],
|
|
];
|
|
|
|
$this->form_validation->set_rules($config);
|
|
}
|
|
|
|
public function getCities() {
|
|
//get query string filter
|
|
$queryString = $this->input->server('QUERY_STRING');
|
|
$filterData = $this->input->get();
|
|
$page = $this->input->get('page');
|
|
|
|
// remove empty value
|
|
$filterData = array_filter($filterData, function ($val) {
|
|
return $val !== '';
|
|
});
|
|
|
|
$pagingUrl = empty($queryString) ? uri_string() : uri_string() . '?' . $queryString;
|
|
$pagingUrl = remove_querystring_var($pagingUrl, 'page');
|
|
|
|
$result = $this->geofence_area_city_model->getAllWithPagination($page, $this->pagePerItem, $filterData);
|
|
|
|
echo json_encode(
|
|
[
|
|
'data' =>$result['data'],
|
|
'total' => $result['total'],
|
|
]
|
|
);
|
|
}
|
|
}
|