<?Php
class University extends CI_Model
{
    /**
     * Role constructor.
     */
    public function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->library(['auth', 'form_validation']);
    }


	function add_university($request){
            $uni_name = $request['uni-name'];
            $web_url = $request['web-url'];
            $uni_email = $request['uni-email'];
            
            $query = $this->db->get_where('universities', array('name' => $uni_name ));
            $count = $query->num_rows();
            
            if ($count === 0) {
            $data = array(
                'name' => $uni_name,
                'weburl' => $web_url,
                'email' => $uni_email
            );
            $this->db->insert('universities', $data);
            $last_row = $this->db->insert_id();
            return $last_row;
            
            }
            else {
            $data = $query->result_array();
            //return $data[0]['id'];
            return false;
            }
		
	}
        
        function add_section($request){
            $uniadmin_section = $request['uniadmin-section'];
            
            $query = $this->db->get_where('sections', array('name' => $uniadmin_section ));
            $count = $query->num_rows();
            
            if ($count === 0) {
            $data = array(
                'name' => $uniadmin_section
            );
            $this->db->insert('sections', $data);
            $last_row = $this->db->insert_id();
            return $last_row;
            
            }
            else {
            $data = $query->result_array();
            return $data[0]['id'];
            }
		
	}
        
        function add_designation($request){
            $uniadmin_designation = $request['uniadmin-designation'];
            
            $query = $this->db->get_where('designations', array('name' => $uniadmin_designation ));
            $count = $query->num_rows();
            
            if ($count === 0) {
            $data = array(
                'name' => $uniadmin_designation
            );
            $this->db->insert('designations', $data);
            $last_row = $this->db->insert_id();
            return $last_row;
            
            }
            else {
            $data = $query->result_array();
            return $data[0]['id'];
            }
		
	}
        
        
        function add_uniadmin($data){
            
            $this->db->insert('users', $data);
            $last_row = $this->db->insert_id();
            return $last_row;
            
            }
        
        function assign_uniadmin($data){
            
            $this->db->insert('roles_users', $data);
            
            
            }
           
        	
}