summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAlessandro <acosenti@malutchosky.(none)>2012-06-02 11:40:35 -0400
committerAlessandro <acosenti@malutchosky.(none)>2012-06-02 11:40:35 -0400
commit3f35d59911ea3e90c4a47249b4a9e7ca49de2cdb (patch)
treec3d0bb3ea07eca40dec65158c9477eb13e33ea08 /lib
parente10cdc67c446e768bc4ef8e0b2a73a3def59bcca (diff)
adds delete functions in the mapper
Diffstat (limited to 'lib')
-rw-r--r--lib/feedmapper.php22
-rw-r--r--lib/item.php22
-rw-r--r--lib/itemmapper.php35
3 files changed, 67 insertions, 12 deletions
diff --git a/lib/feedmapper.php b/lib/feedmapper.php
index 737b17d80..e352c7ea7 100644
--- a/lib/feedmapper.php
+++ b/lib/feedmapper.php
@@ -66,7 +66,7 @@ class OC_News_FeedMapper {
* @brief Find the id of a feed and all its items from the database
* @param url url of the feed
* @return id of the feed corresponding to the url passed as parameters
- null - if there is no such feed
+ * null - if there is no such feed
*/
public function findIdFromUrl($url){
$stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE url = ?');
@@ -84,6 +84,7 @@ class OC_News_FeedMapper {
* @param feed the feed to be saved
* @returns The id of the feed in the database table.
*/
+ //TODO: handle error case
public function insert(OC_News_Feed $feed, $folderid){
$CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" );
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
@@ -132,4 +133,23 @@ class OC_News_FeedMapper {
}
return $feedid;
}
+
+ public function delete(OC_News_Feed $feed){
+
+ $id = $feed->getId();
+
+ $stmt = OCP\DB::prepare("
+ DELETE FROM " . self::tableName .
+ "WHERE id = $id
+ ");
+
+ $result = $stmt->execute();
+
+ $itemMapper = new OC_News_ItemMapper();
+ //TODO: handle the value that the execute returns
+ $itemMapper->deleteAll($id);
+
+ return true;
+
+ }
} \ No newline at end of file
diff --git a/lib/item.php b/lib/item.php
index e048e9d11..ad78f07e2 100644
--- a/lib/item.php
+++ b/lib/item.php
@@ -28,11 +28,11 @@ class StatusFlag{
const Updated = 0x16;
}
-/*
-* This class models an item.
-*
-* It encapsulate a SimplePie_Item object and adds a status flag to it
-*/
+/**
+ * This class models an item.
+ *
+ * It encapsulate a SimplePie_Item object and adds a status flag to it
+ */
class OC_News_Item {
private $url;
@@ -76,6 +76,18 @@ class OC_News_Item {
public function isRead(){
return ($this->status & ~StatusFlag::Unread);
}
+
+ public function isImportant(){
+ return ($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(), ...
+ */
+ public function getStatus(){
+ return $this->status;
+ }
public function getTitle(){
return $this->title;
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