summaryrefslogtreecommitdiffstats
path: root/bl
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2013-03-22 12:35:30 +0100
committerBernhard Posselt <nukeawhale@gmail.com>2013-03-22 12:35:30 +0100
commit7a579b42fa731b65db26bd0c026bc68f2339c451 (patch)
tree77f6481abfa90157ab3cc77566f6d4acd7ce8dda /bl
parent880184d0c2372c2493d62cb6fa4d268902043a65 (diff)
added creating feeds
Diffstat (limited to 'bl')
-rw-r--r--bl/feedbl.php30
-rw-r--r--bl/folderbl.php8
-rw-r--r--bl/itembl.php7
3 files changed, 38 insertions, 7 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
}
diff --git a/bl/folderbl.php b/bl/folderbl.php
index 638f10bd3..c17c516ba 100644
--- a/bl/folderbl.php
+++ b/bl/folderbl.php
@@ -49,7 +49,9 @@ class FolderBl extends Bl {
}
}
-
+ /**
+ * @throws BLException if name exists already
+ */
public function create($folderName, $userId, $parentId=0) {
$this->allowNoNameTwice($folderName, $userId);
@@ -68,6 +70,9 @@ class FolderBl extends Bl {
}
+ /**
+ * @throws BLException if name exists already
+ */
public function rename($folderId, $folderName, $userId){
$this->allowNoNameTwice($folderName, $userId);
@@ -76,5 +81,6 @@ class FolderBl extends Bl {
$this->mapper->update($folder);
}
+ // TODO: delete associated items
}
diff --git a/bl/itembl.php b/bl/itembl.php
index f2b1ac1b3..629f9317f 100644
--- a/bl/itembl.php
+++ b/bl/itembl.php
@@ -72,4 +72,11 @@ class ItemBl extends Bl {
$this->mapper->readFeed($feedId, $userId);
}
+
+ // ATTENTION: this does no validation and is only for creating
+ // items from the fetcher
+ public function create($item){
+ $this->mapper->insert($item);
+ }
+
}