<?php
class Category{

	private $conn;
	private $table_name = "category";

	public $id;	
	public $category_code;
	public $category;	
	public $entry_by;
	public $entry_date_time;

	public function __construct($db){
		$this->conn = $db;
	}

	// function create(){
	// 	$query = "INSERT INTO " . $this->table_name . " SET category_code=:category_code, category=:category, entry_by=:entry_by, entry_date_time=:entry_date_time";
	// 	$stmt = $this->conn->prepare($query);

	// 	$stmt->bindParam(":category_code", $this->category_code);
	// 	$stmt->bindParam(":category", $this->category);
	// 	$stmt->bindParam(":entry_by", $this->entry_by);
	// 	$stmt->bindParam(":entry_date_time", $this->entry_date_time);

	// 	if($stmt->execute()){
	// 		return true;
	// 	}	 
	// 	return false;
	// }

	// function update(){
	// 	$query = "UPDATE " . $this->table_name . " SET category_code=:category_code, category=:category, entry_by=:entry_by, entry_date_time=:entry_date_time where id=:id";
	// 	$stmt = $this->conn->prepare($query);

	// 	$stmt->bindParam(":id", $this->id);
	// 	$stmt->bindParam(":category_code", $this->category_code);
	// 	$stmt->bindParam(":category", $this->category);
	// 	$stmt->bindParam(":entry_by", $this->entry_by);
	// 	$stmt->bindParam(":entry_date_time", $this->entry_date_time);
		
	// 	if($stmt->execute()){
	// 		return true;
	// 	}
	// 	return false;
	// }

	// function exist(){
	// 	$query = "SELECT id FROM " . $this->table_name . " WHERE  category_code= :category_code or category= :category LIMIT 0,1";
	// 	$stmt = $this->conn->prepare( $query );	
	 
	// 	$stmt->bindParam(":category_code", $this->category_code);
	// 	$stmt->bindParam(":category", $this->category);
		
	// 	$stmt->execute();
	// 	if($stmt->rowCount()>0){
	// 		return true;
	// 	}
	// 	return false;
	// }

	function getAllRows(){
		$condition = "";
		if($this->category){
			$condition .= " WHERE category=:category ";
		}
		$query = "SELECT * FROM category " . $condition . " order by id";
		$stmt = $this->conn->prepare($query);
		if($this->category) $stmt->bindParam(":category", $this->category);
		$stmt->execute();
		return $stmt;
	}

    // function delete(){
	// 	$query = "DELETE FROM " . $this->table_name . " WHERE id = ?";
	// 	$stmt = $this->conn->prepare($query);
	// 	$stmt->bindParam(1, $this->id);
	// 	if($stmt->execute()){
	// 		return true;
	// 	}
	// 	return false;
    // }
    

}
?>
