diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2012-10-13 02:21:36 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2012-10-13 02:21:47 +0200 |
commit | dfcf639f2f7b6eaf82c48dd503f7c98ce9d2155e (patch) | |
tree | 603e257c5a60ec7b126b2e8716383d83052e26a8 /controllers/news.controller.php | |
parent | 8fd373e8d5194e315f840fe654b7031979910e88 (diff) |
refactored index php into controllers
Diffstat (limited to 'controllers/news.controller.php')
-rw-r--r-- | controllers/news.controller.php | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/controllers/news.controller.php b/controllers/news.controller.php new file mode 100644 index 000000000..f01022104 --- /dev/null +++ b/controllers/news.controller.php @@ -0,0 +1,108 @@ +<?php +/** +* ownCloud - News app +* +* @author Bernhard Posselt +* Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com> +* +* This file is licensed under the Affero General Public License version 3 or later. +* See the COPYING-README file +* +*/ + +namespace OCA\News; + + +class FeedType { + const FEED = 0; + const FOLDER = 1; + const STARRED = 2; + const SUBSCRIPTIONS = 3; +} + + +class NewsController extends Controller { + + + /** + * Decides wether to show the feedpage or the firstrun page + */ + public function index(){ + $feedMapper = new FeedMapper($this->userId); + + if($feedMapper->feedCount() > 0){ + $this->feedPage(); + } else { + $this->firstRun(); + } + } + + + public function firstRun(){ + $this->addScript('news'); + $this->addScript('firstrun'); + $this->addStyle('firstrun'); + $this->render('firstrun'); + } + + + public function feedPage(){ + $this->addScript('main'); + $this->addScript('news'); + $this->addScript('menu'); + $this->addScript('items'); + $this->add3rdPartyScript('jquery.timeago'); + + $this->addStyle('news'); + $this->addStyle('settings'); + + $folderMapper = new FolderMapper($this->userId); + $feedMapper = new FeedMapper($this->userId); + + // always show the last viewed feed on reload + $lastViewedId = $this->getUserValue('lastViewedFeed'); + $lastViewedType = $this->getUserValue('lastViewedFeedType'); + + if( $lastViewedId === null || $lastViewedType === null) { + $lastViewedId = $feedMapper->mostRecent(); + } else { + // check if the last selected feed or folder exists + if( ( + $feedMapper->findById($lastViewedId) === null && + $lastViewedType === FeedType::FEED + ) || + ( + $folderMapper->findById($lastViewedId) === null && + $lastViewedType === FeedType::FOLDER + ) ){ + $lastViewedId = $feedMapper->mostRecent(); + } + } + + $feeds = $folderMapper->childrenOfWithFeeds(0); + $folderForest = $folderMapper->childrenOf(0); //retrieve all the folders + + $params = array( + 'allfeeds' => $feeds, + 'folderforest' => $folderForest, + 'lastViewedId' => $lastViewedType, + 'lastViewedType' => $lastViewedType, + // for compability, remove this after refactoring + 'feedid' => $lastViewedId, + 'feedtype' => $lastViewedType, + ); + + $this->render('main', $params); + } + + + public function javascriptTests(){ + $this->add3rdPartyScript('jasmine-1.2.0/jasmine.js'); + $this->add3rdPartyStyle('jasmine-1.2.0/jasmine.css'); + $this->render('javascript.tests'); + } + + +} + +?>
\ No newline at end of file |