diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-15 03:41:49 +0200 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2014-05-15 03:41:49 +0200 |
commit | 407fbebc2da14520942e0a6a9220a5a3cfc4a7ad (patch) | |
tree | e313ddad41398382f82cd27b40f46e0b7394c393 /businesslayer | |
parent | 7d33bab5abd81871e4efcf995f8a715d45b9d590 (diff) |
rename businesslayer to service
Diffstat (limited to 'businesslayer')
-rw-r--r-- | businesslayer/businesslayer.php | 62 | ||||
-rw-r--r-- | businesslayer/businesslayerconflictexception.php | 27 | ||||
-rw-r--r-- | businesslayer/businesslayerexception.php | 27 | ||||
-rw-r--r-- | businesslayer/businesslayervalidationexception.php | 27 | ||||
-rw-r--r-- | businesslayer/feedbusinesslayer.php | 376 | ||||
-rw-r--r-- | businesslayer/folderbusinesslayer.php | 173 | ||||
-rw-r--r-- | businesslayer/itembusinesslayer.php | 242 |
7 files changed, 0 insertions, 934 deletions
diff --git a/businesslayer/businesslayer.php b/businesslayer/businesslayer.php deleted file mode 100644 index dc6fc1a68..000000000 --- a/businesslayer/businesslayer.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\BusinessLayer; - -use \OCP\AppFramework\Db\DoesNotExistException; -use \OCP\AppFramework\Db\MultipleObjectsReturnedException; - -use \OCA\News\Db\IMapper; - - -abstract class BusinessLayer { - - protected $mapper; - - public function __construct(IMapper $mapper){ - $this->mapper = $mapper; - } - - - /** - * Delete an entity - * @param int $id the id of the entity - * @param string $userId the name of the user for security reasons - * @throws DoesNotExistException if the entity does not exist - * @throws MultipleObjectsReturnedException if more than one entity exists - */ - public function delete($id, $userId){ - $entity = $this->find($id, $userId); - $this->mapper->delete($entity); - } - - - /** - * Finds an entity by id - * @param int $id the id of the entity - * @param string $userId the name of the user for security reasons - * @throws DoesNotExistException if the entity does not exist - * @throws MultipleObjectsReturnedException if more than one entity exists - * @return Entity the entity - */ - public function find($id, $userId){ - try { - return $this->mapper->find($id, $userId); - } catch(DoesNotExistException $ex){ - throw new BusinessLayerException($ex->getMessage()); - } catch(MultipleObjectsReturnedException $ex){ - throw new BusinessLayerException($ex->getMessage()); - } - } - -} diff --git a/businesslayer/businesslayerconflictexception.php b/businesslayer/businesslayerconflictexception.php deleted file mode 100644 index d29548256..000000000 --- a/businesslayer/businesslayerconflictexception.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\BusinessLayer; - - -class BusinessLayerConflictException extends BusinessLayerException { - - /** - * Constructor - * @param string $msg the error message - */ - public function __construct($msg){ - parent::__construct($msg); - } - -}
\ No newline at end of file diff --git a/businesslayer/businesslayerexception.php b/businesslayer/businesslayerexception.php deleted file mode 100644 index e9428a05e..000000000 --- a/businesslayer/businesslayerexception.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\BusinessLayer; - - -class BusinessLayerException extends \Exception { - - /** - * Constructor - * @param string $msg the error message - */ - public function __construct($msg){ - parent::__construct($msg); - } - -}
\ No newline at end of file diff --git a/businesslayer/businesslayervalidationexception.php b/businesslayer/businesslayervalidationexception.php deleted file mode 100644 index d61afd6f1..000000000 --- a/businesslayer/businesslayervalidationexception.php +++ /dev/null @@ -1,27 +0,0 @@ -<?php -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\BusinessLayer; - - -class BusinessLayerValidationException extends BusinessLayerException { - - /** - * Constructor - * @param string $msg the error message - */ - public function __construct($msg){ - parent::__construct($msg); - } - -}
\ No newline at end of file diff --git a/businesslayer/feedbusinesslayer.php b/businesslayer/feedbusinesslayer.php deleted file mode 100644 index 46e7ab2da..000000000 --- a/businesslayer/feedbusinesslayer.php +++ /dev/null @@ -1,376 +0,0 @@ -<?php -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\BusinessLayer; - -use \OCP\ILogger; -use \OCP\IL10N; -use \OCP\AppFramework\Db\DoesNotExistException; - -use \OCA\News\Db\Feed; -use \OCA\News\Db\Item; -use \OCA\News\Db\FeedMapper; -use \OCA\News\Db\ItemMapper; -use \OCA\News\Fetcher\Fetcher; -use \OCA\News\Fetcher\FetcherException; -use \OCA\News\ArticleEnhancer\Enhancer; -use \OCA\News\Utility\Config; - - -class FeedBusinessLayer extends BusinessLayer { - - private $feedFetcher; - private $itemMapper; - private $feedMapper; - private $logger; - private $l10n; - private $timeFactory; - private $autoPurgeMinimumInterval; - private $enhancer; - private $purifier; - private $loggerParams; - - public function __construct(FeedMapper $feedMapper, - Fetcher $feedFetcher, - ItemMapper $itemMapper, - ILogger $logger, - IL10N $l10n, - $timeFactory, - Config $config, - Enhancer $enhancer, - $purifier, - $loggerParams){ - parent::__construct($feedMapper); - $this->feedFetcher = $feedFetcher; - $this->itemMapper = $itemMapper; - $this->logger = $logger; - $this->l10n = $l10n; - $this->timeFactory = $timeFactory; - $this->autoPurgeMinimumInterval = $config->getAutoPurgeMinimumInterval(); - $this->enhancer = $enhancer; - $this->purifier = $purifier; - $this->feedMapper = $feedMapper; - $this->loggerParams = $loggerParams; - } - - /** - * Finds all feeds of a user - * @param string $userId the name of the user - * @return array of feeds - */ - public function findAll($userId){ - return $this->feedMapper->findAllFromUser($userId); - } - - - /** - * Finds all feeds from all users - * @return array of feeds - */ - public function findAllFromAllUsers() { - return $this->feedMapper->findAll(); - } - - - /** - * Creates a new feed - * @param string $feedUrl the url to the feed - * @param int $folderId the folder where it should be put into, 0 for root folder - * @param string $userId for which user the feed should be created - * @throws BusinessLayerConflictException if the feed exists already - * @throws BusinessLayerException if the url points to an invalid feed - * @return Feed the newly created feed - */ - public function create($feedUrl, $folderId, $userId){ - // first try if the feed exists already - try { - list($feed, $items) = $this->feedFetcher->fetch($feedUrl); - - // try again if feed exists depending on the reported link - try { - $this->feedMapper->findByUrlHash($feed->getUrlHash(), $userId); - throw new BusinessLayerConflictException( - $this->l10n->t('Can not add feed: Exists already')); - - // If no matchin feed was found everything was ok - } catch(DoesNotExistException $ex){} - - // insert feed - $feed->setFolderId($folderId); - $feed->setUserId($userId); - $feed->setArticlesPerUpdate(count($items)); - $feed = $this->feedMapper->insert($feed); - - // insert items in reverse order because the first one is usually the - // newest item - $unreadCount = 0; - for($i=count($items)-1; $i>=0; $i--){ - $item = $items[$i]; - $item->setFeedId($feed->getId()); - - // check if item exists (guidhash is the same) - // and ignore it if it does - try { - $this->itemMapper->findByGuidHash( - $item->getGuidHash(), $item->getFeedId(), $userId); - continue; - } catch(DoesNotExistException $ex){ - $unreadCount += 1; - $item = $this->enhancer->enhance($item, $feed->getLink()); - $item->setBody($this->purifier->purify($item->getBody())); - $this->itemMapper->insert($item); - } - } - - // set unread count - $feed->setUnreadCount($unreadCount); - - return $feed; - } catch(FetcherException $ex){ - $this->logger->debug($ex->getMessage(), $this->loggerParams); - throw new BusinessLayerException( - $this->l10n->t( - 'Can not add feed: URL does not exist, SSL Certificate can not be validated ' . - 'or feed has invalid xml')); - } - } - - - /** - * Runs all the feed updates - */ - public function updateAll(){ - // TODO: this method is not covered by any tests - $feeds = $this->feedMapper->findAll(); - foreach($feeds as $feed){ - try { - $this->update($feed->getId(), $feed->getUserId()); - } catch(BusinessLayerException $ex){ - $this->logger->debug('Could not update feed ' . $ex->getMessage(), - $this->loggerParams); - } - } - } - - - /** - * Updates a single feed - * @param int $feedId the id of the feed that should be updated - * @param string $userId the id of the user - * @throws BusinessLayerException if the feed does not exist - * @return Feed the updated feed entity - */ - public function update($feedId, $userId){ - try { - $existingFeed = $this->feedMapper->find($feedId, $userId); - - if($existingFeed->getPreventUpdate() === true) { - return; - } - - try { - list(, $items) = $this->feedFetcher->fetch( - $existingFeed->getUrl(), false); - - // update number of articles on every feed update - if($existingFeed->getArticlesPerUpdate() !== count($items)) { - $existingFeed->setArticlesPerUpdate(count($items)); - $this->feedMapper->update($existingFeed); - } - - // insert items in reverse order because the first one is usually - // the newest item - for($i=count($items)-1; $i>=0; $i--){ - $item = $items[$i]; - $item->setFeedId($existingFeed->getId()); - - try { - $this->itemMapper->findByGuidHash($item->getGuidHash(), $feedId, $userId); - } catch(DoesNotExistException $ex){ - $item = $this->enhancer->enhance($item, - $existingFeed->getLink()); - $item->setBody($this->purifier->purify($item->getBody())); - $this->itemMapper->insert($item); - } - } - - } catch(FetcherException $ex){ - // failed updating is not really a problem, so only log it - - $this->logger->debug('Can not update feed with url ' . $existingFeed->getUrl() . - ': Not found or bad source', $this->loggerParams); - $this->logger->debug($ex->getMessage(), $this->loggerParams); - } - - return $this->feedMapper->find($feedId, $userId); - - } catch (DoesNotExistException $ex){ - throw new BusinessLayerException('Feed does not exist'); - } - } - - - /** - * Moves a feed into a different folder - * @param int $feedId the id of the feed that should be moved - * @param int $folderId the id of the folder where the feed should be moved to - * @param string $userId the name of the user whose feed should be moved - * @throws BusinessLayerException if the feed does not exist - */ - public function move($feedId, $folderId, $userId){ - $feed = $this->find($feedId, $userId); - $feed->setFolderId($folderId); - $this->feedMapper->update($feed); - } - - - /** - * Rename a feed - * @param int $feedId the id of the feed that should be moved - * @param string $feedTitle the new title of the feed - * @param string $userId the name of the user whose feed should be renamed - * @throws BusinessLayerException if the feed does not exist - */ - public function rename($feedId, $feedTitle, $userId) { - $feed = $this->find($feedId, $userId); - $feed->setTitle($feedTitle); - $this->feedMapper->update($feed); - } - - - /** - * Import articles - * @param array $json the array with json - * @param string userId the username - * @return Feed if one had to be created for nonexistent feeds - */ - public function importArticles($json, $userId) { - $url = 'http://owncloud/nofeed'; - $urlHash = md5($url); - - // build assoc array for fast access - $feeds = $this->findAll($userId); - $feedsDict = []; - foreach($feeds as $feed) { - $feedsDict[$feed->getLink()] = $feed; - } - - $createdFeed = false; - - // loop over all items and get the corresponding feed - // if the feed does not exist, create a seperate feed for them - foreach ($json as $entry) { - $item = Item::fromImport($entry); - $item->setLastModified($this->timeFactory->getTime()); - $feedLink = $entry['feedLink']; // this is not set on the item yet - - if(array_key_exists($feedLink, $feedsDict)) { - $feed = $feedsDict[$feedLink]; - $item->setFeedId($feed->getId()); - } elseif(array_key_exists($url, $feedsDict)) { - $feed = $feedsDict[$url]; - $item->setFeedId($feed->getId()); - } else { - $createdFeed = true; - $feed = new Feed(); - $feed->setUserId($userId); - $feed->setLink($url); - $feed->setUrl($url); - $feed->setTitle($this->l10n->t('Articles without feed')); - $feed->setAdded($this->timeFactory->getTime()); - $feed->setFolderId(0); - $feed->setPreventUpdate(true); - $feed = $this->feedMapper->insert($feed); - - $item->setFeedId($feed->getId()); - $feedsDict[$feed->getLink()] = $feed; - } - - try { - // if item exists, copy the status - $existingItem = $this->itemMapper->findByGuidHash( - $item->getGuidHash(), $feed->getId(), $userId); - $existingItem->setStatus($item->getStatus()); - $this->itemMapper->update($existingItem); - } catch(DoesNotExistException $ex){ - $item->setBody($this->purifier->purify($item->getBody())); - $this->itemMapper->insert($item); - } - } - - if($createdFeed) { - return $this->feedMapper->findByUrlHash($urlHash, $userId); - } - } - - - /** - * Use this to mark a feed as deleted. That way it can be undeleted - * @param int $feedId the id of the feed that should be deleted - * @param string $userId the name of the user for security reasons - * @throws BusinessLayerException when feed does not exist - */ - public function markDeleted($feedId, $userId) { - $feed = $this->find($feedId, $userId); - $feed->setDeletedAt($this->timeFactory->getTime()); - $this->feedMapper->update($feed); - } - - - /** - * Use this to undo a feed deletion - * @param int $feedId the id of the feed that should be restored - * @param string $userId the name of the user for security reasons - * @throws BusinessLayerException when feed does not exist - */ - public function unmarkDeleted($feedId, $userId) { - $feed = $this->find($feedId, $userId); - $feed->setDeletedAt(0); - $this->feedMapper->update($feed); - } - - - /** - * Deletes all deleted feeds - * @param string $userId if given it purges only feeds of that user - * @param boolean $useInterval defaults to true, if true it only purges - * entries in a given interval to give the user a chance to undo the - * deletion - */ - public function purgeDeleted($userId=null, $useInterval=true) { - $deleteOlderThan = null; - - if ($useInterval) { - $now = $this->timeFactory->getTime(); - $deleteOlderThan = $now - $this->autoPurgeMinimumInterval; - } - - $toDelete = $this->feedMapper->getToDelete($deleteOlderThan, $userId); - - foreach ($toDelete as $feed) { - $this->feedMapper->delete($feed); - } - } - - - /** - * Deletes all feeds of a user, delete items first since the user_id - * is not defined in there - * @param string $userId the name of the user - */ - public function deleteUser($userId) { - $this->feedMapper->deleteUser($userId); - } - - -} diff --git a/businesslayer/folderbusinesslayer.php b/businesslayer/folderbusinesslayer.php deleted file mode 100644 index f58e937b2..000000000 --- a/businesslayer/folderbusinesslayer.php +++ /dev/null @@ -1,173 +0,0 @@ -<?php -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\BusinessLayer; - -use \OCP\IL10N; - -use \OCA\News\Db\Folder; -use \OCA\News\Db\FolderMapper; -use \OCA\News\Utility\Config; - - -class FolderBusinessLayer extends BusinessLayer { - - private $l10n; - private $timeFactory; - private $autoPurgeMinimumInterval; - private $folderMapper; - - public function __construct(FolderMapper $folderMapper, - IL10N $l10n, - $timeFactory, - Config $config){ - parent::__construct($folderMapper); - $this->l10n = $l10n; - $this->timeFactory = $timeFactory; - $this->autoPurgeMinimumInterval = $config->getAutoPurgeMinimumInterval(); - $this->folderMapper = $folderMapper; - } - - /** - * Returns all folders of a user - * @param string $userId the name of the user - * @return array of folders - */ - public function findAll($userId) { - return $this->folderMapper->findAllFromUser($userId); - } - - - private function validateFolder($folderName, $userId){ - $existingFolders = $this->folderMapper->findByName($folderName, $userId); - if(count($existingFolders) > 0){ - - throw new BusinessLayerConflictException( - $this->l10n->t('Can not add folder: Exists already')); - } - - if(mb_strlen($folderName) === 0) { - throw new BusinessLayerValidationException('Folder name can not be empty'); - } - } - - - /** - * Creates a new folder - * @param string $folderName the name of the folder - * @param string $userId the name of the user for whom it should be created - * @param int $parentId the parent folder id, deprecated we dont nest folders - * @throws BusinessLayerConflictException if name exists already - * @throws BusinessLayerValidationException if the folder has invalid parameters - * @return Folder the newly created folder - */ - public function create($folderName, $userId, $parentId=0) { - $this->validateFolder($folderName, $userId); - - $folder = new Folder(); - $folder->setName($folderName); - $folder->setUserId($userId); - $folder->setParentId($parentId); - $folder->setOpened(true); - return $this->folderMapper->insert($folder); - } - - - /** - * @throws BusinessLayerException if the folder does not exist - */ - public function open($folderId, $opened, $userId){ - $folder = $this->find($folderId, $userId); - $folder->setOpened($opened); - $this->folderMapper->update($folder); - } - - - /** - * Renames a folder - * @param int $folderId the id of the folder that should be deleted - * @param string $folderName the new name of the folder - * @param string $userId the name of the user for security reasons - * @throws BusinessLayerConflictException if name exists already - * @throws BusinessLayerValidationException if the folder has invalid parameters - * @throws BusinessLayerException if the folder does not exist - * @return Folder the updated folder - */ - public function rename($folderId, $folderName, $userId){ - $this->validateFolder($folderName, $userId); - - $folder = $this->find($folderId, $userId); - $folder->setName($folderName); - return $this->folderMapper->update($folder); - } - - - /** - * Use this to mark a folder as deleted. That way it can be undeleted - * @param int $folderId the id of the folder that should be deleted - * @param string $userId the name of the user for security reasons - * @throws BusinessLayerException when folder does not exist - */ - public function markDeleted($folderId, $userId) { - $folder = $this->find($folderId, $userId); - $folder->setDeletedAt($this->timeFactory->getTime()); - $this->folderMapper->update($folder); - } - - - /** - * Use this to restore a folder - * @param int $folderId the id of the folder that should be restored - * @param string $userId the name of the user for security reasons - * @throws BusinessLayerException when folder does not exist - */ - public function unmarkDeleted($folderId, $userId) { - $folder = $this->find($folderId, $userId); - $folder->setDeletedAt(0); - $this->folderMapper->update($folder); - } - - - /** - * Deletes all deleted folders - * @param string $userId if given it purges only folders of that user - * @param boolean $useInterval defaults to true, if true it only purges - * entries in a given interval to give the user a chance to undo the - * deletion - */ - public function purgeDeleted($userId=null, $useInterval=true) { - $deleteOlderThan = null; - - if ($useInterval) { - $now = $this->timeFactory->getTime(); - $deleteOlderThan = $now - $this->autoPurgeMinimumInterval; - } - - $toDelete = $this->folderMapper->getToDelete($deleteOlderThan, $userId); - - foreach ($toDelete as $folder) { - $this->folderMapper->delete($folder); - } - } - - - /** - * Deletes all folders of a user - * @param string $userId the name of the user - */ - public function deleteUser($userId) { - $this->folderMapper->deleteUser($userId); - } - - -} diff --git a/businesslayer/itembusinesslayer.php b/businesslayer/itembusinesslayer.php deleted file mode 100644 index 82d445161..000000000 --- a/businesslayer/itembusinesslayer.php +++ /dev/null @@ -1,242 +0,0 @@ -<?php -/** - * ownCloud - News - * - * This file is licensed under the Affero General Public License version 3 or - * later. See the COPYING file. - * - * @author Alessandro Cosentino <cosenal@gmail.com> - * @author Bernhard Posselt <dev@bernhard-posselt.com> - * @copyright Alessandro Cosentino 2012 - * @copyright Bernhard Posselt 2012, 2014 - */ - -namespace OCA\News\BusinessLayer; - -use \OCP\AppFramework\Db\DoesNotExistException; - -use \OCA\News\Db\Item; -use \OCA\News\Db\ItemMapper; -use \OCA\News\Db\StatusFlag; -use \OCA\News\Db\FeedType; -use \OCA\News\Utility\Config; - - -class ItemBusinessLayer extends BusinessLayer { - - private $statusFlag; - private $autoPurgeCount; - private $timeFactory; - private $itemMapper; - - public function __construct(ItemMapper $itemMapper, - StatusFlag $statusFlag, - $timeFactory, - Config $config){ - parent::__construct($itemMapper); - $this->statusFlag = $statusFlag; - $this->autoPurgeCount = $config->getAutoPurgeCount(); - $this->timeFactory = $timeFactory; - $this->itemMapper = $itemMapper; - } - - - /** - * Returns all new items - * @param int $id the id of the feed, 0 for starred or all items - * @param int $type the type of the feed - * @param int $updatedSince a timestamp with the last modification date - * returns only items with a >= modified timestamp - * @param boolean $showAll if unread items should also be returned - * @param string $userId the name of the user - * @return array of items - */ - public function findAllNew($id, $type, $updatedSince, $showAll, $userId){ - $status = $this->statusFlag->typeToStatus($type, $showAll); - - switch($type){ - case FeedType::FEED: - return $this->itemMapper->findAllNewFeed( - $id, $updatedSince, $status, $userId - ); - case FeedType::FOLDER: - return $this->itemMapper->findAllNewFolder( - $id, $updatedSince, $status, $userId - ); - default: - return $this->itemMapper->findAllNew( - $updatedSince, $status, $userId - ); - } - } - - - /** - * Returns all items - * @param int $id the id of the feed, 0 for starred or all items - * @param int $type the type of the feed - * @param int $limit how many items should be returned - * @param int $offset only items lower than this id are returned, 0 for no offset - * @param boolean $showAll if unread items should also be returned - * @param string $userId the name of the user - * @param boolean $oldestFirst if it should be ordered by oldest first - * @return array of items - */ - public function findAll($id, $type, $limit, $offset, $showAll, $userId, - $oldestFirst=false){ - $status = $this->statusFlag->typeToStatus($type, $showAll); - - switch($type){ - case FeedType::FEED: - return $this->itemMapper->findAllFeed( - $id, $limit, $offset,$status, $userId, $oldestFirst - ); - case FeedType::FOLDER: - return $this->itemMapper->findAllFolder( - $id, $limit, $offset, $status, $userId, $oldestFirst - ); - default: - return $this->itemMapper->findAll( - $limit, $offset, $status, $userId, $oldestFirst - ); - } - } - - - /** - * Star or unstar an item - * @param int $feedId the id of the item's feed that should be starred - * @param string $guidHash the guidHash of the item that should be starred - * @param boolean $isStarred if true the item will be marked as starred, if false unstar - * @param $userId the name of the user for security reasons - * @throws BusinessLayerException if the item does not exist - */ - public function star($feedId, $guidHash, $isStarred, $userId){ - try { - $item = $this->itemMapper->findByGuidHash($guidHash, $feedId, $userId); - - $item->setLastModified($this->timeFactory->getTime()); - if($isStarred){ - $item->setStarred(); - } else { - $item->setUnstarred(); - } - $this->itemMapper->update($item); - } catch(DoesNotExistException $ex) { - throw new BusinessLayerException($ex->getMessage()); - } - } - - - /** - * Read or unread an item - * @param int $itemId the id of the item that should be read - * @param boolean $isRead if true the item will be marked as read, if false unread - * @param $userId the name of the user for security reasons - * @throws BusinessLayerException if the item does not exist - */ - public function read($itemId, $isRead, $userId){ - $item = $this->find($itemId, $userId); - $item->setLastModified($this->timeFactory->getTime()); - if($isRead){ - $item->setRead(); - } else { - $item->setUnread(); - } - $this->itemMapper->update($item); - } - - - /** - * Set all items read - * @param int $highestItemId all items below that are marked read. This is used - * to prevent marking items as read that the users hasnt seen yet - * @param string $userId the name of the user - */ - public function readAll($highestItemId, $userId){ - $time = $this->timeFactory->getTime(); - $this->itemMapper->readAll($highestItemId, $time, $userId); - } - - - /** - * Set a folder read - * @param int $folderId the id of the folder that should be marked read - * @param int $highestItemId all items below that are marked read. This is used - * to prevent marking items as read that the users hasnt seen yet - * @param string $userId the name of the user - */ - public function readFolder($folderId, $highestItemId, $userId){ - $time = $this->timeFactory->getTime(); - $this->itemMapper->readFolder($folderId, $highestItemId, $time, $userId); - } - - - /** - * Set a feed read - * @param int $feedId the id of the feed that should be marked read - * @param int $highestItemId all items below that are marked read. This is used< |