<?php

if(!defined('BASEPATH')) exit('Hacking Attempt : Get Out of the system ..!');

class Gallery_model extends CI_Model
{
	public function __construct(){
		parent::__construct();
	}
	
	
/*#############################################################################################*/
/*################################################ General START ######################################*/
/*#########################################################################################################*/
	
	public function get_general($status=NULL,$type=NULL){
		$this->db->select('*');
		if($status>=0){
			$where = array('status='=>$status,'type'=>$type);
			$this->db->where($where);
		}else{
			$where = array('type'=>$type);
			$this->db->where($where);
		}
		$this->db->order_by('updatedon','ASC');
		$query = $this->db->get('gallery_category');
		
		return $query->result();
	}
	
	public function get_single_general($id){
		$this->db->select('*');
		$where = array('categoryId='=>$id);
		$this->db->where($where);
		$query = $this->db->get('gallery_category');		
		return $query->result();
	}
	
	public function delete_general($id){
		$this->db->where('categoryId', $id );
		$this->db->delete('gallery_category');
		
		$this->db->where(array('itemId='=>$id,'table='=>'gallery_category') );
		$this->db->delete('site_seo');
	}
	
	public function set_general($data,$id){
		
		if($id>0)
		{
			$this->db->where('categoryId', $id);
			$this->db->update('gallery_category', $data);	
		}else{
			
			$this->db->insert('gallery_category', $data);
			
			$insert_id = $this->db->insert_id();
			
			$seo['itemId']=$insert_id;
			$seo['slug']=$data['slug'];
			$seo['table']='gallery_category';
			$this->db->insert('site_seo', $seo);			
		}
		

	}
	
	public function get_gallery($id){
		$this->db->select('gallery_category.title,gallery.*');		
		$this->db->join('gallery_category','gallery_category.categoryId=gallery.itemId');
		$this->db->where(array('gallery.itemId='=>$id,'gallery.table='=>'gallery_category','gallery.type='=>0));
		$this->db->order_by('gallery.updatedon','ASC');
		$query = $this->db->get('gallery');		
		return $query->result();
	}
	
	public function get_press_gallery($id){
		$this->db->select('gallery.*');		
		$this->db->where(array('gallery.itemId='=>$id,'gallery.table='=>'press','gallery.type='=>0));
		$this->db->order_by('gallery.updatedon','ASC');
		$query = $this->db->get('gallery');		
		return $query->result();
	}
/*#################################################################################################*/
/*###################################### General END ##################################*/
/*#####################################################################################*/

public function set_page_seo($data,$id){
		
			$this->db->where('itemId', $id);
			$this->db->update('site_seo', $data);

			$this->db->where('categoryId', $id);
			$this->db->update('gallery_category', array('slug'=>$data['slug']));	
	}
		
	public function get_page_seo($id){
		$this->db->select('*');
		$where = array('itemId='=>$id,'table='=>'gallery_category');
		$this->db->where($where);
		$query = $this->db->get('site_seo');		
		return $query->result();
	}
}

?>