<?php 

class category {
	
	function getAllRecords($all='*',$where='',$orderby='',$limit=''){
		
		$sql ="select $all FROM tbl_category WHERE 1=1 "; 
		if($where!=''){
			$sql .= " AND $where ";
		}
		
		if($orderby!=''){
			$sql .= " $orderby ";
		}
		
		if($limit!=''){
			$sql .= " $limit ";
		}
		//echo $sql;
		//exit;
		return connection::execute($sql,'select-all');
	}
	
	function getAllCount($where='',$group_by=''){
		
		$sql ="select COUNT(*) as total FROM tbl_category WHERE 1=1 "; 
		if($where!=''){
			$sql .= " AND $where ";
		}
		
		if($group_by!=''){
			$sql .= " GROUP BY  $group_by ";
		}

		$result = connection::execute($sql,'select');
		if($result && count($result)> 0){
			return $result->total;
		}
		return 0;
	}
	
	function fromId($id){
		
		if($id && !is_null($id)){
			$sql ="select * FROM tbl_category WHERE id = $id"; 
			return connection::execute($sql,'select');
		}
		return false;
	}
	
	
	
	function addRecords($data){
		
		if($data && count($data) > 0){
			$sql ="INSERT INTO tbl_category(
				name,
				added_by,
				status,
				created,
				contact_no,
				address,
				profile_image
				)  VALUES (
				'".$data->name."',
				'".$data->added_by."',
				'".$data->status."',
				'".$data->created."',
				'".$data->contact_no."',
				'".$data->address."',
				'".$data->profile_image."'
				)";
				
			return connection::execute($sql,'insert');
		}
		return false;
	}
	
	function updateRecords($data){
		
		if($data && !is_null($data)){
			$sql ="UPDATE tbl_category SET 
			name = '".$data->name."',
			contact_no = '".$data->contact_no."',
			address = '".$data->address."',
			added_by = '".$data->added_by."',
			profile_image = '".$data->profile_image."',
			status = '".$data->status."'
			WHERE id = ".$data->id;
			
			return connection::execute($sql,'update');
		}
		return false;
	}
	
	
	
	function changeStatus($id,$status){

		if($status==0){
			$new_status = 1;
		}else{
			$new_status = 0;
		}
		$sql ="UPDATE tbl_category SET status = '".$new_status."' WHERE id = ".$id;
		return connection::execute($sql,'update');
	}
	
	
	function deleteRecord($id){
		$sql ="DELETE FROM tbl_category  WHERE id = ".$id;
		return connection::execute($sql,'delete');
	}
	
	function allAction($act_val,$checkArr){
		
		if($act_val=='delete_all'  && $checkArr && count($checkArr) > 0){

				$sql ="DELETE FROM tbl_category  WHERE id IN(".implode(',',$checkArr).") " ;
				return connection::execute($sql,'delete');
				
		}else if($act_val=='activate_all' && $checkArr && count($checkArr) > 0){
				
				$sql ="UPDATE tbl_category SET status = '1'  WHERE id IN(".implode(',',$checkArr).") " ;
				return connection::execute($sql,'update');
		
		}else if($act_val=='inactivate_all' && $checkArr && count($checkArr) > 0){

				$sql ="UPDATE tbl_category SET status = '0'  WHERE id IN(".implode(',',$checkArr).") " ;
				return connection::execute($sql,'update');
		}
	}
	
	

	
}

?>
