summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlessandro Cosentino <cosenal@gmail.com>2012-06-03 23:36:39 -0400
committerAlessandro Cosentino <cosenal@gmail.com>2012-06-03 23:36:39 -0400
commit48ca4574197d3452189eb204324f724dadf6a888 (patch)
tree20c07a8da7da0b2fecef5255bbcd5e950c7cff42 /lib
parent3f35d59911ea3e90c4a47249b4a9e7ca49de2cdb (diff)
renames some function; changes status of items in the database
Diffstat (limited to 'lib')
-rw-r--r--lib/feedmapper.php7
-rw-r--r--lib/foldermapper.php9
-rw-r--r--lib/item.php16
-rw-r--r--lib/itemmapper.php41
4 files changed, 47 insertions, 26 deletions
diff --git a/lib/feedmapper.php b/lib/feedmapper.php
index e352c7ea7..4d885579e 100644
--- a/lib/feedmapper.php
+++ b/lib/feedmapper.php
@@ -32,7 +32,7 @@ class OC_News_FeedMapper {
* @param id The id of the feed in the database table.
* @returns
*/
- public function find($id){
+ public function findById($id){
$stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?');
$result = $stmt->execute(array($id));
$row = $result->fetchRow();
@@ -85,7 +85,7 @@ class OC_News_FeedMapper {
* @returns The id of the feed in the database table.
*/
//TODO: handle error case
- public function insert(OC_News_Feed $feed, $folderid){
+ public function save(OC_News_Feed $feed, $folderid){
$CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" );
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
$_ut = "strftime('%s','now')";
@@ -129,8 +129,9 @@ class OC_News_FeedMapper {
$items = $feed->getItems();
foreach($items as $item){
- $itemMapper->insert($item, $feedid);
+ $itemMapper->save($item, $feedid);
}
+
return $feedid;
}
diff --git a/lib/foldermapper.php b/lib/foldermapper.php
index c5adfbfbb..b751e6bcc 100644
--- a/lib/foldermapper.php
+++ b/lib/foldermapper.php
@@ -67,7 +67,7 @@ class OC_News_FolderMapper {
* @param folder the folder to be saved
* @returns The id of the folder in the database table.
*/
- public function insert(OC_News_Folder $folder){
+ public function save(OC_News_Folder $folder){
$query = OCP\DB::prepare('
INSERT INTO ' . self::tableName .
'(name, parent_id, user_id)
@@ -93,12 +93,5 @@ class OC_News_FolderMapper {
$folder->setId($folderid);
-// $folder->getFeeds();
-// $feedMapper = new OC_News_FeedMapper($feed);
-// $items = $feed->getItems();
-// foreach($items as $item){
-// $itemMapper->insert($item);
-// }
-// return $folderid;
}
} \ No newline at end of file
diff --git a/lib/item.php b/lib/item.php
index ad78f07e2..a2ad69b2a 100644
--- a/lib/item.php
+++ b/lib/item.php
@@ -51,6 +51,16 @@ class OC_News_Item {
public function getGuid(){
return $this->guid;
+ echo $item->getTitle() . ' - ';
+ if ($item->isRead()) {
+ echo $l->t('Read');
+ }
+ else {
+ echo $l->t('Unread');
+ }
+ echo '<br>';
+ $item->setRead();
+
}
public function setGuid($guid){
@@ -66,7 +76,7 @@ class OC_News_Item {
}
public function setRead(){
- $this->status |= ~StatusFlag::Unread;
+ $this->status |= ~StatusFlag::Unread;
}
public function setUnread(){
@@ -81,6 +91,10 @@ class OC_News_Item {
return ($this->status & StatusFlag::Important);
}
+ public function setImportant(){
+ $this->status |= StatusFlag::Important;
+ }
+
/**
* NOTE: this is needed to store items in the database, otherwise
* the status of an item should be retrieved with methods: isRead(), isImportant(), ...
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