<?php 
defined('BASEPATH') OR exit('No direct script access allowed');

class LocationModel extends CI_Model { 

    public function __construct(){
		parent::__construct();
		$this->load->database();
	}
	
	function get_rows($where)
    {
		$sql = "select location_tb.*, 
		               site_tb.title as site, 
		               country_tb.title as country, 
		               category_tb.title as content, 
		               background_tb.comp_attachment as comp_attachment, background_tb.orderID as orderID
				from location_tb 
				left join country_tb on location_tb.country_id = country_tb.id
				left join site_tb on location_tb.site_id = site_tb.id
				left join category_tb on location_tb.category_id = category_tb.id
				left join background_tb on location_tb.id = background_tb.location_id
				".$where;
		$query = $this->db->query($sql);
		return $query->result_array();
	}
	
	function get_location_rows($where)
    {
		$sql = "select * from location_tb".$where;
		$query = $this->db->query($sql);
		return $query->result_array();
	}

	public function insert_row($insert_data)
	{
		$this->db->insert('location_tb', $insert_data);
	}

	function delete_row($edit_id)
    {		
		$this->db->delete('location_tb', array('id' => $edit_id));
	}
	
	function get_row($id)
    {
		$sql = "select location_tb.*, 
		               site_tb.title as site, 
		               country_tb.title as country, 
		               category_tb.title as content
				from location_tb 
				left join country_tb on location_tb.country_id = country_tb.id
				left join site_tb on location_tb.site_id = site_tb.id
				left join category_tb on location_tb.category_id = category_tb.id
				where location_tb.id = '".$id."'";
		$query = $this->db->query($sql);
		return $query->row_array();
	}
	
	function get_background_rows($id)
    {
		$sql = "select * from background_tb where location_id = '".$id."'";
		$query = $this->db->query($sql);
		return $query->result_array();
	}

	public function update_row($update_data, $id)
	{
		$this->db->update('location_tb', $update_data, $id);
	}
	
	function get_location_row($where)
    {
		$sql = "select * from location_tb".$where;
		$query = $this->db->query($sql);
		return $query->row_array();
	}
}