From 4b154de4526d25fe810f1f371d9707789994e858 Mon Sep 17 00:00:00 2001 From: Alessandro Cosentino Date: Sat, 7 Jul 2012 21:52:41 -0400 Subject: mark as read item working now --- lib/item.php | 7 +++++- lib/itemmapper.php | 64 +++++++++++++++++++++++++++++++++++------------------- 2 files changed, 48 insertions(+), 23 deletions(-) (limited to 'lib') diff --git a/lib/item.php b/lib/item.php index ff3655e04..64ae368c3 100644 --- a/lib/item.php +++ b/lib/item.php @@ -36,7 +36,12 @@ class OC_News_Item { $this->url = $url; $this->guid = $guid; $this->body = $body; - $this->status |= StatusFlag::Unread; + if ($id == null) { + $this->status |= StatusFlag::Unread; + } + else { + $this->id = $id; + } } public function getGuid(){ diff --git a/lib/itemmapper.php b/lib/itemmapper.php index db2dd0056..95b88f6b3 100644 --- a/lib/itemmapper.php +++ b/lib/itemmapper.php @@ -18,6 +18,19 @@ class OC_News_ItemMapper { const tableName = '*PREFIX*news_items'; + public function fromRow($row){ + $url = $row['url']; + $title = $row['title']; + $guid = $row['guid']; + $status = $row['status']; + $body = $row['body']; + $id = $row['id']; + $item = new OC_News_Item($url, $title, $guid, $body, $id); + $item->setStatus($status); + + return $item; + } + /** * @brief Retrieve all the item corresponding to a feed from the database * @param feedid The id of the feed in the database table. @@ -28,13 +41,7 @@ class OC_News_ItemMapper { $items = array(); while ($row = $result->fetchRow()) { - $url = $row['url']; - $title = $row['title']; - $guid = $row['guid']; - $status = $row['status']; - $body = $row['body']; - $item = new OC_News_Item($url, $title, $guid, $body); - $item->setStatus($status); + $item = $this->fromRow($row); $items[] = $item; } @@ -56,6 +63,30 @@ class OC_News_ItemMapper { return $id; } + /** + * @brief Update the item after its status has changed + * @returns The item whose status has changed. + */ + public function update(OC_News_Item $item){ + + $itemid = $item->getId(); + $status = $item->getStatus(); + + $stmt = OCP\DB::prepare(' + UPDATE ' . self::tableName . + ' SET status = ? + WHERE id = ? + '); + + $params=array( + $status, + $itemid + ); + $stmt->execute($params); + + return true; + } + /** * @brief Save the feed and all its items into the database * @returns The id of the feed in the database table. @@ -99,20 +130,8 @@ class OC_News_ItemMapper { $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); + update($item); } $item->setId($itemid); return $itemid; @@ -127,8 +146,9 @@ class OC_News_ItemMapper { $result = $stmt->execute(array($id)); $row = $result->fetchRow(); - $url = $row['url']; - $title = $row['title']; + $item = $this->fromRow($row); + + return $item; } -- cgit v1.2.3