From e583df60d3c77d4e7f64a889b8951907c594b922 Mon Sep 17 00:00:00 2001 From: Alessandro Cosentino Date: Thu, 7 Jun 2012 16:19:25 -0400 Subject: creates a superclass collection for feeds and folders --- appinfo/app.php | 1 + index.php | 6 ++++++ lib/feed.php | 11 +---------- lib/folder.php | 24 ++++++++---------------- lib/foldermapper.php | 13 ++++++------- templates/main.php | 2 +- 6 files changed, 23 insertions(+), 34 deletions(-) diff --git a/appinfo/app.php b/appinfo/app.php index 6fcd7a146..08eb32627 100644 --- a/appinfo/app.php +++ b/appinfo/app.php @@ -22,6 +22,7 @@ */ OC::$CLASSPATH['OC_News_Item'] = 'apps/news/lib/item.php'; +OC::$CLASSPATH['OC_News_Collection'] = 'apps/news/lib/collection.php'; OC::$CLASSPATH['OC_News_Feed'] = 'apps/news/lib/feed.php'; OC::$CLASSPATH['OC_News_Folder'] = 'apps/news/lib/folder.php'; diff --git a/index.php b/index.php index 44dc7102f..064b1167c 100644 --- a/index.php +++ b/index.php @@ -37,7 +37,13 @@ OCP\App::setActiveNavigationEntry('news'); //OCP\Util::addscript('news','news'); OCP\Util::addStyle('news', 'news'); +$foldermapper = new OC_News_FolderMapper(); + +//this is the root folder, which contains all sub-folders and feeds +$allfeeds = null; + $tmpl = new OCP\Template( 'news', 'main', 'user' ); +$tmpl->assign('allfeeds', $allfeeds); $tmpl->printPage(); ?> diff --git a/lib/feed.php b/lib/feed.php index 311068463..870fd64f6 100644 --- a/lib/feed.php +++ b/lib/feed.php @@ -23,10 +23,9 @@ /** * This class models a feed. */ -class OC_News_Feed { +class OC_News_Feed extends OC_News_Collection { private $url; - private $id; //id of the feed in the database private $spfeed; //encapsulate a SimplePie_Core object private $items; //array that contains all the items of the feed @@ -39,14 +38,6 @@ class OC_News_Feed { } } - public function getId(){ - return $this->id; - } - - public function setId($id){ - $this->id = $id; - } - public function getUrl(){ return $this->url; } diff --git a/lib/folder.php b/lib/folder.php index 6c7c4c2f5..2bdc1fb78 100644 --- a/lib/folder.php +++ b/lib/folder.php @@ -23,18 +23,18 @@ /** * This class models a folder that contains feeds. */ -class OC_News_Folder { +class OC_News_Folder extends OC_News_Collection { private $name; - private $id; - private $feeds; private $children; private $parent; public function __construct($name, $parent = null){ $this->name = $name; - $this->parent = $parent; - $this->feeds = array(); + $this->children = array(); + if ($parent !== null){ + $this->parent = $parent; + } } public function getName(){ @@ -45,23 +45,15 @@ class OC_News_Folder { $this->name = $name; } - public function getId(){ - return $this->id; - } - - public function setId($id){ - $this->id = $id; - } - public function getParentId(){ - if ($this->parent == null){ + if ($this->parent === null){ return 0; } return $this->parent->getId(); } - public function addFeed(OC_News_Feed $feed){ - $this->feeds[] = $feed; + public function addChild(OC_News_Collection $child){ + $this->children[] = $child; } } \ No newline at end of file diff --git a/lib/foldermapper.php b/lib/foldermapper.php index e9de89341..f4ff6239b 100644 --- a/lib/foldermapper.php +++ b/lib/foldermapper.php @@ -27,19 +27,18 @@ class OC_News_FolderMapper { const tableName = '*PREFIX*news_folders'; + public function root(){ + $root = new OC_News_Folder('All feeds'); + + return $root; + } + /** * @brief Retrieve a feed from the database * @param id The id of the feed in the database table. * @returns */ public function find($id){ - $stmt = OCP\DB::prepare('SELECT * FROM ' . self::tableName . ' WHERE id = ?'); - $result = $stmt->execute(array($id)); - $row = $result->fetchRow(); - $url = $row['url']; - $title = $row['title']; - $feed = new OC_News_Feed($url, $title, null, $id); - return $feed; } /** diff --git a/templates/main.php b/templates/main.php index 5102b48a4..6405055ec 100644 --- a/templates/main.php +++ b/templates/main.php @@ -1,6 +1,6 @@
-- cgit v1.2.3