. * */ namespace OCA\News\Bl; use \OCA\AppFramework\Db\DoesNotExistException; 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, ItemBl $itemBl){ parent::__construct($feedMapper); $this->feedFetcher = $feedFetcher; $this->itemBl = $itemBl; } // README: only call this for the cronjob because it does not // check that the feeds belong to the right user public function findAll(){ return $this->mapper->findAll(); } public function findAllFromUser($userId){ return $this->mapper->findAllFromUser($userId); } public function create($feedUrl, $folderId, $userId){ // first try if the feed exists already try { $this->mapper->findByUrlHash(md5($feedUrl), $userId); throw new BLException('Can not add feed: Exists already'); } catch(DoesNotExistException $ex){} 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'); } } public function update($feedId, $userId){ // TODO: update given feed } public function move($feedId, $folderId, $userId){ $feed = $this->find($feedId, $userId); $feed->setFolderId($folderId); $this->mapper->update($feed); } // TODO: delete associated items }