?
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Blog Model
*
* @package User
* @subpackage Models
* @category Blog
* @author Bhoopesh Kumar
* @website http://www.tekshapers.com
* @company Tekshapers Inc
*/
class Blog_model extends CI_Model
{
function __construct()
{
parent::__construct();
}
public function blog_list($data)
{
$page='';
$per_page='';
if(isset($data['page_no']) && $data['page_no']!=NULL){
$page = $data['page_no'];
}
if(isset($data['per_page']) && $data['per_page']!=NULL){
$per_page = $data['per_page'];
}
if( isset($data['select_key']) && $data['select_key'] != NULL){
$this->db->select("tbl_blog.blog_id");
}else{
$this->db->select("SQL_CALC_FOUND_ROWS tbl_blog.*,tbl_blog_to_categories.categories_id",false);
}
$this->db->where("tbl_blog.status", '1');
$this->db->join('tbl_blog_to_categories', 'tbl_blog_to_categories.blog_id = tbl_blog.blog_id', 'left');
$this->db->order_by('date_added','DESC');
$this->db->group_by('tbl_blog.blog_id');
$this->db->limit($per_page, ($page * $per_page));
$query = $this->db->get('tbl_blog');
//echo $this->db->last_query();
if($query->num_rows()){
$rs_data['status'] = "success";
$rs_data['search_records'] = $query->num_rows();
$rs_data['result'] = $query->result();
// $total_record = $this->db->query('SELECT FOUND_ROWS() AS `count`');
// $rs_data['totalRecords'] = $total_record->row()->count;
}else{
$rs_data['status']="error";
$rs_data['result']='';
$rs_data['totalRecords'] = 0;
$rs_data['search_records'] = 0;
}
return $rs_data;
}
public function blog_list_for_home_page($data)
{
if($this->cache->file->get('all_home_blog_list')){
$result__ = $this->cache->file->get('all_home_blog_list');
return $result__;
}
$this->db->select("SQL_CALC_FOUND_ROWS tbl_blog.*,tbl_blog_to_categories.categories_id",false);
$this->db->where("tbl_blog.status", '1');
$this->db->join('tbl_blog_to_categories', 'tbl_blog_to_categories.blog_id = tbl_blog.blog_id', 'left');
$this->db->order_by('date_added','DESC');
$this->db->group_by('tbl_blog.blog_id');
$this->db->where('tbl_blog.status','1');
$query = $this->db->get('tbl_blog');
//echo $this->db->last_query();
if($query->num_rows()){
$rs_data['status'] = "success";
$rs_data['search_records'] = $query->num_rows();
$rs_data['result'] = $query->result();
// $total_record = $this->db->query('SELECT FOUND_ROWS() AS `count`');
// $rs_data['totalRecords'] = $total_record->row()->count;
}else{
$rs_data['status']="error";
$rs_data['result']='';
$rs_data['totalRecords'] = 0;
$rs_data['search_records'] = 0;
}
$this->cache->file->save('all_home_blog_list', $rs_data, CACHE_EXPIRE);
return $rs_data;
}
public function blog_list_F_H($data)
{
$this->db->select("SQL_CALC_FOUND_ROWS tbl_blog.*,tbl_blog_to_categories.categories_id",false);
$this->db->where("tbl_blog.status", '1');
$this->db->join('tbl_blog_to_categories', 'tbl_blog_to_categories.blog_id = tbl_blog.blog_id', 'left');
$this->db->order_by('date_added','DESC');
$this->db->group_by('tbl_blog.blog_id');
$this->db->where('tbl_blog.status','1');
$this->db->limit(5);
$query = $this->db->get('tbl_blog');
//echo $this->db->last_query();
if($query->num_rows()){
$rs_data['status'] = "success";
$rs_data['search_records'] = $query->num_rows();
$rs_data['result'] = $query->result();
// $total_record = $this->db->query('SELECT FOUND_ROWS() AS `count`');
// $rs_data['totalRecords'] = $total_record->row()->count;
}else{
$rs_data['status']="error";
$rs_data['result']='';
$rs_data['totalRecords'] = 0;
$rs_data['search_records'] = 0;
}
return $rs_data;
}
public function get_archive_list($arch_month="",$arch_year="",$limit="", $start="", $counts="",$status="")
{
$this->db->select("*");
if($limit!="" || $start != "")
{
$this->db->limit($limit, $start);
}
if($arch_year != "")
{
$this->db->where("YEAR(date_added)", $arch_year);
}
if($arch_month != "")
{
$this->db->where("MONTHNAME(date_added)", $arch_month);
}
$this->db->where("status", '1');
$this->db->order_by('date_added','DESC');
$this->db->group_by('blog_id');
$query = $this->db->get('tbl_blog');
//echo $this->db->last_query();
$total = $query->num_rows();
if($counts != "")
{
return $total;
}
else
{
if ($total > 0)
{
foreach ($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
return false;
}
/*function comment_list($blog_id)
{
if(!empty($post_id))
{
$this->db->where('blog_id',$blog_id);
$this->db->where('status',1);
$this->db->group_by('comment_id');
}
return $this->db->get('tbl_blog_comment')->result();
}*/
function comment_list($blog_id)
{
if(!empty($blog_id))
{
$this->db->where('blog_id',$blog_id);
$this->db->where('status',1);
$this->db->group_by('comment_id');
}
return $this->db->get('tbl_blog_comment')->result();
}
public function categories($categories_id=0)
{
$this->db->order_by('date_added','desc');
if(!empty($categories_id))
{
$this->db->join('tbl_blog_to_categories', 'tbl_blog_to_categories.categories_id = tbl_blog.blog_id', 'left');
$this->db->where('tbl_blog_to_categories.categories_id ='.$categories_id);
}
$query=$this->db->get('tbl_blog');
//echo $this->db->last_query();
return $query;
}
public function blog_details($blog_id="")
{
if(!empty($blog_id))
{
$this->db->where('blog_id',$blog_id);
}
return $this->db->get('tbl_blog')->row();
}
public function list_categories()
{
$row=$this->db->get('tbl_blog_categories');
return $row;
}
public function get_by_blog_id($post_id)
{
$this->db->where('post_id',$post_id);
return $this->db->get('tbl_blog');
}
public function save_comment($comment)
{
$this->db->insert('tbl_blog_comment',$comment);
return $this->db->insert_id();
}
public function get_tag_list($tags="",$limit="", $start="", $counts="")
{
$this->db->select("tbl_blog.*,tbl_blog_tag.blog_tag_id");
if($limit!="" || $start != "")
{
$this->db->limit($limit, $start);
}
if($tags != "")
{
$this->db->where("`tbl_blog_tag`.`tag_id`", $tags);
}
$this->db->where("tbl_blog.status", '1');
$this->db->join('tbl_blog_tag', 'tbl_blog_tag.blog_tag_id = tbl_blog.blog_id', 'left');
$this->db->order_by('tbl_blog.date_added','DESC');
$this->db->group_by('tbl_blog.blog_id');
$query = $this->db->get('tbl_blog');
//echo $this->db->last_query();
$total = $query->num_rows();
if($counts != "")
{
return $total;
}
else
{
if ($total > 0)
{
foreach ($query->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
return false;
}
function get_blog_id($blog_id=FALSE){
if ($group_id !== FALSE) {
$this->db->select('tbl_blog.blog_id,tbl_blog.title');
$this->db->from('tbl_blog');
$this->db->where('tbl_blog.blog_id',$blog_id);
$this->db->where('tbl_blog.status','1'); // Set Filter
$query = $this->db->get();
if ($query->num_rows() > 0) {
foreach ($query->result_array() as $row) {
return $row;
}
}
return false;
}
}
public function get_blog($blog_id)
{
$this->db->select('*');
$this->db->where('status','1');
$this->db->where('blog_id',$blog_id);
$result = $this->db->get('tbl_blog')->row();
if(!empty($result)){
return $result;
}else{
return false;
}
}
public function get_all_blog_data()
{
$this->db->select('*');
$this->db->where('status','1');
$this->db->order_by('blog_id','desc');
$result = $this->db->get('tbl_blog')->result();
if(!empty($result))
{
return $result;
}
else
{
return false;
}
}
public function get_recent_blogs($blog_id)
{
$this->db->select('*');
$this->db->where('blog_id !=',$blog_id);
$this->db->where('status','1');
$this->db->order_by('blog_id','desc');
$this->db->limit(3);
$result = $this->db->get('tbl_blog')->result();
if(!empty($result)){
return $result;
}else{
return false;
}
}
}
?>