<?php 
class news {
	function getAllRecords($all='*',$where='',$orderby='',$limit=''){
		$sql ="select $all FROM tbl_news WHERE 1=1 "; 
		if($where!=''){
			$sql .= " AND $where ";
		}
		if($orderby!=''){
			$sql .= " $orderby ";
		}
		if($limit!=''){
			$sql .= " $limit ";
		}
		return connection::execute($sql,'select-all');
	}
	function getAllnewsFromIds($ids=null){
		if($ids!=null){
			$sql ="select * FROM tbl_news WHERE FIND_IN_SET(news_id,'$ids')";
			return connection::execute($sql,'select-all');
		}	
	}
	function fromId($id){
		if($id && !is_null($id)){
			$sql ="select * FROM tbl_news WHERE news_id = $id"; 
			return connection::execute($sql,'select');
		}
		return false;
	}
	function getLastOrder(){
		$sql ="select * FROM tbl_news ORDER BY news_order desc LIMIT 0,1 "; 
		$newsDetails = connection::execute($sql,'select');
		if($newsDetails && count($newsDetails) > 0){
			return $newsDetails->news_order;
		}
		return 0;
	}
	function getnewsDetailsFromName($name){
		if($name && !is_null($name)){
			$sql ="select * FROM tbl_news WHERE news_slug = '$name' "; 
			return connection::execute($sql,'select');
		}
		return false;
	}
	function addRecords($data){
		if($data && count($data) > 0){
			$sql ="INSERT INTO tbl_news(news_title,news_slug,news_desc,news_date,news_meta_title,news_meta_keywords,news_meta_desc,news_status)  VALUES ('".$data->news_title."', '".$data->news_slug."', '".$data->news_desc."', '".$data->news_date."', '".$data->news_meta_title."', '".$data->news_meta_keywords."', '".$data->news_meta_desc."', '".$data->news_status."' )";
			
			return connection::execute($sql,'insert');
		}
		return false;
	}
	function updateRecords($data){
		if($data && !is_null($data)){
			$sql ="UPDATE tbl_news SET news_title = '".$data->news_title."',news_slug = '".$data->news_slug."', news_desc = '".$data->news_desc."', news_date = '".$data->news_date."',  news_meta_title = '".$data->news_meta_title."', news_meta_keywords = '".$data->news_meta_keywords."', news_meta_desc = '".$data->news_meta_desc."', news_status = '".$data->news_status."' WHERE news_id = ".$data->news_id;
			return connection::execute($sql,'update');
		}
		return false;
	}
	function changeStatus($news_id,$status){
		if($status==0){
			$new_status = 1;
		}else{
			$new_status = 0;
		}
		$sql ="UPDATE tbl_news SET news_status = '".$new_status."' WHERE news_id = ".$news_id;
		return connection::execute($sql,'update');
	}
	function deleteRecord($news_id){
		$sql ="DELETE FROM tbl_news  WHERE news_id = ".$news_id;
		return connection::execute($sql,'delete');
	}
	function allAction($act_val,$checkArr){
		if($act_val=='delete_all'  && $checkArr && count($checkArr) > 0){
				$sql ="DELETE FROM tbl_news  WHERE news_id IN(".implode(',',$checkArr).") " ;
				return connection::execute($sql,'delete');
		}else if($act_val=='activate_all' && $checkArr && count($checkArr) > 0){
				$sql ="UPDATE tbl_news SET news_status = '1'  WHERE news_id IN(".implode(',',$checkArr).") " ;
				return connection::execute($sql,'update');
		}else if($act_val=='inactivate_all' && $checkArr && count($checkArr) > 0){
				$sql ="UPDATE tbl_news SET news_status = '0'  WHERE news_id IN(".implode(',',$checkArr).") " ;
				return connection::execute($sql,'update');
		}
	}
}
?>