summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appinfo/bootstrap.php11
-rw-r--r--appinfo/routes.php3
-rw-r--r--db/feed.php2
-rw-r--r--db/feedmapper.php5
-rw-r--r--db/folder.php13
-rw-r--r--db/itemmapper.php4
-rw-r--r--external_api/feed.php12
-rw-r--r--external_api/folder.php14
-rw-r--r--feed.bl.php6
-rw-r--r--folder.bl.php6
10 files changed, 60 insertions, 16 deletions
diff --git a/appinfo/bootstrap.php b/appinfo/bootstrap.php
index c7ce8fb62..10ddeadc6 100644
--- a/appinfo/bootstrap.php
+++ b/appinfo/bootstrap.php
@@ -2,7 +2,7 @@
/**
* ownCloud - News app
*
-* @author Alessandro Copyright
+* @author Alessandro Cosentino
* @author Bernhard Posselt
* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
@@ -126,13 +126,14 @@ function createDIContainer(){
/**
* EXTERNAL API LAYER
*/
- $newsContainer['API_Feed'] = $newsContainer->share(function($c){
- return new API_($c['FolderMapper']);
+ $newsContainer['API_Folder'] = $newsContainer->share(function($c){
+ return new API_Folder($c['FolderBL']);
});
- $newsContainer['API_Folder'] = $newsContainer->share(function($c){
- return new FeedBL($c['FeedMapper']);
+ $newsContainer['API_Feed'] = $newsContainer->share(function($c){
+ return new API_Feed($c['FeedBL']);
});
+
return $newsContainer;
} \ No newline at end of file
diff --git a/appinfo/routes.php b/appinfo/routes.php
index 66dedd7f0..0370ecb93 100644
--- a/appinfo/routes.php
+++ b/appinfo/routes.php
@@ -222,4 +222,7 @@ $this->create('news_ajax_importOPML', '/import')->action(
*/
\OCP\API::register(
'get', '/news/folders', array('OCA\News\API_Folder', 'getAll'), 'news', \OC_API::USER_AUTH
+);
+\OCP\API::register(
+ 'post', '/news/folders/create', array('OCA\News\API_Folder', 'create'), 'news', \OC_API::USER_AUTH
); \ No newline at end of file
diff --git a/db/feed.php b/db/feed.php
index 8ab772ab9..eda225302 100644
--- a/db/feed.php
+++ b/db/feed.php
@@ -25,7 +25,7 @@ class Feed extends Collection {
// if $items = null, it means that feed has not been fetched yet
// if $id = null, it means that the feed has not been stored in the db yet
- public function __construct($url, $title, $items = null, $id = null) {
+ public function __construct($url, $title = null, $items = null, $id = null) {
$this->url = $url;
$this->title = $title;
if ($items !== null) {
diff --git a/db/feedmapper.php b/db/feedmapper.php
index 906ced069..62a7d41f5 100644
--- a/db/feedmapper.php
+++ b/db/feedmapper.php
@@ -163,10 +163,10 @@ class FeedMapper {
*/
//TODO: handle error case
public function save(Feed $feed, $folderid) {
- $title = $feed->getTitle();
$url = $feed->getUrl();
$url_hash = md5($url);
+ $title = $feed->getTitle();
if(empty($title)) {
$l = \OC_L10N::get('news');
$title = $l->t('no title');
@@ -199,11 +199,12 @@ class FeedMapper {
//update the db. it needs to be done, since it might be the first save after a full fetch
$stmt = \OCP\DB::prepare('
UPDATE ' . self::tableName .
- ' SET favicon_link = ? , lastmodified = UNIX_TIMESTAMP() , folder_id = ?
+ ' SET title = ? , favicon_link = ? , lastmodified = UNIX_TIMESTAMP() , folder_id = ?
WHERE id = ?
');
$params=array(
+ $title,
$favicon,
$folderid,
$feedid
diff --git a/db/folder.php b/db/folder.php
index 23d33737f..5dfa738f3 100644
--- a/db/folder.php
+++ b/db/folder.php
@@ -51,6 +51,12 @@ class Folder extends Collection {
public function setOpened($opened) {
$this->opened = $opened;
}
+
+ public function setParentId() {
+ if ($this->parent !== null) {
+
+ }
+ }
public function getParentId() {
if ($this->parent === null) {
@@ -73,7 +79,12 @@ class Folder extends Collection {
public function jsonSerialize() {
//TODO: this is just for test
- return $this->name;
+ $encoding = array(
+ 'id' => $this->getId(),
+ 'parentId' => $this->getParentId(),
+ 'title' => $this->getName(),
+ );
+ return $encoding;
}
} \ No newline at end of file
diff --git a/db/itemmapper.php b/db/itemmapper.php
index 3399e2e03..3791c3a49 100644
--- a/db/itemmapper.php
+++ b/db/itemmapper.php
@@ -355,7 +355,7 @@ class ItemMapper {
break;
case FeedType::FOLDER:
- $feedMapper = new FeedMapper($this->userId);
+ $feedMapper = new FeedMapper($this->userid);
$feeds = $feedMapper->findByFolderId($feedId);
foreach($feeds as $feed){
$unreadCount += $this->countAllStatus($feed->getId(), StatusFlag::UNREAD);
@@ -405,7 +405,7 @@ class ItemMapper {
// folder
} elseif ($feedType === FeedType::FOLDER){
- $feedMapper = new FeedMapper($this->userId);
+ $feedMapper = new FeedMapper($this->userid);
$feeds = $feedMapper->findByFolderId($feedId);
foreach($feeds as $feed){
diff --git a/external_api/feed.php b/external_api/feed.php
index dba518b7a..fcdfd2c7f 100644
--- a/external_api/feed.php
+++ b/external_api/feed.php
@@ -6,6 +6,10 @@ use \OCA\News\Controller\FeedController;
class API_Feed {
+// public __construct($feedbl) {
+// $this->bl = $feedbl;
+// }
+
public static function getAll() {
$container = createDIContainer();
$bl = $container['FeedBL'];
@@ -17,7 +21,7 @@ class API_Feed {
return new \OC_OCS_Result($serializedFeeds);
}
- public static function getById($parameters) {
+ public function getById($parameters) {
$feedid = $parameters['feedid'];
$container = createDIContainer();
$bl = $container['FeedBL'];
@@ -29,17 +33,17 @@ class API_Feed {
public static function create() {
$url = $_POST['url'];
- $folderId = $_POST['folderId'];
+ $folderId = $_POST['folderid'];
$container = createDIContainer();
$bl = $container['FeedBL'];
$success = $bl->create($url, $folderId);
if ($success) {
- return new OC_OCS_Result();
+ return new \OC_OCS_Result();
}
else {
- return new OC_OCS_Result(null, 101);
+ return new \OC_OCS_Result(null, 101);
}
}
}
diff --git a/external_api/folder.php b/external_api/folder.php
index e2bbeb870..f9dae7535 100644
--- a/external_api/folder.php
+++ b/external_api/folder.php
@@ -11,10 +11,24 @@ class API_Folder {
$bl = $container['FolderBL'];
$folders = $bl->getAll();
$serializedFolders = array();
+
+ //TODO: check the behaviour for nested folders
foreach ($folders as $folder) {
$serializedFolders[] = $folder->jsonSerialize();
}
return new \OC_OCS_Result($serializedFolders);
}
+
+ public static function create() {
+
+ $name = $_POST['name'];
+ $parentId = $_POST['parentid'];
+
+ $container = createDIContainer();
+ $bl = $container['FolderBL'];
+ $bl->create($name, $parentId);
+
+ return new \OC_OCS_Result();
+ }
}
diff --git a/feed.bl.php b/feed.bl.php
index c18b5a50b..30dc5f4c3 100644
--- a/feed.bl.php
+++ b/feed.bl.php
@@ -17,8 +17,12 @@ class FeedBL {
}
public function create($url, $folderid) {
- $feed = \OC_News_Utils::fetch($url);
+ $feed = new Feed($url);
$this->feedMapper->save($feed, $folderid);
+ $feed = Utils::fetch($url);
+ if ($feed != null) {
+ $this->feedMapper->save($feed, $folderid);
+ }
return true;
}
diff --git a/folder.bl.php b/folder.bl.php
index ff1164c28..4bc0f45ab 100644
--- a/folder.bl.php
+++ b/folder.bl.php
@@ -11,4 +11,10 @@ class FolderBL {
public function getAll() {
return $this->folderMapper->getAll();
}
+
+ public function create($name, $parentId) {
+ //TODO: change the setparentid in the model class Folder
+ $folder = new Folder($name, null, null);
+ return $this->folderMapper->save($folder);
+ }
}