<?php

class Store_model extends CI_Model {

    function __construct() {

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

    function get_business_stores() {
        
        $this->db->select('*');
        $this->db->where('business_id', $this->session->userdata('businessid'));
        $query = $this->db->get('business_stores');

        return $query->result_array();
    }

    
    function edit_store() {
        $this->db->select('*');
        $this->db->where('business_stores.id_business_stores', $this->input->post('id_business_stores'));
        $query = $this->db->get('business_stores');

        return $query->row();
    }
    
    function update_store() {
        $this->db->where('id_business_stores', $this->input->post('id_business_stores'));
        $data = array(
            'business_store' => $this->input->post('business_store', TRUE),
            'store_manager' => $this->input->post('store_manager', TRUE),
            'store_cell' => $this->input->post('store_cell', TRUE),
            'store_phone1' => $this->input->post('store_phone1', TRUE),
            'store_address' => $this->input->post('store_address', TRUE),
            'store_city' => $this->input->post('store_city', TRUE)
        );
        $this->db->update('business_stores', $data);
        return $this->db->affected_rows();
    }

    function add_store() {
        
        $data=array(
            
            'business_store' => $this->input->post('business_store', TRUE),
            'store_manager' => $this->input->post('store_manager', TRUE),
            'store_cell' => $this->input->post('store_cell', TRUE),
            'store_phone1' => $this->input->post('store_phone1', TRUE),
            'store_address' => $this->input->post('store_address', TRUE),
            'store_city' => $this->input->post('store_city', TRUE),
            'business_id' => $this->session->userdata('businessid')
        );
        
        $this->db->insert('business_stores', $data);
        return $this->db->insert_id();
    }

}
