From e604b3aaa698a939b2210faf390df22fc25b5631 Mon Sep 17 00:00:00 2001 From: Aaron van Geffen Date: Wed, 17 Jan 2024 17:51:25 +0100 Subject: [PATCH] Asset: introduce save method --- models/Asset.php | 44 +++++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) diff --git a/models/Asset.php b/models/Asset.php index c2973c7..49e43bc 100644 --- a/models/Asset.php +++ b/models/Asset.php @@ -8,17 +8,17 @@ class Asset { - protected $id_asset; - protected $id_user_uploaded; - protected $subdir; - protected $filename; - protected $title; - protected $slug; - protected $mimetype; - protected $image_width; - protected $image_height; - protected $date_captured; - protected $priority; + public $id_asset; + public $id_user_uploaded; + public $subdir; + public $filename; + public $title; + public $slug; + public $mimetype; + public $image_width; + public $image_height; + public $date_captured; + public $priority; protected $meta; protected $tags; @@ -675,6 +675,28 @@ class Asset FROM assets'); } + public function save() + { + if (empty($this->id_asset)) + throw new UnexpectedValueException(); + + return Registry::get('db')->query(' + UPDATE assets + SET id_asset = {int:id_asset}, + id_user_uploaded = {int:id_user_uploaded}, + subdir = {string:subdir}, + filename = {string:filename}, + title = {string:title}, + slug = {string:slug}, + mimetype = {string:mimetype}, + image_width = {int:image_width}, + image_height = {int:image_height}, + date_captured = {datetime:date_captured}, + priority = {int:priority} + WHERE id_asset = {int:id_asset}', + get_object_vars($this)); + } + public function setKeyData($title, $slug, DateTime $date_captured = null, $priority) { $params = [