load->model('geofence_area_city_settings_model'); $this->load->model('country_model'); $this->load->helper('pagination'); global $savvyext; $this->viewData['storage'] = $savvyext->cfgReadChar('system.storage_url'); } 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') ?? 1; // 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_settings_model->getAllWithPagination($filterData, ['page' => $page, 'itemPerPage' => $this->pagePerItem]); $this->viewData['list'] = $data['data']; $this->viewData['filterData'] = $filterData; $this->viewData['countryList'] = $this->country_model->getAll(); $this->viewData['cityStatus'] = [ Geofence_area_city_settings_model::ACTIVE_STATUS=>'Active', Geofence_area_city_settings_model::INACTIVE_STATUS=>'Inactive' , ]; $this->viewData['pagination'] = initPagination($this->pagePerItem, $data['total'], $page, $pagingUrl); $this->renderAdminPage('geofence_area_city_settings/list', $this->viewData); } public function create() { $this->load->helper(array('form', 'url')); $this->viewData['cityStatus'] = [ 'Active' => Geofence_area_city_settings_model::ACTIVE_STATUS, 'Inactive' => Geofence_area_city_settings_model::INACTIVE_STATUS, ]; $this->viewData['item'] = null; $this->renderAdminPage('geofence_area_city_settings/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_settings_model::ACTIVE_STATUS, 'Inactive' => Geofence_area_city_settings_model::INACTIVE_STATUS, ]; $this->setCreationRules(); if ($this->form_validation->run() == false) { $this->renderAdminPage('geofence_area_city_settings/create', $this->viewData); return; } $inputData = [ 'geofence_area_city' => $this->input->post('city'), 'status' => intval($this->input->post('status')), 'image_url' => $this->input->post('image_url') ?? '', ]; $this->geofence_area_city_settings_model->create($inputData); $this->session->set_flashdata('success', 'Created geofence area city successfully.'); redirect('/geofence_area_city_settings'); } public function edit($id) { $this->load->helper(array('form', 'url')); $this->viewData['item'] = $this->geofence_area_city_settings_model->getItem($id); $this->viewData['itemId'] = $id; $this->viewData['editing'] = true; $this->viewData['cityStatus'] = [ 'Active' => Geofence_area_city_settings_model::ACTIVE_STATUS, 'Inactive' => Geofence_area_city_settings_model::INACTIVE_STATUS, ]; $this->renderAdminPage('geofence_area_city_settings/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_settings_model->getItem($id); $this->viewData['itemId'] = $id; $this->viewData['cityStatus'] = [ 'Active' => Geofence_area_city_settings_model::ACTIVE_STATUS, 'Inactive' => Geofence_area_city_settings_model::INACTIVE_STATUS, ]; $this->setEditRules(); if ($this->form_validation->run() == false) { $this->renderAdminPage('geofence_area_city_settings/edit', $this->viewData); return; } $inputData = [ 'status' => $this->input->post('status'), 'image_url' => $this->input->post('image_url') ?? '', ]; $this->geofence_area_city_settings_model->update($id, $inputData); $this->session->set_flashdata('success', 'Updated geofence area city settings successfully.'); redirect('/geofence_area_city_settings'); } public function delete($id) { $res = $this->geofence_area_city_settings_model->delete($id); $this->session->set_flashdata('success', 'Deleted geofence area city settings successfully.'); redirect('/geofence_area_city_settings'); } 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' => 'city', 'label' => 'City', 'rules' => 'required', ], [ 'field' => 'status', 'label' => 'Status', 'rules' => 'required|integer', ], ]; $this->form_validation->set_rules($config); } private function setEditRules() { $config = [ [ 'field' => 'status', 'label' => 'Status', 'rules' => 'required|integer', ], ]; $this->form_validation->set_rules($config); } }