<?php
class Type{

	private $conn;
	private $table_name = "type";

	public $id;	
	public $type_code;
	public $type;	

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

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

	// 	$stmt->bindParam(":type_code", $this->type_code);
	// 	$stmt->bindParam(":type", $this->type);
	// 	$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 type_code=:type_code, type=:type, 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(":type_code", $this->type_code);
	// 	$stmt->bindParam(":type", $this->type);
	// 	$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  type_code= :type_code or type= :type LIMIT 0,1";
	// 	$stmt = $this->conn->prepare( $query );	
	 
	// 	$stmt->bindParam(":type_code", $this->type_code);
	// 	$stmt->bindParam(":type", $this->type);
		
	// 	$stmt->execute();
	// 	if($stmt->rowCount()>0){
	// 		return true;
	// 	}
	// 	return false;
	// }

	function getAllRows(){
		$condition = "";
		if($this->type){
			$condition .= " WHERE type=:type ";
		}
		$query = "SELECT * FROM type " . $condition . " order by type_code";
		$stmt = $this->conn->prepare($query);
		if($this->type) $stmt->bindParam(":type", $this->type);
		$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;
    // }
    

}
?>
