summaryrefslogtreecommitdiffstats
path: root/lib/feedmapper.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/feedmapper.php')
-rw-r--r--lib/feedmapper.php43
1 files changed, 33 insertions, 10 deletions
diff --git a/lib/feedmapper.php b/lib/feedmapper.php
index e0c81a2b3..f3dde51ba 100644
--- a/lib/feedmapper.php
+++ b/lib/feedmapper.php
@@ -22,15 +22,31 @@
/**
* This class maps a feed to an entry in the feeds table of the database.
- * It follows the Data Mapper pattern.
+ * It follows the Data Mapper pattern (see http://martinfowler.com/eaaCatalog/dataMapper.html).
*/
class OC_News_FeedMapper {
-
+
+ private $tableName = '*PREFIX*news_feeds';
+
+ /**
+ * @brief Retrieve a feed from the database
+ * @param id The id of the feed in the database table.
+ */
+ public function find($id){
+ $stmt = OCP\DB::prepare('SELECT * FROM ' . $this->tableName . ' WHERE id = ?');
+ $result = $stmt->execute(array($id));
+ $row = $result->fetchRow();
+
+ $url = $row['url'];
+ $title = $row['title'];
+
+ }
+
/**
- * @brief Save the feed into the database
+ * @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_Feed $feed) {
+ public function insert(OC_News_Feed $feed){
$CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" );
if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){
$_ut = "strftime('%s','now')";
@@ -42,11 +58,11 @@ class OC_News_FeedMapper {
//FIXME: Detect when user adds a known feed
//FIXME: specify folder where you want to add
- $query = OCP\DB::prepare("
- INSERT INTO *PREFIX*news_feeds
- (url, title, added, lastmodified)
+ $query = OCP\DB::prepare('
+ INSERT INTO ' . $this->tableName .
+ '(url, title, added, lastmodified)
VALUES (?, ?, $_ut, $_ut)
- ");
+ ');
$title = $feed->getTitle();
@@ -64,8 +80,15 @@ class OC_News_FeedMapper {
);
$query->execute($params);
- $feed_id = OCP\DB::insertid('*PREFIX*news_feeds');
+ $feedid = OCP\DB::insertid($this->tableName);
+ $feed->setId($feedid);
+
+ $itemMapper = new OC_News_ItemMapper($feed);
- return $feed_id;
+ $items = $feed->getItems();
+ foreach($items as $item){
+ $itemMapper->insert($item);
+ }
+ return $feedid;
}
} \ No newline at end of file