<?php

class Floor_model extends CI_Model {

    function __construct() {
        // Call the Model constructor
        parent::__construct();
    }

    function day_visit_list($today=null) {
        
        
    }
    
    function get_all_floors($floorid=null){
        
        $this->db->select('*');
        
        if($this->session->userdata('ho')=='No'){
            $this->db->where('business_id', $this->session->userdata('businessid'));
        }
        
        if(null!=$floorid){
            $this->db->where('id_business_floors', $floorid);
        }
        
        $query = $this->db->get('business_floors');
        
        return $query->result_array();
        
    }
    
    function get_floor_staff(){
        $this->db->select('id_staff, staff_fullname, floor_id, floor');
        
        if($this->session->userdata('ho')=='No'){
            $this->db->where('business_id', $this->session->userdata('businessid'));
        }
        
        $this->db->order_by('floor_id');
                
        $query = $this->db->get('staff');
        
        return $query->result_array();
    }
    
    function update_floor(){
        
        $data = array(
            'floor_name' => $this->input->post('floor_name')
            ,'floor_workstations'=>$this->input->post('floor_workstations')
            ,'floormanager_id'=>$this->input->post('floormanager_id')
            ,'floormanager_name'=>$this->input->post('floormanager_name')
        );
     
        $this->db->where('id_business_floors', $this->input->post('id_business_floors'));
        $this->db->update('business_floors', $data);
        
        return $this->db->affected_rows();
        
    }
    
    function add_floor(){
        
        $data = array(
            'floor_name' => $this->input->post('floor_name')
            ,'floor_workstations'=>$this->input->post('floor_workstations')
            ,'floormanager_id'=>$this->input->post('floormanager_id')
            ,'floormanager_name'=>$this->input->post('floormanager_name')
            ,'business_id'=>$this->session->userdata('businessid')
        );
     
        $this->db->insert('business_floors', $data);
        
        return $this->db->insert_id();
        
    }
    
}