diff options
author | Alessandro Cosentino <cosenal@gmail.com> | 2012-06-03 23:36:39 -0400 |
---|---|---|
committer | Alessandro Cosentino <cosenal@gmail.com> | 2012-06-03 23:36:39 -0400 |
commit | 48ca4574197d3452189eb204324f724dadf6a888 (patch) | |
tree | 20c07a8da7da0b2fecef5255bbcd5e950c7cff42 /lib/itemmapper.php | |
parent | 3f35d59911ea3e90c4a47249b4a9e7ca49de2cdb (diff) |
renames some function; changes status of items in the database
Diffstat (limited to 'lib/itemmapper.php')
-rw-r--r-- | lib/itemmapper.php | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/lib/itemmapper.php b/lib/itemmapper.php index 05aceb28a..ea59756eb 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -20,7 +20,7 @@ * */ -/**e 49 +/** * This class maps an item to a row of the items table in the database. * It follows the Data Mapper pattern (see http://martinfowler.com/eaaCatalog/dataMapper.html). */ @@ -67,16 +67,17 @@ class OC_News_ItemMapper { * @brief Save the feed and all its items into the database * @returns The id of the feed in the database table. */ - public function insert(OC_News_Item $item, $feedid){ + public function save(OC_News_Item $item, $feedid){ $guid = $item->getGuid(); - + $status = $item->getStatus(); + echo $status; + $itemid = $this->findIdFromGuid($guid, $feedid); if ($itemid == null){ $title = $item->getTitle(); - $status = $item->getStatus(); - $query = OCP\DB::prepare(' + $stmt = OCP\DB::prepare(' INSERT INTO ' . self::tableName . '(url, title, guid, feed_id, status) VALUES (?, ?, ?, ?, ?) @@ -88,17 +89,32 @@ class OC_News_ItemMapper { } $params=array( - htmlspecialchars_decode($item->getUrl()), - htmlspecialchars_decode($title), - $guid, - $feedid, - $status + htmlspecialchars_decode($item->getUrl()), + htmlspecialchars_decode($title), + $guid, + $feedid, + $status ); - $query->execute($params); + $stmt->execute($params); $itemid = OCP\DB::insertid(self::tableName); } + // update item: its status might have changed + // TODO: maybe make this a new function + else { + $stmt = OCP\DB::prepare(' + UPDATE ' . self::tableName . + ' SET status = ? + WHERE id = ? + '); + + $params=array( + $status, + $itemid + ); + $stmt->execute($params); + } $item->setId($itemid); return $itemid; } @@ -117,9 +133,6 @@ 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 |