From 0866fdaee85bc8530437436abe7f8536b8b0f4f0 Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Tue, 19 Jul 2022 15:17:08 +0200 Subject: Add database field attributes for entries (#4444) * Add database field attributes for entries Just like we already have for categories, feeds, etc. No core use yet, but allows in particular extensions to save per-entry data * Fix PHPStand * Fix wrong variable --- app/Models/Entry.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'app/Models/Entry.php') diff --git a/app/Models/Entry.php b/app/Models/Entry.php index fb17268b3..72e59e38c 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -44,6 +44,7 @@ class FreshRSS_Entry extends Minz_Model { private $feed; private $tags; + private $attributes = []; public function __construct(int $feedId = 0, string $guid = '', string $title = '', string $authors = '', string $content = '', string $link = '', $pubdate = 0, bool $is_read = false, bool $is_favorite = false, string $tags = '') { @@ -88,6 +89,9 @@ class FreshRSS_Entry extends Minz_Model { if (!empty($dao['categories'])) { $entry->_tags($dao['categories']); } + if (!empty($dao['attributes'])) { + $entry->_attributes('', $dao['attributes']); + } return $entry; } @@ -228,6 +232,29 @@ class FreshRSS_Entry extends Minz_Model { } } + public function attributes($key = '') { + if ($key == '') { + return $this->attributes; + } else { + return isset($this->attributes[$key]) ? $this->attributes[$key] : null; + } + } + + public function _attributes(string $key, $value) { + if ($key == '') { + if (is_string($value)) { + $value = json_decode($value, true); + } + if (is_array($value)) { + $this->attributes = $value; + } + } elseif ($value === null) { + unset($this->attributes[$key]); + } else { + $this->attributes[$key] = $value; + } + } + public function hash(): string { if ($this->hash == '') { //Do not include $this->date because it may be automatically generated when lacking @@ -588,6 +615,7 @@ class FreshRSS_Entry extends Minz_Model { 'is_favorite' => $this->isFavorite(), 'id_feed' => $this->feed(), 'tags' => $this->tags(true), + 'attributes' => $this->attributes(), ); } } -- cgit v1.2.3