diff options
author | Alessandro Cosentino <cosenal@gmail.com> | 2012-05-28 23:40:18 -0400 |
---|---|---|
committer | Alessandro Cosentino <cosenal@gmail.com> | 2012-05-28 23:40:18 -0400 |
commit | 07fdf6ad3c3cc659a06099cd2011aab1ce2c8c5e (patch) | |
tree | ccc41c9c30206e5406415fc9b7dfe1fa24ea7401 /lib/feedmapper.php | |
parent | 762b4d89bc0876d8d514a21bf22babcb012cf298 (diff) |
find a feed in the database by url;Detect when databse contains already a feed
Diffstat (limited to 'lib/feedmapper.php')
-rw-r--r-- | lib/feedmapper.php | 61 |
1 files changed, 41 insertions, 20 deletions
diff --git a/lib/feedmapper.php b/lib/feedmapper.php index c0e0b03a5..7b148b142 100644 --- a/lib/feedmapper.php +++ b/lib/feedmapper.php @@ -63,11 +63,28 @@ 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 + */ + public function findIdFromUrl($url){ + $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE url = ?'); + $result = $stmt->execute(array($url)); + $row = $result->fetchRow(); + $id = null; + if ($row != null){ + $id = $row['id']; + } + return $id; + } + + /** * @brief Save the feed and all its items into the database * @param feed the feed to be saved * @returns The id of the feed in the database table. */ - public function insert(OC_News_Feed $feed){ + public function insert(OC_News_Feed $feed, $folderid){ $CONFIG_DBTYPE = OCP\Config::getSystemValue( "dbtype", "sqlite" ); if( $CONFIG_DBTYPE == 'sqlite' or $CONFIG_DBTYPE == 'sqlite3' ){ $_ut = "strftime('%s','now')"; @@ -76,32 +93,36 @@ class OC_News_FeedMapper { } else { $_ut = "UNIX_TIMESTAMP()"; } - - //FIXME: Detect when user adds a known feed - //FIXME: specify folder where you want to add - $query = OCP\DB::prepare(' - INSERT INTO ' . self::tableName . - '(url, title, added, lastmodified) - VALUES (?, ?, $_ut, $_ut) - '); - + $title = $feed->getTitle(); + $url = htmlspecialchars_decode($feed->getUrl()); if(empty($title)) { $l = OC_L10N::get('news'); $title = $l->t('no title'); } - $params=array( - htmlspecialchars_decode($feed->getUrl()), - htmlspecialchars_decode($title) - - //FIXME: user_id is going to move to the folder properties - //OCP\USER::getUser() - ); - $query->execute($params); - - $feedid = OCP\DB::insertid(self::tableName); + //FIXME: Detect when feed contains already a database id + + $feedid = $this->findIdFromUrl($url); + if ($feedid == null){ + $query = OCP\DB::prepare(' + INSERT INTO ' . self::tableName . + '(url, title, folderid, added, lastmodified) + VALUES (?, ?, ?, ?, ?) + '); + + $params=array( + $url, + htmlspecialchars_decode($title), + $folderid, + $_ut, + $_ut + ); + $query->execute($params); + + $feedid = OCP\DB::insertid(self::tableName); + } $feed->setId($feedid); $itemMapper = new OC_News_ItemMapper($feed); |