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

	class Mod_post extends CI_Model
	{
		var $table = "blog_posts";
		function __construct()
		{
			parent::__construct();
		}	
		
		
		function getpost()
		{
			$this->db->SELECT("*");
			$this->db->from($this->table);
			$this->db->where('postID !=' , 1);
			$this->db->join("tbluser","tbluser.userid = blog_posts.postBy","left");		
			$this->db->order_by("blog_posts.postID", "DESC"); 
			return $this->db->get();
		}
		
			
		function add($data)
		{
			$this->db->insert($this->table,$data);
		}


		function addcats($data)
		{
			$this->db->insert('blog_post_cats',$data);	
		}
		
		
		function addsubcats($data)
		{
			$this->db->insert('blog_post_subcats',$data);	
		}
		
		
		function insertTags($data)
		{
			$this->db->insert('blog_tags',$data);
		}
		
		
		function update($data,$id)
		{
			$this->db->where("postID",$id);
			$this->db->update($this->table,$data);
		}
		
		
		function delete($id)
		{
			$this->db->where("postID",$id);
			$this->db->delete($this->table);
		}
		
		
		function delcat($id)
		{
			$this->db->where("postID",$id);
			$this->db->delete("blog_post_cats");
		}
		
		/*function deltags($id)
		{
			$this->db->where("postID",$id);
			$this->db->delete("blog_tags");
		}
		
		function delsubcat($id)
		{
			$this->db->where("postID",$id);
			$this->db->delete("blog_post_subcats");
		}*/
		
		function getById($id)
		{
			$this->db->where("postID",$id);
			$this->db->from($this->table);
			$q = $this->db->get();
			if($q->num_rows() > 0)
			{
				return $q->row();
			}
			return false;
		}
		
		function getByCode($code)
		{
			$this->db->where("postCode",$code);
			$this->db->from($this->table);
			$q = $this->db->get();
			if($q->num_rows() > 0)
			{	
				return $code;
			}
			return false;
			
		} 	
			
			
			
}