From f52cdaa750f1efa8cb76f6d88c9b1dc291f7b328 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 14 May 2014 17:49:52 +0200 Subject: add JsonSerializable to entities --- db/item.php | 51 ++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) (limited to 'db/item.php') diff --git a/db/item.php b/db/item.php index 3b18cbc8e..e7cbb7793 100644 --- a/db/item.php +++ b/db/item.php @@ -44,21 +44,22 @@ use \OCP\AppFramework\Db\Entity; * @method integer getLastModified() * @method void setLastModified(integer $value) */ -class Item extends Entity implements IAPI { - - public $guidHash; - public $guid; - public $url; - public $title; - public $author; - public $pubDate; - public $body; - public $enclosureMime; - public $enclosureLink; - public $feedId; - public $status = 0; - public $lastModified; - +class Item extends Entity implements IAPI, \JsonSerializable { + + use EntityJSONSerializer; + + protected $guidHash; + protected $guid; + protected $url; + protected $title; + protected $author; + protected $pubDate; + protected $body; + protected $enclosureMime; + protected $enclosureLink; + protected $feedId; + protected $status = 0; + protected $lastModified; public function __construct(){ $this->addType('pubDate', 'integer'); @@ -104,6 +105,26 @@ class Item extends Entity implements IAPI { return !$this->isStarred(); } + /** + * Turns entitie attributes into an array + */ + public function jsonSerialize() { + return $this->serializeFields([ + 'id', + 'guidHash', + 'guid', + 'url', + 'title', + 'author', + 'pubDate', + 'body', + 'enclosureMime', + 'enclosureLink', + 'feedId', + 'status', + 'lastModified', + ]); + } public function toAPI() { return [ -- cgit v1.2.3