first commit
This commit is contained in:
@@ -0,0 +1,173 @@
|
||||
<?php
|
||||
|
||||
defined( 'BASEPATH' ) OR exit( 'No direct script access allowed' );
|
||||
|
||||
class Emission extends Admin_Controller {
|
||||
|
||||
public $statusOptions = [
|
||||
'Active' => 1,
|
||||
'Inactive' => 0
|
||||
];
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
// load library
|
||||
$this->load->library('table');
|
||||
// load model
|
||||
$this->load->model('Emission_model', 'emission');
|
||||
$this->load->model('Emission_Average_model', 'emissionAvrg');
|
||||
|
||||
// init view layer
|
||||
$this->view = array();
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$this->template["table_open"] = "<table class='table table-striped table-hover table-bordered table-condensed' style='padding:0px; background-color:lightgreen;'>";
|
||||
$this->table->set_template( $this->template );
|
||||
|
||||
$emission = $this->getEmission();
|
||||
$emissionAvrg = $this->getEmissionAvrg();
|
||||
|
||||
$data = array();
|
||||
$data['emission_model'] = $this->table->generate( $emission );
|
||||
$data['emission_model_item'] = $emissionAvrg;
|
||||
$this->renderEmissionPage( 'view_emissionmodel', $data );
|
||||
}
|
||||
|
||||
public function getEmission(){
|
||||
global $bko_users_members_access_list;
|
||||
//How many Farm records generated daliy - last 10 days [SG & US] - 2 plots
|
||||
$emission = $this->emission->getData();
|
||||
return $emission;
|
||||
// echo 'Ameye Olu';
|
||||
}
|
||||
|
||||
/**
|
||||
* Get emission avrg result per page and pagination links
|
||||
* @return array
|
||||
*/
|
||||
public function getEmissionAvrg() {
|
||||
$this->load->helper(array('url'));
|
||||
$this->load->helper('pagination');
|
||||
|
||||
// get pagination params
|
||||
$page = $this->input->get('page') ? $this->input->get('page') : 1;
|
||||
$results = $this->emissionAvrg->index($page);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete emission avrg record by id
|
||||
* @param itn $id emission avrg id
|
||||
* @return status code
|
||||
*/
|
||||
public function deleteEmissionAvrg($id) {
|
||||
$affected = $this->emissionAvrg->delete($id);
|
||||
$this->output->set_content_type('application/json')
|
||||
->set_output(json_encode($affected));
|
||||
}
|
||||
|
||||
/**
|
||||
* View form create new emission avrg
|
||||
* @return view
|
||||
*/
|
||||
public function create() {
|
||||
$this->prepare_form();
|
||||
$this->renderEmissionPage('create_emission_avrg', $this->view);
|
||||
}
|
||||
|
||||
/**
|
||||
* View Emission Avrg
|
||||
* @param int $id emission avrg id
|
||||
* @return object emission avrg details
|
||||
*/
|
||||
public function edit($id) {
|
||||
$result = $this->emissionAvrg->edit($id);
|
||||
if (!$result) {
|
||||
show_404();
|
||||
}
|
||||
$this->view['details'] = $result;
|
||||
$this->prepare_form();
|
||||
$this->renderEmissionPage('edit_emission_avrg', $this->view);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store Emission Avrg
|
||||
* @return bool return true if create success, reverse
|
||||
*/
|
||||
public function store() {
|
||||
$this->load->helper(array('form', 'url'));
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$this->prepare_form();
|
||||
$this->view['details'] = $this->input->post();
|
||||
|
||||
$this->form_validation->set_rules($this->emissionAvrg->rules);
|
||||
if ($this->form_validation->run() == false) {
|
||||
$this->renderEmissionPage('create_emission_avrg', $this->view);
|
||||
return;
|
||||
}
|
||||
|
||||
$create = $this->emissionAvrg->store($this->view['details']);
|
||||
if ($create) {
|
||||
$this->session->set_flashdata('success', isSet($create['message']) ? $create['message'] : 'Create success');
|
||||
redirect('/emission');
|
||||
}
|
||||
|
||||
$this->session->set_flashdata('error', $create['message']);
|
||||
$this->renderEmissionPage('create_emission_avrg', $this->view);
|
||||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Emission Avrg
|
||||
* @param int $id emission avrg id
|
||||
* @return bool return true if update success, reverse
|
||||
*/
|
||||
public function update($id) {
|
||||
$this->load->helper(array('form', 'url'));
|
||||
$this->load->library('form_validation');
|
||||
|
||||
$this->prepare_form();
|
||||
$this->view['details'] = $this->input->post();
|
||||
$this->view['details']['id'] = $id;
|
||||
|
||||
$this->form_validation->set_rules($this->emissionAvrg->rules);
|
||||
if ($this->form_validation->run() == false) {
|
||||
$this->renderEmissionPage('edit_emission_avrg', $this->view);
|
||||
return;
|
||||
}
|
||||
|
||||
$update = $this->emissionAvrg->update($id, $this->view['details']);
|
||||
if ($update) {
|
||||
$this->session->set_flashdata('success', isSet($update['message']) ? $update['message'] : 'Create success');
|
||||
redirect('/emission');
|
||||
} else {
|
||||
$this->session->set_flashdata('error', $update['message']);
|
||||
$this->renderEmissionPage('edit_emission_avrg', $this->view);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare form before actions (create, edit)
|
||||
* @return array
|
||||
*/
|
||||
protected function prepare_form() {
|
||||
// load mkey from emission model
|
||||
$mkeyOptions = $this->getEmission()->result();
|
||||
$mkeyOptions = (isset($mkeyOptions) and !empty($mkeyOptions)) ? array_column($mkeyOptions, 'mkey') : null;
|
||||
// load country from country model
|
||||
$this->load->model('Country_model', 'country');
|
||||
$country = $this->country->getAll();
|
||||
$country = (isset($country) and !empty($country)) ? array_column($country, 'code') : null;
|
||||
// load status code
|
||||
$status = $this->statusOptions;
|
||||
|
||||
$this->view['mkeyOptions'] = $mkeyOptions;
|
||||
$this->view['country'] = $country;
|
||||
$this->view['statusOptions'] = $status;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user