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

class CountryModel extends CI_Model { 

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

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

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

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

	function get_country_rows($where)
    {
		$sql = "select * from country_data_tb".$where;
		$query = $this->db->query($sql);
		return $query->result_array();
	}
	
	function get_site_rows($where)
    {
		$sql = "select * from site_tb".$where;
		$query = $this->db->query($sql);
		return $query->result_array();
	}
	
	function get_continent_rows()
    {
		$sql = "select * from continent_tb";
		$query = $this->db->query($sql);
		return $query->result_array();
	}

	function get_country_row($id)
    {
		$sql = "select * from country_data_tb where country = '".$id."'";
		$query = $this->db->query($sql);
		return $query->row_array();
	}
	
	function get_currency_rows()
    {
		$sql = "select id, iso_code from country_tb where id > 0";
		$query = $this->db->query($sql);
		return $query->result_array();
	}
}