<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of add_area_model
 *
 * @author zmq163
 */
class add_area_model extends CI_Model {

    //put your code here
    var $mdb;

    public function __construct() {
        parent::__construct();
        $this->mdb = $this->load->database('mdb', TRUE);
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function addCountryModel($_country_details = NULL) {
        $this->mdb->select('*');
        $this->mdb->from('master_country');
        $this->mdb->where('country_id',$_country_details['country_id']);
        if ($this->getData($this->mdb->get())) {
            return FALSE;
        } else {
            $this->mdb->insert('master_country', $_country_details);
            return ($this->mdb->affected_rows() != 1) ? FALSE : TRUE;
        }
    }

    /**
     * 
     * 
     * 
     */
    public function getCountryModel($_activation_status = NULL) {
        if ($_activation_status != NULL) {
            $this->mdb->select('*');
            $this->mdb->from('master_country');
            $this->mdb->where('activation_status', $_activation_status);
            return $this->getData($this->mdb->get());
        } else {
            return FALSE;
        }
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function addStateModel($_state_details = NULL) {
        if ($_state_details != NULL) {
            $this->mdb->insert('master_state', $_state_details);
            return ($this->mdb->affected_rows() != 1) ? FALSE : TRUE;
        } else {
            return FALSE;
        }
    }

    /**
     * 
     * 
     * 
     */
    public function getStateModel($_activation_status = NULL) {
        if ($_activation_status != NULL) {
            $this->mdb->select('*');
            $this->mdb->from('master_state');
            $this->mdb->where('state_actvation_status', $_activation_status);
            return $this->getData($this->mdb->get());
        } else {
            return FALSE;
        }
    }

    public function getStateByCountryCodeModel($_country_code = NULL) {
        if ($_country_code != NULL) {
            $this->mdb->select('*');
            $this->mdb->from('master_state');
            $this->mdb->where('country_code', $_country_code);
            return $this->getData($this->mdb->get());
        } else {
            return FALSE;
        }
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function addDistrictModel($_district_details = NULL) {
        if ($_district_details != NULL) {
            $this->mdb->insert('master_district', $_district_details);
            return ($this->mdb->affected_rows() != 1) ? FALSE : TRUE;
        } else {
            return FALSE;
        }
    }

    public function getDistrictByStateCodeModel($_state_code = NULL) {
        if ($_state_code != NULL) {
            $this->mdb->select('*');
            $this->mdb->from('master_district');
            $this->mdb->where('state_code', $_state_code);
            return $this->getData($this->mdb->get());
        } else {
            return FALSE;
        }
    }

    /**
     * 
     * 
     * 
     */
    private function getData($_query = NULL) {
        if ($_query != NULL) {
            if ($_query->num_rows() > 0) {
                return $_query->result_array();
            } else {
                return FALSE;
            }
        } else {
            return FALSE;
        }
    }

}
