diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-22 12:35:30 +0100 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2013-03-22 12:35:30 +0100 |
commit | 7a579b42fa731b65db26bd0c026bc68f2339c451 (patch) | |
tree | 77f6481abfa90157ab3cc77566f6d4acd7ce8dda /bl/feedbl.php | |
parent | 880184d0c2372c2493d62cb6fa4d268902043a65 (diff) |
added creating feeds
Diffstat (limited to 'bl/feedbl.php')
-rw-r--r-- | bl/feedbl.php | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/bl/feedbl.php b/bl/feedbl.php index da6c602bf..5e5ff4fa7 100644 --- a/bl/feedbl.php +++ b/bl/feedbl.php @@ -28,16 +28,17 @@ namespace OCA\News\Bl; use \OCA\News\Db\Feed; use \OCA\News\Db\FeedMapper; use \OCA\News\Utility\FeedFetcher; - +use \OCA\News\Utility\FetcherException; class FeedBl extends Bl { private $feedFetcher; - public function __construct(FeedMapper $feedMapper, - FeedFetcher $feedFetcher){ + public function __construct(FeedMapper $feedMapper, + FeedFetcher $feedFetcher, ItemBl $itemBl){ parent::__construct($feedMapper); $this->feedFetcher = $feedFetcher; + $this->itemBl = $itemBl; } @@ -53,8 +54,25 @@ class FeedBl extends Bl { } - public function create($feedUrl, $parentId, $userId){ - // TODO: download new items of feed + public function create($feedUrl, $folderId, $userId){ + // first try if its possible to reach the feed + try { + list($feed, $items) = $this->feedFetcher->fetch($feedUrl); + + // insert feed + $feed->setFolderId($folderId); + $feed = $this->mapper->insert($feed); + + // insert items + foreach($items as $item){ + $item->setFeedId($feed->getId()); + $this->itemBl->create($item); + } + + return $feed; + } catch(FetcherException $ex){ + throw new BLException('Can not add feed: Not found or bad source'); + } } @@ -69,5 +87,5 @@ class FeedBl extends Bl { $this->mapper->update($feed); } - + // TODO: delete associated items } |