<?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 Restore_house_women_child_model
 *
 * @author zmq163
 */
class Restore_house_women_child_model extends CI_Model{
    //put your code here
    var $mdb;
    public function __construct() {
        parent::__construct();
        $this->mdb=  $this->load->database('mdb',true);
    }
    /**
     * 
     * @param type $postData
     * @return boolean
     * 
     * 
     * 
     */
    public function updateAncJqueryModel($postData=NULL){
        if($postData!=NULL){
            $this->mdb->insert('anm_anc_critical',$postData);
            if($this->mdb->affected_rows()>0){
                return TRUE;
            }  else {
                return FALSE;    
            }
        }  else {
            return FALSE;    
        }
    }

    /**
     * 
     * 
     * 
     * 
     * 
     */
    public function getChildListByRegionCodeModel($_region_code = NULL, $_current_page = NULL, $_per_page_row = NULL) {
        if ($_region_code != NULL) {
            $this->mdb->select('mira_child.*,mira_women.name,mira_house.house_number,mira_house.house_head_name');
            $this->mdb->from('mira_child');
            $this->mdb->join('mira_women', 'mira_women.women_id=mira_child.women_id', 'INNER');
            $this->mdb->join('mira_house', 'mira_house.auto_id=mira_women.house_id', 'INNER');
            $this->mdb->where(array('mira_house.region_id'=>$_region_code,'mira_child.delete_status'=>1));
            if ($_current_page != NULL and $_per_page_row != NULL) {
                $this->mdb->order_by('mira_child.child_id', 'asc');
                $this->mdb->limit($_per_page_row, ($_current_page - 1) * $_per_page_row);
            }
            return $this->getData($this->mdb->get());
        } else {
            return FALSE;
        }
    }
    
    /**
     * 
     * 
     * 
     * 
     * 
     */
    public function getHouseListByRegionCodeModel($_region_code = NULL, $_active_page = NULL, $_per_page_row = NULL) {
        if ($_region_code != NULL) {
            $this->mdb->select('*');
            $this->mdb->from('mira_house');
            $this->mdb->where(array('region_id'=> $_region_code,'delete_status'=>1));

            if ($_active_page != NULL and$_per_page_row != NULL) {
                $this->mdb->order_by('mira_house.auto_id', 'asc');
                $this->mdb->limit($_per_page_row, ($_active_page - 1) * $_per_page_row);
            }
            return $this->getData($this->mdb->get());
        } else {
            return FALSE;
        }
    }
    /**
     * 
     * 
     * 
     */
     public function getWomenListByRegionCodeModel($_region_code = NULL, $_current_page = NULL, $_per_page_row = NULL) {
        if ($_region_code != NULL) {
            $this->mdb->select('mira_women.*,mira_house.house_number,mira_house.house_head_name');
            $this->mdb->from('mira_women');
            $this->mdb->join('mira_house', 'mira_house.auto_id=mira_women.house_id', 'INNER');
            $this->mdb->where(array('mira_house.region_id'=> $_region_code,'mira_women.delete_status'=>1));
            if ($_current_page != NULL and $_per_page_row != NULL) {
                $this->mdb->order_by('mira_women.women_id', 'asc');
                $this->mdb->limit($_per_page_row, ($_current_page - 1) * $_per_page_row);
            }
            return $this->getData($this->mdb->get());
        } else {
            return FALSE;
        }
    }
    /**
     * 
     * 
     * 
     * 
     */
    public function updateRestoreHouseModel($auto_id=NULL){
        if($auto_id!=NULL){
            $this->mdb->set('delete_status',0);
            $this->mdb->where('auto_id',$auto_id);
            $this->mdb->update('mira_house');
            if($this->mdb->affected_rows()>0){
                return TRUE;
            }  else {
                return FALSE;    
            }
        }  else {
            return FALSE;    
        }
        
    }
     /**
     * 
     * 
     * 
     * 
     */
    public function updateRestoreChildModel($child_id=NULL){
        if($child_id!=NULL){
            $this->mdb->set('delete_status',0);
            $this->mdb->where('child_id',$child_id);
            $this->mdb->update('mira_child');
            if($this->mdb->affected_rows()>0){
                return TRUE;
            }  else {
                return FALSE;    
            }
        }  else {
            return FALSE;    
        }
        
    }
    
     /**
     * 
     * 
     * 
     * 
     */
    public function updateRestoreWomenModel($women_id=NULL){
        if($women_id!=NULL){
            $this->mdb->set('delete_status',0);
            $this->mdb->where('women_id',$women_id);
            $this->mdb->update('mira_women');
            if($this->mdb->affected_rows()>0){
                return TRUE;
            }  else {
                return FALSE;    
            }
        }  else {
            return FALSE;    
        }
        
    }
    

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