<?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 Admin_user_model
 *
 * @author zmq163
 */
class Admin_user_model extends CI_Model {

    //put your code here
    var $mdb;

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

    /**
     * 
     * 
     * 
     * 
     */
    public function checkUserIdModel($_user_id = NULL) {
        if ($_user_id != NULL) {
            $this->mdb->select('*');
            $this->mdb->from('master_user_details');
            $this->mdb->where('user_login_id', $_user_id);
            $query = $this->mdb->get();
            if ($query->num_rows() > 0) {
                return FALSE;
            } else {
                return TRUE;
            }
        }
    }
    public function checkAdminUserIdModel($_user_id = NULL) {
        if ($_user_id != NULL) {
            $this->mdb->select('*');
            $this->mdb->from('admin_user_details');
            $this->mdb->where('admin_login_id', $_user_id);
            $query = $this->mdb->get();
            if ($query->num_rows() > 0) {
                return FALSE;
            } else {
                return TRUE;
            }
        }
    }

    /**
     * 
     * 
     * 
     * 
     */
     public function getAdminUserByCondition($_condition_array = NULL) {
        if ($_condition_array != NULL) {
            $this->mdb->select('*');
            $this->mdb->from('admin_user_details');
            $this->mdb->where($_condition_array);
            return $this->getData($this->mdb->get());
        } else {
            return FALSE;
        }
    }
    /**
     * 
     * @param type $_admin_details
     * @return boolean
     * 
     * 
     * 
     */
    public function updateAdminUser($_update_data=NULL,$_update_condition=NULL){
        if($_update_data!=NULL and $_update_condition!=NULL){
           $this->mdb->where($_update_condition); 
           $this->mdb->update('admin_user_details',$_update_data);
           
           $this->mdb->select('*');
           $this->mdb->from('admin_user_details');
           $this->mdb->where($_update_condition);
           return $this->getData($this->mdb->get());
           
        }else{
            return FALSE;
        }
    }
    public function adminUserRegistrationModel($_admin_details = NULL) {
        if ($_admin_details != NULL) {
            if(isset($_admin_details['app_id']) and $_admin_details['app_id']!=0){
                $this->mdb->insert('master_user_details', $_admin_details);
            }  else {
               $this->mdb->insert('admin_user_details', $_admin_details); 
            }
            
            return ($this->mdb->affected_rows() != 1) ? FALSE : TRUE;
        } else {
            return FALSE;
        }
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function adminUserListModel() {
        $this->mdb->select('*');
        $this->mdb->from('admin_user_details');
        return $this->getData($this->mdb->get());
    }

    /**
     * 
     * 
     * 
     */
    public function getAdminUserByAdminIdModel($_admin_id = NULL) {
        if ($_admin_id != NULL) {
            $this->mdb->select('*');
            $this->mdb->from('admin_user_details');
            $this->mdb->where('admin_id', $_admin_id);
            return $this->getData($this->mdb->get());
        } else {
            return FALSE;
        }
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function deleteAdminModel($_admin_id = NULL) {
        if ($_admin_id != NULL) {
            $this->mdb->where('admin_id', $_admin_id);
            $this->mdb->delete('admin_user_details');
            return ($this->mdb->affected_rows() != 1) ? FALSE : TRUE;
        } else {
            return FALSE;
        }
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function updateAdminModel($_admin_id = NULL, $update_array = NULL) {
        if ($_admin_id != NULL) {
            $this->mdb->where('admin_id', $_admin_id);
            $this->mdb->update('admin_user_details', $update_array);
            return ($this->mdb->affected_rows() != 1) ? FALSE : TRUE;
        } else {
            return FALSE;
        }
    }

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

}
