news/controller/foldercontroller.php

154 строки
3.2 KiB
PHP
Исходник Обычный вид История

2013-01-30 01:06:39 +04:00
<?php
/**
* ownCloud - News
*
2013-03-02 22:50:33 +04:00
* @author Alessandro Cosentino
2013-01-30 01:06:39 +04:00
* @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/>.
*
*/
2013-02-02 03:20:26 +04:00
namespace OCA\News\Controller;
2013-01-30 01:06:39 +04:00
2013-02-02 03:20:26 +04:00
use \OCA\AppFramework\Controller\Controller;
use \OCA\AppFramework\Core\API;
use \OCA\AppFramework\Http\Request;
2013-03-21 02:33:51 +04:00
use \OCA\News\Bl\FolderBl;
2013-03-22 02:07:03 +04:00
use \OCA\News\Bl\BLException;
2013-01-30 01:06:39 +04:00
2013-02-02 03:20:26 +04:00
class FolderController extends Controller {
2013-01-30 01:06:39 +04:00
2013-03-21 02:33:51 +04:00
private $folderBl;
2013-01-30 01:06:39 +04:00
2013-03-21 02:33:51 +04:00
public function __construct(API $api, Request $request, FolderBl $folderBl){
2013-02-02 03:21:22 +04:00
parent::__construct($api, $request);
2013-03-21 02:33:51 +04:00
$this->folderBl = $folderBl;
2013-02-02 03:21:22 +04:00
}
/**
* @IsAdminExemption
* @IsSubAdminExemption
* @Ajax
*/
2013-03-21 16:16:16 +04:00
public function folders(){
2013-03-21 02:33:51 +04:00
$folders = $this->folderBl->findAll($this->api->getUserId());
$result = array(
'folders' => $folders
);
return $this->renderJSON($result);
2013-02-02 03:21:22 +04:00
}
2013-01-30 01:06:39 +04:00
private function setOpened($isOpened){
$userId = $this->api->getUserId();
$folderId = (int) $this->params('folderId');
$this->folderBl->open($folderId, $isOpened, $userId);
}
/**
* @IsAdminExemption
* @IsSubAdminExemption
* @Ajax
*/
public function open(){
$this->setOpened(true);
2013-03-22 02:07:03 +04:00
return $this->renderJSON();
}
/**
* @IsAdminExemption
* @IsSubAdminExemption
* @Ajax
*/
public function collapse(){
$this->setOpened(false);
2013-03-22 02:07:03 +04:00
return $this->renderJSON();
}
/**
* @IsAdminExemption
* @IsSubAdminExemption
* @Ajax
*/
public function create(){
2013-03-22 02:07:03 +04:00
$userId = $this->api->getUserId();
$folderName = $this->params('folderName');
try {
$folder = $this->folderBl->create($folderName, $userId);
$params = array(
'folders' => array($folder)
);
return $this->renderJSON($params);
} catch (BLException $ex){
return $this->renderJSON(array(), $ex->getMessage());
}
}
/**
* @IsAdminExemption
* @IsSubAdminExemption
* @Ajax
*/
public function delete(){
2013-03-22 02:07:03 +04:00
$userId = $this->api->getUserId();
$folderId = (int) $this->params('folderId');
2013-03-22 02:07:03 +04:00
$this->folderBl->delete($folderId, $userId);
return $this->renderJSON();
}
/**
* @IsAdminExemption
* @IsSubAdminExemption
* @Ajax
*/
public function rename(){
2013-03-22 02:07:03 +04:00
$userId = $this->api->getUserId();
$folderName = $this->params('folderName');
$folderId = (int) $this->params('folderId');
2013-03-22 02:07:03 +04:00
try {
$folder = $this->folderBl->rename($folderId, $folderName, $userId);
$params = array(
'folders' => array($folder)
);
return $this->renderJSON($params);
} catch (BLException $ex){
return $this->renderJSON(array(), $ex->getMessage());
}
}
2013-01-30 01:06:39 +04:00
}