prototype for business layer for feed

This commit is contained in:
Alessandro Cosentino 2013-03-02 19:50:33 +01:00
Родитель 165540d346
Коммит 4902253e9c
11 изменённых файлов: 128 добавлений и 15 удалений

Просмотреть файл

@ -47,8 +47,10 @@ namespace OCA\News;
\OC::$CLASSPATH['OCA\News\NewsAjaxController'] = 'apps/news/controller/news.ajax.controller.php';
\OC::$CLASSPATH['OCA\News\FolderBL'] = 'apps/news/folder.bl.php';
\OC::$CLASSPATH['OCA\News\FeedBL'] = 'apps/news/feed.bl.php';
\OC::$CLASSPATH['OCA\News\API_Folder'] = 'apps/news/external_api/folder.php';
\OC::$CLASSPATH['OCA\News\API_Feed'] = 'apps/news/external_api/feed.php';
/**
@ -113,9 +115,14 @@ function createDIContainer(){
/**
* BUSINESS LAYER OBJECTS
*/
$newsContainer['FolderBL'] = function($c){
$newsContainer['FolderBL'] = $newsContainer->share(function($c){
return new FolderBL($c['FolderMapper']);
};
});
$newsContainer['FeedBL'] = $newsContainer->share(function($c){
return new FeedBL($c['FeedMapper']);
});
return $newsContainer;
}

Просмотреть файл

@ -203,12 +203,12 @@ $this->create('news_ajax_importOPML', '/import')->action(
/**
* External API for folders
* External API
*/
\OCP\API::register(
'get',
'/news/folders',
array('OCA\News\API_Folder ', 'getAll'),
'news',
\OC_API::USER_AUTH
'get', '/news/feeds', array('OCA\News\API_Feed', 'getAll'), 'news', \OC_API::USER_AUTH
);
\OCP\API::register(
'get', '/news/folders', array('OCA\News\API_Folder', 'getAll'), 'news', \OC_API::USER_AUTH
);

Просмотреть файл

@ -0,0 +1,55 @@
<?php
/**
* ownCloud - News
*
* @author Alessandro Cosentino
* @author Bernhard Posselt
* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\News\Controller;
use \OCA\AppFramework\Controller\Controller;
use \OCA\AppFramework\Core\API;
use \OCA\AppFramework\Http\Request;
use \OCA\AppFramework\Db\DoesNotExistException;
use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
class FeedController extends Controller {
public function __construct(API $api, Request $request, $feedMapper){
parent::__construct($api, $request);
$this->feedMapper = $feedMapper;
}
/**
* @IsAdminExemption
* @IsSubAdminExemption
* @Ajax
*
* Returns all feeds
*/
public function getAll(){
$feeds = $this->feedMapper->findAll();
return $this->renderJSON($feeds);
}
}

Просмотреть файл

@ -3,7 +3,7 @@
/**
* ownCloud - News
*
* @author Alessandro Copyright
* @author Alessandro Cosentino
* @author Bernhard Posselt
* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
* @copyright 2012 Bernhard Posselt nukeawhale@gmail.com

Просмотреть файл

@ -71,5 +71,15 @@ class Feed extends Collection {
public function getFolderId(){
return $this->folderId;
}
public function jsonSerialize(){
//TODO: this is just for test
$encoding = array(
'id' => $this->getId(),
'url' => $this->getUrl(),
'title' => $this->getTitle()
);
return $encoding;
}
}

Просмотреть файл

@ -71,6 +71,9 @@ class Folder extends Collection {
return $this->children;
}
public function jsonSerialize() {
//TODO: this is just for test
return $this->name;
}
}

Просмотреть файл

@ -60,7 +60,7 @@ class FolderMapper {
* @returns
*/
public function getAll() {
return self::childrenOf(0);
return $this->childrenOf(0);
}
/**

19
external_api/feed.php Normal file
Просмотреть файл

@ -0,0 +1,19 @@
<?php
namespace OCA\News;
use \OCA\News\Controller\FeedController;
class API_Feed {
public static function getAll() {
$container = createDIContainer();
$bl = $container['FeedBL'];
$feeds = $bl->getAll();
$serializedFeeds = array();
foreach ($feeds as $feed) {
$serializedFeeds[] = $feed->jsonSerialize();
}
return new \OC_OCS_Result($serializedFeeds);
}
}

Просмотреть файл

@ -8,8 +8,13 @@ class API_Folder {
public static function getAll() {
$container = createDIContainer();
$controller = $container['FolderBL'];
return \OC_OCS_Result($controller->getAll());
$bl = $container['FolderBL'];
$folders = $bl->getAll();
$serializedFolders = array();
foreach ($folders as $folder) {
$serializedFolders[] = $folder->jsonSerialize();
}
return new \OC_OCS_Result($serializedFolders);
}
}

14
feed.bl.php Normal file
Просмотреть файл

@ -0,0 +1,14 @@
<?php
namespace OCA\News;
class FeedBL {
public function __construct($feedMapper){
$this->feedMapper = $feedMapper;
}
public function getAll() {
return $this->feedMapper->findAll();
}
}

Просмотреть файл

@ -8,7 +8,7 @@ class FolderBL {
$this->folderMapper = $folderMapper;
}
public static function getAll() {
$folders = $this->folderMapper->getAll();
public function getAll() {
return $this->folderMapper->getAll();
}
}