diff options
Diffstat (limited to 'lib/itemmapper.php')
-rw-r--r-- | lib/itemmapper.php | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/lib/itemmapper.php b/lib/itemmapper.php index 9b6c613ff..9aac95a37 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -36,18 +36,25 @@ class ItemMapper { * @returns an object of the class OC_News_Item */ public function fromRow($row) { - $url = $row['url']; $title = $row['title']; $guid = $row['guid']; $body = $row['body']; $id = $row['id']; + $item = new Item($url, $title, $guid, $body, $id); $item->setStatus($row['status']); $item->setAuthor($row['author']); $item->setFeedId($row['feed_id']); $item->setDate(Utils::dbtimestampToUnixtime($row['pub_date'])); + if($row['enclosure_mime'] !== null && $row['enclosure_link'] !== null) { + $enclosure = new Item_Enclosure(); + $enclosure->setMimeType($row['enclosure_mime']); + $enclosure->setLink($row['enclosure_link']); + $item->setEnclosure($enclosure); + } + return $item; } @@ -195,11 +202,18 @@ class ItemMapper { $title = $item->getTitle(); $body = $item->getBody(); $author = $item->getAuthor(); - + $enclosure_mime = null; + $enclosure_link = null; + + if($enclosure = $item->getEnclosure()) { + $enclosure_mime = $enclosure->getMimeType(); + $enclosure_link = $enclosure->getLink(); + } + $stmt = \OCP\DB::prepare(' INSERT INTO ' . self::tableName . - '(url, title, body, author, guid, guid_hash, pub_date, feed_id, status) - VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?) + '(url, title, body, author, guid, guid_hash, pub_date, enclosure_mime, enclosure_link, feed_id, status) + VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) '); if(empty($title)) { @@ -222,6 +236,8 @@ class ItemMapper { $guid, $guid_hash, $pub_date, + $enclosure_mime, + $enclosure_link, $feedid, $status ); @@ -244,7 +260,7 @@ class ItemMapper { public function findById($id) { $stmt = \OCP\DB::prepare('SELECT ' . self::tableName . '.id AS id, ' . self::tableName . - '.url AS url, ' . self::tableName . '.title AS title, guid, body, status, author, feed_id, pub_date' . + '.url AS url, ' . self::tableName . '.title AS title, guid, body, status, author, feed_id, pub_date, enclosure_mime, enclosure_link' . ' FROM ' . self::tableName . ' JOIN ' . FeedMapper::tableName . ' ON ' . self::tableName . '.feed_id = ' . FeedMapper::tableName . '.id WHERE (' . self::tableName . '.id = ? AND ' . FeedMapper::tableName . '.user_id = ? )'); |