$value) { if (property_exists(get_called_class(), $field)) { $this->$field = $value; } } } public static function create($data) { $FronkDB = FronkDB::singleton(); $db = $FronkDB->link; $dataArr = [ $data["table"], $data["row_id"], $data["key"], $data["old_value"], $data["new_value"], $data["note"], $data["user_id"], $data["create"] ]; $sqlValueStr = "(" . implode(", ", array_map(function ($item) use ($db) { return "'" . $db->real_escape_string($item) . "'"; }, $dataArr)) . ")"; $sql = /** @lang text */ "INSERT INTO `WarehouseHistory` (`table`, `row_id`, `key`, `old_value`, `new_value`, `note`, `user_id`, `create`) VALUES $sqlValueStr"; $db->query($sql) or die($db->error); return $db->insert_id; } /** * Retrieves an array of WarehouseHistoryModel objects by row ID. * * @param int $id The row ID. * @param string $table The table name. * @return WarehouseHistoryModel[] Array of WarehouseHistoryModel objects. */ public static function getByRowId(int $id, string $table): array { $db = FronkDB::singleton(); $id = $db->escape($id); $sql = /** @lang text */ "SELECT WH.*, W.name as user_name FROM `WarehouseHistory` WH LEFT JOIN `Worker` W ON WH.user_id = W.id WHERE `row_id` = $id AND `table` = '$table' ORDER BY `create` DESC"; $result = $db->query($sql); $rows = []; while ($row = $result->fetch_assoc()) { $rows[] = new WarehouseHistoryModel($row); } return $rows; } }