summaryrefslogtreecommitdiffstats
path: root/lib/Controller/FeedController.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Controller/FeedController.php')
-rw-r--r--lib/Controller/FeedController.php123
1 files changed, 72 insertions, 51 deletions
diff --git a/lib/Controller/FeedController.php b/lib/Controller/FeedController.php
index fecd58398..cf323b58e 100644
--- a/lib/Controller/FeedController.php
+++ b/lib/Controller/FeedController.php
@@ -5,10 +5,10 @@
* 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
+ * @author Alessandro Cosentino <cosenal@gmail.com>
+ * @author Bernhard Posselt <dev@bernhard-posselt.com>
+ * @copyright 2012 Alessandro Cosentino
+ * @copyright 2012-2014 Bernhard Posselt
*/
namespace OCA\News\Controller;
@@ -26,7 +26,8 @@ use OCA\News\Service\ServiceConflictException;
use OCA\News\Db\FeedType;
-class FeedController extends Controller {
+class FeedController extends Controller
+{
use JSONHttpError;
@@ -36,14 +37,15 @@ class FeedController extends Controller {
private $userId;
private $settings;
- public function __construct($AppName,
- IRequest $request,
- FolderService $folderService,
- FeedService $feedService,
- ItemService $itemService,
- IConfig $settings,
- $UserId){
- parent::__construct($AppName, $request);
+ public function __construct($appName,
+ IRequest $request,
+ FolderService $folderService,
+ FeedService $feedService,
+ ItemService $itemService,
+ IConfig $settings,
+ $UserId
+ ) {
+ parent::__construct($appName, $request);
$this->feedService = $feedService;
$this->folderService = $folderService;
$this->itemService = $itemService;
@@ -55,7 +57,8 @@ class FeedController extends Controller {
/**
* @NoAdminRequired
*/
- public function index(){
+ public function index()
+ {
// this method is also used to update the interface
// because of this we also pass the starred count and the newest
@@ -69,9 +72,10 @@ class FeedController extends Controller {
$params['newestItemId'] =
$this->itemService->getNewestItemId($this->userId);
- // An exception occurs if there is a newest item. If there is none,
- // simply ignore it and do not add the newestItemId
- } catch (ServiceNotFoundException $ex) {}
+ // An exception occurs if there is a newest item. If there is none,
+ // simply ignore it and do not add the newestItemId
+ } catch (ServiceNotFoundException $ex) {
+ }
return $params;
}
@@ -80,27 +84,32 @@ class FeedController extends Controller {
/**
* @NoAdminRequired
*/
- public function active(){
- $feedId = (int) $this->settings->getUserValue($this->userId,
- $this->appName,'lastViewedFeedId');
- $feedType = $this->settings->getUserValue($this->userId, $this->appName,
- 'lastViewedFeedType');
+ public function active()
+ {
+ $feedId = (int) $this->settings->getUserValue(
+ $this->userId,
+ $this->appName, 'lastViewedFeedId'
+ );
+ $feedType = $this->settings->getUserValue(
+ $this->userId, $this->appName,
+ 'lastViewedFeedType'
+ );
// cast from null to int is 0
- if($feedType !== null){
+ if($feedType !== null) {
$feedType = (int) $feedType;
}
// check if feed or folder exists
try {
- if($feedType === FeedType::FOLDER){
+ if($feedType === FeedType::FOLDER) {
$this->folderService->find($feedId, $this->userId);
- } elseif ($feedType === FeedType::FEED){
+ } elseif ($feedType === FeedType::FEED) {
$this->feedService->find($feedId, $this->userId);
- // if its the first launch, those values will be null
- } elseif($feedType === null){
+ // if its the first launch, those values will be null
+ } elseif($feedType === null) {
throw new ServiceNotFoundException('');
}
@@ -122,31 +131,35 @@ class FeedController extends Controller {
* @NoAdminRequired
*
* @param string $url
- * @param int $parentFolderId
+ * @param int $parentFolderId
* @param string $title
* @param string $user
* @param string $password
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
public function create($url, $parentFolderId, $title=null,
- $user=null, $password=null){
+ $user=null, $password=null
+ ) {
try {
// we need to purge deleted feeds if a feed is created to
// prevent already exists exceptions
$this->feedService->purgeDeleted($this->userId, false);
- $feed = $this->feedService->create($url, $parentFolderId,
- $this->userId, $title,
- $user, $password);
+ $feed = $this->feedService->create(
+ $url, $parentFolderId,
+ $this->userId, $title,
+ $user, $password
+ );
$params = ['feeds' => [$feed]];
try {
$params['newestItemId'] =
$this->itemService->getNewestItemId($this->userId);
- // An exception occurs if there is a newest item. If there is none,
- // simply ignore it and do not add the newestItemId
- } catch (ServiceNotFoundException $ex) {}
+ // An exception occurs if there is a newest item. If there is none,
+ // simply ignore it and do not add the newestItemId
+ } catch (ServiceNotFoundException $ex) {
+ }
return $params;
@@ -165,7 +178,8 @@ class FeedController extends Controller {
* @param int $feedId
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
- public function delete($feedId){
+ public function delete($feedId)
+ {
try {
$this->feedService->markDeleted($feedId, $this->userId);
} catch(ServiceNotFoundException $ex) {
@@ -182,7 +196,8 @@ class FeedController extends Controller {
* @param int $feedId
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
- public function update($feedId){
+ public function update($feedId)
+ {
try {
$feed = $this->feedService->update($feedId, $this->userId);
@@ -210,7 +225,8 @@ class FeedController extends Controller {
* @param array $json
* @return array
*/
- public function import($json) {
+ public function import($json)
+ {
$feed = $this->feedService->importArticles($json, $this->userId);
$params = [
@@ -232,7 +248,8 @@ class FeedController extends Controller {
* @param int $highestItemId
* @return array
*/
- public function read($feedId, $highestItemId){
+ public function read($feedId, $highestItemId)
+ {
$this->itemService->readFeed($feedId, $highestItemId, $this->userId);
return [
@@ -252,7 +269,8 @@ class FeedController extends Controller {
* @param int $feedId
* @return array|\OCP\AppFramework\Http\JSONResponse
*/
- public function restore($feedId){
+ public function restore($feedId)
+ {
try {
$this->feedService->unmarkDeleted($feedId, $this->userId);
} catch(ServiceNotFoundException $ex) {
@@ -265,17 +283,18 @@ class FeedController extends Controller {
/**
* @NoAdminRequired
*
- * @param int $feedId
- * @param bool $pinned
- * @param bool $fullTextEnabled
- * @param int $updateMode
- * @param int $ordering
- * @param int $folderId
+ * @param int $feedId
+ * @param bool $pinned
+ * @param bool $fullTextEnabled
+ * @param int $updateMode
+ * @param int $ordering
+ * @param int $folderId
* @param string $title
*/
public function patch($feedId, $pinned=null, $fullTextEnabled=null,
- $updateMode=null, $ordering=null, $title=null,
- $folderId=null) {
+ $updateMode=null, $ordering=null, $title=null,
+ $folderId=null
+ ) {
$attributes = [
'pinned' => $pinned,
'fullTextEnabled' => $fullTextEnabled,
@@ -285,9 +304,11 @@ class FeedController extends Controller {
'folderId' => $folderId
];
- $diff = array_filter($attributes, function ($value) {
- return $value !== null;
- });
+ $diff = array_filter(
+ $attributes, function ($value) {
+ return $value !== null;
+ }
+ );
try {
$this->feedService->patch($feedId, $this->userId, $diff);