HEX
Server: Apache/2.4.41 (Amazon) OpenSSL/1.0.2k-fips PHP/5.6.40
System: Linux ip-172-31-40-18 4.14.146-93.123.amzn1.x86_64 #1 SMP Tue Sep 24 00:45:23 UTC 2019 x86_64
User: apache (48)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /var/www/html/nt/application/models/admin/Mplot.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Mplot extends CI_Model {

    public function __construct() {
        parent::__construct();

    }

    public function get_active_parks() {
        // Select active industrial parks from the database
        $this->db->select('industrial_park_id, park_name');
        $this->db->where('is_active', 1);
        $query = $this->db->get('industrial_park_master');

        // Return the result as an array
        return $query->result_array();
    }

      public function savePlotHeader($data) {
        $this->db->insert('plot_header', $data);
        return $this->db->insert_id();
    }

    public function savePlotDetail($data) {
        $this->db->insert('plot_detail', $data);
    }

    public function saveBoundaryDetail($data) {
        $this->db->insert('boundary_detail', $data);
    }

    public function getPlotData() {
        // Select required fields from plot_header and industrial_park_master tables
        $this->db->select('plot_header.*, industrial_park_master.park_name');
        $this->db->from('plot_header');
        $this->db->join('industrial_park_master', 'plot_header.industrial_park_id = industrial_park_master.industrial_park_id');
        $this->db->order_by('plot_header.plot_header_id', 'DESC');
        // Get plot data
        $query = $this->db->get();
    
        // Return results as array
        return $query->result_array();
    }

    public function getPlotDetails($plotHeaderId) {
        // Join plot_header with industrial_park_master to get park_name
        $this->db->select('plot_header.*, industrial_park_master.park_name,uom_master.name as uom_name');
        $this->db->from('plot_header');
        $this->db->join('industrial_park_master', 'plot_header.industrial_park_id = industrial_park_master.industrial_park_id');
        $this->db->join('uom_master', 'plot_header.uom_id = uom_master.uom_id');

        $this->db->where('plot_header.plot_header_id', $plotHeaderId);
        $plotDetails = $this->db->get()->row_array();
 
        // Fetch plot_details for the given plot_header_id
        $this->db->select('*');
        $this->db->from('plot_detail');
        $this->db->where('plot_header_id', $plotHeaderId);
        $plotDetails['plot_details'] = $this->db->get()->result_array();
    
        // Fetch boundary_details if exists
        $this->db->select('*');
        $this->db->from('boundary_detail');
        $this->db->where('plot_header_id', $plotHeaderId);
        $boundaryDetails = $this->db->get()->result_array();
    
        if (!empty($boundaryDetails)) {
            $plotDetails['boundary_details'] = $boundaryDetails;
        }
        return $plotDetails;
    }
    
    public function updatePlotHeader($plotHeaderId, $plotHeaderData) {
        // Update plot header details with the specified plot header ID
        $this->db->where('plot_header_id', $plotHeaderId);
        $this->db->update('plot_header', $plotHeaderData);
    }

    public function deletePlotDetails($plotHeaderId) {
        // Delete existing plot details associated with the specified plot header ID
        $this->db->where('plot_header_id', $plotHeaderId);
        $this->db->delete('plot_detail');
    }

    public function deleteBoundaryDetails($plotHeaderId) {
        // Delete existing boundary details associated with the specified plot header ID
        $this->db->where('plot_header_id', $plotHeaderId);
        $this->db->delete('boundary_detail');
    }
    
    
}