<?php 
class testimonial {
	function getAllRecords($all='*',$where='',$orderby='',$limit=''){
		$sql ="select $all FROM tbl_testimonial WHERE 1=1 "; 
		if($where!=''){
			$sql .= " AND $where ";
		}
		if($orderby!=''){
			$sql .= " $orderby ";
		}
		if($limit!=''){
			$sql .= " $limit ";
		}
		return connection::execute($sql,'select-all');
	}
	function getAlltestimonialFromIds($ids=null){
		if($ids!=null){
			$sql ="select * FROM tbl_testimonial WHERE FIND_IN_SET(testimonial_id,'$ids')";
			return connection::execute($sql,'select-all');
		}	
	}
	function fromId($id){
		if($id && !is_null($id)){
			$sql ="select * FROM tbl_testimonial WHERE testimonial_id = $id"; 
			return connection::execute($sql,'select');
		}
		return false;
	}
	
	function gettestimonialDetailsFromName($name){
		if($name && !is_null($name)){
			$sql ="select * FROM tbl_testimonial WHERE testimonial_image = '$name' "; 
			return connection::execute($sql,'select');
		}
		return false;
	}
	function addRecords($data){
		if($data && count($data) > 0){
			$sql ="INSERT INTO tbl_testimonial(testimonial_title,testimonial_image,testimonial_desc,testimonial_company,testimonial_meta_title,testimonial_meta_keywords,testimonial_meta_desc,testimonial_status)  VALUES ('".$data->testimonial_title."', '".$data->testimonial_image."', '".$data->testimonial_desc."', '".$data->testimonial_company."', '".$data->testimonial_meta_title."', '".$data->testimonial_meta_keywords."', '".$data->testimonial_meta_desc."', '".$data->testimonial_status."' )";
			
			return connection::execute($sql,'insert');
		}
		return false;
	}
	function updateRecords($data){
		if($data && !is_null($data)){
			$sql ="UPDATE tbl_testimonial SET testimonial_title = '".$data->testimonial_title."',testimonial_image = '".$data->testimonial_image."', testimonial_desc = '".$data->testimonial_desc."', testimonial_company = '".$data->testimonial_company."',  testimonial_meta_title = '".$data->testimonial_meta_title."', testimonial_meta_keywords = '".$data->testimonial_meta_keywords."', testimonial_meta_desc = '".$data->testimonial_meta_desc."', testimonial_status = '".$data->testimonial_status."' WHERE testimonial_id = ".$data->testimonial_id;
			return connection::execute($sql,'update');
		}
		return false;
	}
	function changeStatus($testimonial_id,$status){
		if($status==0){
			$new_status = 1;
		}else{
			$new_status = 0;
		}
		$sql ="UPDATE tbl_testimonial SET testimonial_status = '".$new_status."' WHERE testimonial_id = ".$testimonial_id;
		return connection::execute($sql,'update');
	}
	function deleteRecord($testimonial_id){
		$sql ="DELETE FROM tbl_testimonial  WHERE testimonial_id = ".$testimonial_id;
		return connection::execute($sql,'delete');
	}
	function allAction($act_val,$checkArr){
		if($act_val=='delete_all'  && $checkArr && count($checkArr) > 0){
				$sql ="DELETE FROM tbl_testimonial  WHERE testimonial_id IN(".implode(',',$checkArr).") " ;
				return connection::execute($sql,'delete');
		}else if($act_val=='activate_all' && $checkArr && count($checkArr) > 0){
				$sql ="UPDATE tbl_testimonial SET testimonial_status = '1'  WHERE testimonial_id IN(".implode(',',$checkArr).") " ;
				return connection::execute($sql,'update');
		}else if($act_val=='inactivate_all' && $checkArr && count($checkArr) > 0){
				$sql ="UPDATE tbl_testimonial SET testimonial_status = '0'  WHERE testimonial_id IN(".implode(',',$checkArr).") " ;
				return connection::execute($sql,'update');
		}
	}
}
?>