<?php
include_once '../objects/db_table_object.php';

class DBObjectType extends DBTableObject
{
    // database connection and table name
    //private $conn;
    //private $table_name = "sessioneventtypes";
	
    protected $array_key = "type";

	// object properties
    public $id = -1;
    public $displayName = "";
    public $description = "";
	

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	public function toArray () : array
	{
		return array (
			"id" => $this->id,
			"displayName" => $this->displayName,
			"description" => $this->description
		);
	}
	

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	function save ()
	{
        // query to insert record of new user signup
        $query = "INSERT INTO " . $this->table_name . " SET displayName=:displayName, description=:description";
    
        // prepare query
        $stmt = $this->conn->prepare($query);
		
        // sanitize
        $this->displayName=htmlspecialchars(strip_tags($this->displayName));
        $this->description=htmlspecialchars(strip_tags($this->description));
    
        // bind values
        $stmt->bindParam(":displayName", $this->displayName);
        $stmt->bindParam(":description", $this->description);
		
        // execute query
        if($stmt->execute())
		{
            $this->id = $this->conn->lastInsertId();
            return true;
        }
    
        return false;
    }
}
?>