. * */ namespace OCA\News\Controller; use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; use \OCA\News\BusinessLayer\ItemBusinessLayer; class ItemController extends Controller { private $itemBusinessLayer; public function __construct(API $api, Request $request, ItemBusinessLayer $itemBusinessLayer){ parent::__construct($api, $request); $this->itemBusinessLayer = $itemBusinessLayer; } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function items(){ $userId = $this->api->getUserId(); $showAll = $this->api->getUserValue('showAll') === '1'; $limit = $this->params('limit'); $type = (int) $this->params('type'); $id = (int) $this->params('id'); $this->api->setUserValue('lastViewedFeedId', $id); $this->api->setUserValue('lastViewedFeedType', $type); if($limit !== null){ $offset = (int) $this->params('offset', 0); $items = $this->itemBusinessLayer->findAll($id, $type, (int) $limit, $offset, $showAll, $userId); } else { $updatedSince = (int) $this->params('updatedSince'); $items = $this->itemBusinessLayer->findAllNew($id, $type, $updatedSince, $showAll, $userId); } $params = array( 'items' => $items ); return $this->renderJSON($params); } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function starred(){ $userId = $this->api->getUserId(); $starredCount = $this->itemBusinessLayer->starredCount($userId); $params = array( 'starred' => (int) $starredCount ); return $this->renderJSON($params); } private function setStarred($isStarred){ $userId = $this->api->getUserId(); $feedId = (int) $this->params('feedId'); $guidHash = $this->params('guidHash'); $this->itemBusinessLayer->star($feedId, $guidHash, $isStarred, $userId); } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function star(){ $this->setStarred(true); return $this->renderJSON(); } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function unstar(){ $this->setStarred(false); return $this->renderJSON(); } private function setRead($isRead){ $userId = $this->api->getUserId(); $itemId = (int) $this->params('itemId'); $this->itemBusinessLayer->read($itemId, $isRead, $userId); } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function read(){ $this->setRead(true); return $this->renderJSON(); } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function unread(){ $this->setRead(false); return $this->renderJSON(); } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function readFeed(){ $userId = $this->api->getUserId(); $feedId = (int) $this->params('feedId'); $highestItemId = (int) $this->params('highestItemId'); $this->itemBusinessLayer->readFeed($feedId, $highestItemId, $userId); return $this->renderJSON(); } }