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

class SiteModel extends CI_Model { 

    public function __construct(){
		parent::__construct();
		$this->load->database();
	}
	
	function get_rows($where)
    {
		$sql = "select site_tb.*, 
		               country_tb.title as country, country_tb.symbol as symbol, country_tb.iso_code as iso_code 
				from site_tb 
				left join country_tb on site_tb.country_id = country_tb.id
				where site_tb.id > 0 and site_tb.isDeleted = 0 ".$where;
		$query = $this->db->query($sql);
		return $query->result_array();
	}

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

	function delete_row($edit_id)
    {		
		$this->db->delete('site_tb', array('id' => $edit_id));
	}
	
	function get_row($id)
    {
		$sql = "select * from site_tb where id = '".$id."'";
		$query = $this->db->query($sql);
		return $query->row_array();
	}

	function get_row_from_url($url)
    {
        $sql = "select kiosk_tb.*, 
		               site_tb.logo as logo
				from kiosk_tb 
				left join site_tb on site_tb.id = kiosk_tb.site_id
				where kiosk_tb.link = '".$url."'";
		$query = $this->db->query($sql);
		return $query->row_array();
	}
	
	function get_site_row($id){
	    $sql = "select site_tb.title as siteName, 
	                   location_tb.title as locationName 
	            from site_tb 
	            left join location_tb on location_tb.site_id = site_tb.id
	            where site_tb.id = '".$id."'";
		$query = $this->db->query($sql);
		return $query->row_array();
	}

	public function update_row($update_data, $id)
	{
		$this->db->update('site_tb', $update_data, $id);
	}
}