From 09f60e75c90e5734a3b11a0cca944bd42bc41665 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Wed, 11 Sep 2013 16:42:03 +0200 Subject: #342 implement export --- controller/exportcontroller.php | 39 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) (limited to 'controller') diff --git a/controller/exportcontroller.php b/controller/exportcontroller.php index 637219706..357c54d54 100644 --- a/controller/exportcontroller.php +++ b/controller/exportcontroller.php @@ -29,9 +29,11 @@ use \OCA\AppFramework\Controller\Controller; use \OCA\AppFramework\Core\API; use \OCA\AppFramework\Http\Request; use \OCA\AppFramework\Http\TextDownloadResponse; +use \OCA\AppFramework\Http\JSONResponse; use \OCA\News\BusinessLayer\FeedBusinessLayer; use \OCA\News\BusinessLayer\FolderBusinessLayer; +use \OCA\News\BusinessLayer\ItemBusinessLayer; use \OCA\News\Utility\OPMLExporter; class ExportController extends Controller { @@ -39,15 +41,18 @@ class ExportController extends Controller { private $opmlExporter; private $folderBusinessLayer; private $feedBusinessLayer; + private $itemBusinessLayer; public function __construct(API $api, Request $request, FeedBusinessLayer $feedBusinessLayer, FolderBusinessLayer $folderBusinessLayer, + ItemBusinessLayer $itemBusinessLayer, OPMLExporter $opmlExporter){ parent::__construct($api, $request); $this->feedBusinessLayer = $feedBusinessLayer; $this->folderBusinessLayer = $folderBusinessLayer; $this->opmlExporter = $opmlExporter; + $this->itemBusinessLayer = $itemBusinessLayer; } @@ -57,12 +62,40 @@ class ExportController extends Controller { * @CSRFExemption */ public function opml(){ - $user = $this->api->getUserId(); - $feeds = $this->feedBusinessLayer->findAll($user); - $folders = $this->folderBusinessLayer->findAll($user); + $userId = $this->api->getUserId(); + $feeds = $this->feedBusinessLayer->findAll($userId); + $folders = $this->folderBusinessLayer->findAll($userId); $opml = $this->opmlExporter->build($folders, $feeds)->saveXML(); return new TextDownloadResponse($opml, 'subscriptions.opml', 'text/xml'); } + /** + * @IsAdminExemption + * @IsSubAdminExemption + * @CSRFExemption + */ + public function articles(){ + $userId = $this->api->getUserId(); + $feeds = $this->feedBusinessLayer->findAll($userId); + $items = $this->itemBusinessLayer->getUnreadOrStarred($userId); + + // build assoc array for fast access + $feedsDict = array(); + foreach($feeds as $feed) { + $feedsDict['feed' . $feed->getId()] = $feed; + } + + $articles = array(); + foreach($items as $item) { + array_push($articles, $item->toExport($feedsDict)); + } + + $response = new JSONResponse($articles); + $response->addHeader('Content-Disposition', + 'attachment; filename="articles.json"'); + return $response; + } + + } \ No newline at end of file -- cgit v1.2.3