summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2012-07-07 21:52:41 -0400
committerAlessandro Cosentino <cosenal@gmail.com>2012-07-07 21:52:41 -0400
commit4b154de4526d25fe810f1f371d9707789994e858 (patch)
tree77d17e41eb269a73550f263fce26ed12301fc183 /lib
parent5754af967cb92c49ae90c544725eb5a9ed33fc59 (diff)
mark as read item working now
Diffstat (limited to 'lib')
-rw-r--r--lib/item.php7
-rw-r--r--lib/itemmapper.php64
2 files changed, 48 insertions, 23 deletions
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;
}
@@ -57,6 +64,30 @@ class OC_News_ItemMapper {
}
/**
+ * @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;
}