summaryrefslogtreecommitdiffstats
path: root/controllers
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2012-10-13 02:21:36 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2012-10-13 02:21:47 +0200
commitdfcf639f2f7b6eaf82c48dd503f7c98ce9d2155e (patch)
tree603e257c5a60ec7b126b2e8716383d83052e26a8 /controllers
parent8fd373e8d5194e315f840fe654b7031979910e88 (diff)
refactored index php into controllers
Diffstat (limited to 'controllers')
-rw-r--r--controllers/controller.php92
-rw-r--r--controllers/news.controller.php108
2 files changed, 200 insertions, 0 deletions
diff --git a/controllers/controller.php b/controllers/controller.php
new file mode 100644
index 000000000..89037b263
--- /dev/null
+++ b/controllers/controller.php
@@ -0,0 +1,92 @@
+<?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 Controller {
+
+ protected $userId;
+ protected $trans;
+
+
+ public function __construct(){
+ $this->userId = \OCP\USER::getUser();
+ $this->trans = \OC_L10N::get('news');
+ }
+
+
+ protected function addScript($name){
+ \OCP\Util::addScript('news', $name);
+ }
+
+
+ protected function addStyle($name){
+ \OCP\Util::addStyle('news', $name);
+ }
+
+
+ protected function add3rdPartyScript($name){
+ \OCP\Util::addScript('news/3rdparty', $name);
+ }
+
+
+ protected function add3rdPartyStyle($name){
+ \OCP\Util::addStyle('news/3rdparty', $name);
+ }
+
+
+ /**
+ * Shortcut for setting a user defined value
+ * @param $key the key under which the value is being stored
+ * @param $value the value that you want to store
+ */
+ protected function setUserValue($key, $value){
+ \OCP\Config::setUserValue($this->userId, 'news', $key, $value);
+ }
+
+
+ /**
+ * Shortcut for getting a user defined value
+ * @param $key the key under which the value is being stored
+ */
+ protected function getUserValue($key){
+ return \OCP\Config::getUserValue($this->userId, 'news', $key);
+ }
+
+
+ /**
+ * Binds variables to the template and prints it
+ * The following values are always assigned: userId
+ * @param $arguments an array with arguments in $templateVar => $content
+ * @param $template the name of the template
+ * @param $fullPage if true, it will render a full page, otherwise only a part
+ * defaults to true
+ */
+ protected function render($template, $arguments=array(), $fullPage=true){
+
+ if($fullPage){
+ $template = new \OCP\Template('news', $template, 'user');
+ } else {
+ $template = new \OCP\Template('news', $template);
+ }
+
+ foreach($arguments as $key => $value){
+ $template->assign($key, $value);
+ }
+
+ $template->assign('userId', $this->userId);
+ $template->printPage();
+ }
+
+}
+
+?> \ No newline at end of file
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