. * */ namespace OCA\News\Controller; use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; use \OCA\AppFramework\Db\DoesNotExistException; use \OCA\AppFramework\Db\MultipleObjectsReturnedException; use \OCA\News\Bl\FeedBl; use \OCA\News\Bl\BLException; class FeedController extends Controller { private $feedBl; public function __construct(API $api, Request $request, FeedBl $feedBl){ parent::__construct($api, $request); $this->feedBl = $feedBl; } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function feeds(){ $userId = $this->api->getUserId(); $result = $this->feedBl->findAllFromUser($userId); $params = array( 'feeds' => $result ); return $this->renderJSON($params); } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function active(){ $feedId = $this->api->getUserValue('lastViewedFeedId'); $feedType = $this->api->getUserValue('lastViewedFeedType'); $params = array( 'activeFeed' => array( 'id' => $feedId, 'type' => $feedType ) ); return $this->renderJSON($params); } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function create(){ $url = $this->params('url'); $parentFolderId = $this->params('parentFolderId'); $userId = $this->api->getUserId(); try { $feed = $this->feedBl->create($url, $parentFolderId, $userId); $params = array( 'feeds' => array($feed) ); return $this->renderJSON($params); } catch(BLException $ex) { return $this->renderJSON(array(), $ex->getMessage()); } } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function delete(){ $feedId = $this->params('feedId'); $userId = $this->api->getUserId(); $this->feedBl->delete($feedId, $userId); return $this->renderJSON(); } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function update(){ $feedId = $this->params('feedId'); $userId = $this->api->getUserId(); $feed = $this->feedBl->update($feedId, $userId); $params = array( 'feeds' => array($feed) ); return $this->renderJSON($params); } /** * @IsAdminExemption * @IsSubAdminExemption * @Ajax */ public function move(){ $feedId = $this->params('feedId'); $parentFolderId = $this->params('parentFolderId'); $userId = $this->api->getUserId(); $this->feedBl->move($feedId, $parentFolderId, $userId); return $this->renderJSON(); } }