diff options
Diffstat (limited to 'lib/Controller/ItemController.php')
-rw-r--r-- | lib/Controller/ItemController.php | 82 |
1 files changed, 52 insertions, 30 deletions
diff --git a/lib/Controller/ItemController.php b/lib/Controller/ItemController.php index 9c0801b1d..156f4d1d4 100644 --- a/lib/Controller/ItemController.php +++ b/lib/Controller/ItemController.php @@ -23,10 +23,8 @@ use \OCA\News\Service\ServiceNotFoundException; use \OCA\News\Service\ItemService; use \OCA\News\Service\FeedService; - class ItemController extends Controller { - use JSONHttpError; private $itemService; @@ -34,7 +32,8 @@ class ItemController extends Controller private $userId; private $settings; - public function __construct($appName, + public function __construct( + $appName, IRequest $request, FeedService $feedService, ItemService $itemService, @@ -61,31 +60,45 @@ class ItemController extends Controller * @param string $search * @return array */ - public function index($type=3, $id=0, $limit=50, $offset=0, $showAll=null, - $oldestFirst=null, $search='' + public function index( + $type = 3, + $id = 0, + $limit = 50, + $offset = 0, + $showAll = null, + $oldestFirst = null, + $search = '' ) { // in case this is called directly and not from the website use the // internal state if ($showAll === null) { $showAll = $this->settings->getUserValue( - $this->userId, $this->appName, 'showAll' + $this->userId, + $this->appName, + 'showAll' ) === '1'; } if ($oldestFirst === null) { $oldestFirst = $this->settings->getUserValue( - $this->userId, $this->appName, 'oldestFirst' + $this->userId, + $this->appName, + 'oldestFirst' ) === '1'; } $this->settings->setUserValue( - $this->userId, $this->appName, - 'lastViewedFeedId', $id + $this->userId, + $this->appName, + 'lastViewedFeedId', + $id ); $this->settings->setUserValue( - $this->userId, $this->appName, - 'lastViewedFeedType', $type + $this->userId, + $this->appName, + 'lastViewedFeedType', + $type ); $params = []; @@ -100,11 +113,10 @@ class ItemController extends Controller } try { - // the offset is 0 if the user clicks on a new feed // we need to pass the newest feeds to not let the unread count get // out of sync - if($offset === 0) { + if ($offset === 0) { $params['newestItemId'] = $this->itemService->getNewestItemId($this->userId); $params['feeds'] = $this->feedService->findAll($this->userId); @@ -113,13 +125,19 @@ class ItemController extends Controller } $params['items'] = $this->itemService->findAll( - $id, $type, $limit, $offset, $showAll, $oldestFirst, - $this->userId, $search + $id, + $type, + $limit, + $offset, + $showAll, + $oldestFirst, + $this->userId, + $search ); // this gets thrown if there are no items // in that case just return an empty array - } catch(ServiceException $ex) { + } catch (ServiceException $ex) { } return $params; @@ -134,10 +152,11 @@ class ItemController extends Controller * @param int $lastModified * @return array */ - public function newItems($type, $id, $lastModified=0) + public function newItems($type, $id, $lastModified = 0) { $showAll = $this->settings->getUserValue( - $this->userId, $this->appName, + $this->userId, + $this->appName, 'showAll' ) === '1'; @@ -150,13 +169,16 @@ class ItemController extends Controller $params['starred'] = $this->itemService->starredCount($this->userId); $params['items'] = $this->itemService->findAllNew( - $id, $type, - $lastModified, $showAll, $this->userId + $id, + $type, + $lastModified, + $showAll, + $this->userId ); // this gets thrown if there are no items // in that case just return an empty array - } catch(ServiceException $ex) { + } catch (ServiceException $ex) { } return $params; @@ -175,10 +197,12 @@ class ItemController extends Controller { try { $this->itemService->star( - $feedId, $guidHash, $isStarred, + $feedId, + $guidHash, + $isStarred, $this->userId ); - } catch(ServiceException $ex) { + } catch (ServiceException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -193,11 +217,11 @@ class ItemController extends Controller * @param bool $isRead * @return array|\OCP\AppFramework\Http\JSONResponse */ - public function read($itemId, $isRead=true) + public function read($itemId, $isRead = true) { try { $this->itemService->read($itemId, $isRead, $this->userId); - } catch(ServiceException $ex) { + } catch (ServiceException $ex) { return $this->error($ex, Http::STATUS_NOT_FOUND); } @@ -223,16 +247,14 @@ class ItemController extends Controller * * @param int[] item ids */ - public function readMultiple($itemIds) + public function readMultiple($itemIds) { - foreach($itemIds as $id) { + foreach ($itemIds as $id) { try { $this->itemService->read($id, true, $this->userId); - } catch(ServiceNotFoundException $ex) { + } catch (ServiceNotFoundException $ex) { continue; } } } - - } |