<?php
	require_once dirname(__FILE__) . "/dalBase.php";
	class floatbuttonDAL extends dalBase {
		public $ID;
		public $Type;
		public $Title;
		public $Value;
		public $Icon;
		public $Class;
		public $Visible;

		public function insertRecord(): bool|int {
			$intoAry = [
				parent::addArray(":id", $this->ID, "int"),
				parent::addArray(":type", $this->Type, "int"),
				parent::addArray(":title", $this->Title, "str", 200),
				parent::addArray(":value", $this->Value, "str", 200),
				parent::addArray(":icon", $this->Icon, "str", 200),
				parent::addArray(":class", $this->Class, "str", 100),
				parent::addArray(":visible", $this->Visible, "int")
			];
			$sql = "INSERT INTO `floatbutton` (`ID`, `Type`, `Title`, `Value`, `Icon`, `Class`, `Visible`)".
				" VALUES (:id, :type, :title, :value, :icon, :class, :visible)";
			$this->data->executeNonQuery($sql, $intoAry, true);
			return (!$this->data->error) ? $this->data->getInsertID() : false;
		}
		//查詢
		public function executeRecordset(array $intoAry = [], string $filter = "", string $order = "", int $start = 0, int $length = -1): array {
			$sql = "SELECT a.* FROM `floatbutton` a";
			if ($filter !== "") $sql .= " WHERE $filter";
			$sql .= (!isset($order) || $order === "") ? " ORDER BY a.`ID`" : " ORDER BY $order";
			$length = is_int($length) ? $length : -1;
			return $this->data->executeRecordset($sql, $intoAry, $start, $length);
		}
		//查詢計數
		public function countRecordset(array $intoAry = [], string $filter = ""): int {
			$sql = "SELECT COUNT(*) FROM `floatbutton` a";
			if ($filter !== "") $sql .= " WHERE $filter";
			return $this->data->executeScalar($sql, $intoAry);
		}
		
		//刪除
		public function deleteRecord(): bool {
			$sql = "DELETE FROM `floatbutton` WHERE 1";
			$this->data->executeNonQuery($sql, [], true);
			return (!$this->data->error) ? true : false;
		}
	}
?>