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

    //put your code here
    var $db_sbcc;
    var $status;
    var $message;
    var $response_data = array();

    public function __construct() {
        parent::__construct();
        $this->db_sbcc = $this->load->database('db_sbcc', true);
        $this->status = false;
    }
    /**
     * 
     * 
     * 
     */
    public function getUserRightFunctionModel($userId=null) {
        if($userId!=null){
            return $this->getData($this->db_sbcc->select('MappingUserFunction.*,MasterFunction.functionName')
                    ->from('MappingUserFunction')
                    ->join('MasterFunction','MasterFunction.functionId=MappingUserFunction.functionId','INNER')
                    ->where('userId',$userId)
                    ->order_by('orderNumber','DESC')
                    ->get());
        } else {
            return false;    
        }
    }

    /**
     * 
     * 
     * 
     * 
     */
    public function userAuthenticationUserIdPassword_model($_post_data = null) {
        if ($_post_data != null) {
          
            $query_data = $this->db_sbcc->select('*')
                            ->from('MasterUser')
                            ->where($_post_data)->get();
            if ($query_data->num_rows() > 0) {
                $this->status = true;
                $this->message = 'Login success';
                $this->response_data = $query_data->result_array();
            } else {
                $this->message = 'Login failed';
            }
        } else {
            $this->message = 'Login failed';
        }
        return $this->getResponseAfterSubmitData($this->status, $this->message, $this->response_data);
    }

    /**
     * 
     * 
     * 
     * 
     */
    private function getResponseAfterSubmitData($_status, $_message, $_responsedata) {
        return array('status' => $_status, 'message' => $_message, 'response_data' => $_responsedata);
    }

    /**
     * 
     * 
     * 
     */
    private function checkLoginIdAvilability($loginId = null) {
        if ($loginId != null) {
            if (
                            $this->db_sbcc->select('*')
                            ->from('MasterUser')
                            ->where('loginId', $loginId)->get()
                            ->num_rows() > 0) {
                return false;
            } else {
                return true;
            }
        } else {
            return false;
        }
    }
    /**
     * 
     * 
     * 
     * 
     */
    public function getData($query=null) {
        if($query!=null and $query->num_rows()>0){
            return $query->result_array();
        } else {
            return false;    
        }
    }

}
