152 lines
4.9 KiB
PHP
152 lines
4.9 KiB
PHP
<?php
|
|
defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class Geofence_area_country extends Admin_Controller
|
|
{
|
|
|
|
public $viewData = array();
|
|
public $pagePerItem = 10;
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
// Load model
|
|
$this->load->model('geofence_area_country_model');
|
|
$this->load->model('country_model');
|
|
$this->load->helper('pagination');
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
$page = $this->input->get('page');
|
|
|
|
//get query string filter
|
|
$queryString = $this->input->server('QUERY_STRING');
|
|
|
|
$pagingUrl = empty($queryString) ? uri_string() : uri_string() . '?' . $queryString;
|
|
$pagingUrl = remove_querystring_var($pagingUrl, 'page');
|
|
|
|
$data = $this->geofence_area_country_model->getAllWithPagination($page, $this->pagePerItem);
|
|
$this->viewData['list'] = $data['data'];
|
|
$this->viewData['pagination'] = initPagination($this->pagePerItem, $data['total'], $page, $pagingUrl);
|
|
$this->renderAdminPage('geofence_area_country/list', $this->viewData);
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->viewData['countryList'] = $this->country_model->getAll();
|
|
$this->viewData['item'] = null;
|
|
$this->renderAdminPage('geofence_area_country/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->setCreationRules();
|
|
if ($this->form_validation->run() == false) {
|
|
$this->renderAdminPage('geofence_area_country/create', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
$inputData = [
|
|
'country' => $this->input->post('country_code'),
|
|
'latitude' => $this->input->post('latitude'),
|
|
'longitude' => $this->input->post('longitude'),
|
|
'radius' => $this->input->post('radius'),
|
|
];
|
|
|
|
$this->geofence_area_country_model->create($inputData);
|
|
|
|
$this->session->set_flashdata('success', 'Created geofence area country successfully.');
|
|
redirect('/geofence_area_country');
|
|
}
|
|
|
|
public function edit($id)
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->viewData['item'] = $this->geofence_area_country_model->getItem($id);
|
|
$this->viewData['itemId'] = $id;
|
|
$this->viewData['countryList'] = $this->country_model->getAll();
|
|
$this->renderAdminPage('geofence_area_country/edit', $this->viewData);
|
|
}
|
|
|
|
public function update($id)
|
|
{
|
|
$this->load->helper(array('form', 'url'));
|
|
$this->load->library('form_validation');
|
|
|
|
$this->viewData['item'] = $this->geofence_area_country_model->getItem($id);
|
|
$this->viewData['itemId'] = $id;
|
|
$this->viewData['countryList'] = $this->country_model->getAll();
|
|
|
|
$this->setCreationRules();
|
|
if ($this->form_validation->run() == false) {
|
|
$this->renderAdminPage('geofence_area_country/edit', $this->viewData);
|
|
return;
|
|
}
|
|
|
|
$inputData = [
|
|
'country' => $this->input->post('country_code'),
|
|
'latitude' => $this->input->post('latitude'),
|
|
'longitude' => $this->input->post('longitude'),
|
|
'radius' => $this->input->post('radius'),
|
|
];
|
|
|
|
$this->geofence_area_country_model->update($id, $inputData);
|
|
|
|
$this->session->set_flashdata('success', 'Updated geofence area country successfully.');
|
|
redirect('/geofence_area_country');
|
|
}
|
|
|
|
public function delete($id)
|
|
{
|
|
$res = $this->geofence_area_country_model->delete($id);
|
|
$this->session->set_flashdata('success', 'Deleted geofence area country successfully.');
|
|
|
|
redirect('/geofence_area_country');
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
private function setCreationRules()
|
|
{
|
|
$config = [
|
|
[
|
|
'field' => 'country_code',
|
|
'label' => 'Country',
|
|
'rules' => 'required',
|
|
],
|
|
[
|
|
'field' => 'latitude',
|
|
'label' => 'Latitude',
|
|
'rules' => 'required|numeric',
|
|
],
|
|
[
|
|
'field' => 'longitude',
|
|
'label' => 'Longitude',
|
|
'rules' => 'required|numeric',
|
|
],
|
|
[
|
|
'field' => 'radius',
|
|
'label' => 'Radius',
|
|
'rules' => 'required|integer',
|
|
]
|
|
];
|
|
|
|
$this->form_validation->set_rules($config);
|
|
}
|
|
}
|