From 3f35d59911ea3e90c4a47249b4a9e7ca49de2cdb Mon Sep 17 00:00:00 2001 From: Alessandro Date: Sat, 2 Jun 2012 11:40:35 -0400 Subject: adds delete functions in the mapper --- lib/itemmapper.php | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) (limited to 'lib/itemmapper.php') diff --git a/lib/itemmapper.php b/lib/itemmapper.php index 0d1393409..05aceb28a 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -41,7 +41,8 @@ class OC_News_ItemMapper { $url = $row['url']; $title = $row['title']; $guid = $row['guid']; - $items[] = new OC_News_Item($url, $title, $guid); + $item = new OC_News_Item($url, $title, $guid); + $items[] = $item; } return $items; @@ -73,11 +74,12 @@ class OC_News_ItemMapper { if ($itemid == null){ $title = $item->getTitle(); - + $status = $item->getStatus(); + $query = OCP\DB::prepare(' INSERT INTO ' . self::tableName . - '(url, title, guid, feed_id) - VALUES (?, ?, ?, ?) + '(url, title, guid, feed_id, status) + VALUES (?, ?, ?, ?, ?) '); if(empty($title)) { @@ -89,7 +91,8 @@ class OC_News_ItemMapper { htmlspecialchars_decode($item->getUrl()), htmlspecialchars_decode($title), $guid, - $feedid + $feedid, + $status ); $query->execute($params); @@ -104,7 +107,7 @@ class OC_News_ItemMapper { * @brief Retrieve an item from the database * @param id The id of the feed in the database table. */ - public static function find($id){ + public function find($id){ $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?'); $result = $stmt->execute(array($id)); $row = $result->fetchRow(); @@ -114,4 +117,24 @@ class OC_News_ItemMapper { } + //TODO: the delete of an item should mark an item as deleted, not actually delete from the db + public function markAsDelete($id){ + } + + /** + * @brief Permanently delete all items belonging to a feed from the database + * @param feedid The id of the feed that we wish to delete + * @return + */ + public function deleteAll($feedid){ + + $stmt = OCP\DB::prepare(" + DELETE FROM " . self::tableName . + "WHERE feedid = $id + "); + + $result = $stmt->execute(); + + return $result; + } } \ No newline at end of file -- cgit v1.2.3