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

class SouvenirModel extends CI_Model { 

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

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

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

	public function update_row($update_data, $id)
	{
		$this->db->update('souvenir_tb', $update_data, $id);
	}	
	
	/*         Souvenir Size & Price Part           */
	
	function get_size_rows($where)
    {
		$sql = "select souvenir_size_tb.*, 
		               country_tb.symbol as symbol, souvenir_tb.discount as discount
		        from souvenir_size_tb
		        left join souvenir_tb on souvenir_tb.id = souvenir_size_tb.souvenir_id
		        left join country_tb on souvenir_tb.country_id = country_tb.id".$where;
		$query = $this->db->query($sql);
		return $query->result_array();
	}

	function get_size_row($id)
    {
		$sql = "select * from souvenir_size_tb where id = '".$id."'";
		$query = $this->db->query($sql);
		return $query->row_array();
	}

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

	function delete_size_row($edit_id)
    {		
		$this->db->delete('souvenir_size_tb', array('id' => $edit_id));
	}

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