move to PSR-4

This commit is contained in:
Julius Haertl
2016-08-19 18:10:07 +02:00
parent aeb9f29119
commit 33e99b9e7c
28 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,114 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Controller;
use OCA\Deck\Service\BoardService;
use OCP\IRequest;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\IUserManager;
use OCP\IGroupManager;
class BoardController extends Controller {
private $userId;
private $boardService;
protected $userManager;
protected $groupManager;
public function __construct($appName,
IRequest $request,
IUserManager $userManager,
IGroupManager $groupManager,
BoardService $cardService,
$userId) {
parent::__construct($appName, $request);
$this->userId = $userId;
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->boardService = $cardService;
$this->userInfo = $this->getBoardPrequisites();
}
private function getBoardPrequisites() {
$groups = $this->groupManager->getUserGroupIds($this->userManager->get($this->userId));
return [
'user' => $this->userId,
'groups' => $groups
];
}
/**
* @NoAdminRequired
*/
public function index() {
return $this->boardService->findAll($this->userInfo);
}
/**
* @NoAdminRequired
*/
public function read($boardId) {
// FIXME: Remove as this is just for testing if loading animation works out nicely
//usleep(2000);
return $this->boardService->find($this->userId, $boardId);
}
/**
* @NoAdminRequired
*/
public function create($title, $color) {
return $this->boardService->create($title, $this->userId, $color);
}
/**
* @NoAdminRequired
*/
public function update($id, $title, $color) {
return $this->boardService->update($id, $title, $this->userId, $color);
}
/**
* @NoAdminRequired
*/
public function delete($boardId) {
return $this->boardService->delete($this->userId, $boardId);
}
public function labels($boardId) {
return $this->boardService->labels($this->boardId);
}
public function addAcl($boardId, $type, $participant, $write, $invite, $manage) {
return $this->boardService->addAcl($boardId, $type, $participant, $write, $invite, $manage);
}
public function updateAcl($id, $permissionWrite, $permissionInvite, $permissionManage) {
return $this->boardService->updateAcl($id, $permissionWrite, $permissionInvite, $permissionManage);
}
public function deleteAcl($id) {
return $this->boardService->deleteAcl($id);
}
}

View File

@@ -0,0 +1,110 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Controller;
use OCA\Deck\Service\CardService;
use OCP\IRequest;
use OCP\AppFramework\Controller;
class CardController extends Controller {
private $userId;
private $cardService;
public function __construct($appName,
IRequest $request,
CardService $cardService,
$userId){
parent::__construct($appName, $request);
$this->userId = $userId;
$this->cardService = $cardService;
}
/**
* @NoAdminRequired
*/
public function index($cardId) {
return $this->cardService->findAll($boardId);
}
/**
* @NoAdminRequired
*/
public function read($cardId) {
return $this->cardService->find($this->userId, $cardId);
}
/**
* @NoAdminRequired
*/
public function reorder($cardId, $stackId, $order) {
return $this->cardService->reorder($cardId, $stackId, $order);
}
/**
* @NoAdminRequired
*/
public function rename($cardId, $title) {
return $this->cardService->rename($cardId, $title);
}
/**
* @NoAdminRequired
*/
public function create($title, $stackId, $type, $order=999) {
return $this->cardService->create($title, $stackId, $type, $order, $this->userId);
}
/**
* @NoAdminRequired
*/
public function update($id, $title, $stackId, $type, $order, $description) {
return $this->cardService->update($id, $title, $stackId, $type, $order, $description, $this->userId);
}
/**
* @NoAdminRequired
*/
public function delete($cardId) {
return $this->cardService->delete($this->userId, $cardId);
}
/**
* @NoAdminRequired
*/
public function archive($cardId) {
return $this->cardService->archive($cardId);
}
/**
* @NoAdminRequired
*/
public function unarchive($cardId) {
return $this->cardService->unarchive($cardId);
}
/**
* @NoAdminRequired
*/
public function assignLabel($cardId, $labelId) {
return $this->cardService->assignLabel($this->userId, $cardId, $labelId);
}
/**
* @NoAdminRequired
*/
public function removeLabel($cardId, $labelId) {
return $this->cardService->removeLabel($this->userId, $cardId, $labelId);
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Controller;
use OCA\Deck\Service\LabelService;
use OCP\IRequest;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
class LabelController extends Controller {
private $userId;
private $labelService;
public function __construct($appName,
IRequest $request,
LabelService $labelService,
$userId){
parent::__construct($appName, $request);
$this->userId = $userId;
$this->labelService = $labelService;
}
/**
* @NoAdminRequired
*/
public function create($title, $color, $boardId) {
return $this->labelService->create($title, $this->userId, $color, $boardId);
}
/**
* @NoAdminRequired
*/
public function update($id, $title, $color) {
return $this->labelService->update($id, $title, $this->userId, $color);
}
/**
* @NoAdminRequired
*/
public function delete($labelId) {
return $this->labelService->delete($this->userId, $labelId);
}
}

View File

@@ -0,0 +1,58 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Controller;
use OCP\IRequest;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
use OCP\IL10N;
class PageController extends Controller {
private $userId;
private $l10n;
public function __construct($AppName, IRequest $request, IL10N $l10n, $userId) {
parent::__construct($AppName, $request);
$this->userId = $userId;
$this->l10n = $l10n;
}
/**
* Handle main html view from templates/main.php
* This will return the main angular application
*
* @NoAdminRequired
* @NoCSRFRequired
*/
public function index() {
$params = [
'user' => $this->userId,
];
return new TemplateResponse('deck', 'main', $params);
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Controller;
use OCA\Deck\Db\Acl;
use OCP\IGroupManager;
use OCP\IRequest;
use OCP\AppFramework\ApiController as BaseApiController;
use OCP\AppFramework\Controller;
use OCP\IUserManager;
class ShareController extends Controller {
protected $userManager;
protected $groupManager;
private $userId;
public function __construct($appName,
IRequest $request,
IUserManager $userManager,
IGroupManager $groupManager,
$userId
){
parent::__construct($appName, $request);
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->userId = $userId;
}
/**
* FIXME: REMOVE, just for testing
* @NoCSRFRequired
* @NoAdminRequired
*/
public function searchUser($search) {
$limit = null;
$offset = null;
$result = [];
foreach ($this->groupManager->search($search, $limit, $offset) as $idx => $group) {
$acl = new Acl();
$acl->setType('group');
$acl->setParticipant($group->getGID());
$acl->setPermissionWrite(true);
$acl->setPermissionInvite(true);
$acl->setPermissionManage(true);
$result[] = $acl;
}
foreach ($this->userManager->searchDisplayName($search, $limit, $offset) as $idx => $user) {
if($user->getUID() === $this->userId)
continue;
$acl = new Acl();
$acl->setType('user');
$acl->setParticipant($user->getUID());
$acl->setPermissionWrite(true);
$acl->setPermissionInvite(true);
$acl->setPermissionManage(true);
$result[] = $acl;
}
return $result;
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Controller;
use OCA\Deck\Service\StackService;
use OCP\IRequest;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Db\DoesNotExistException;
class StackController extends Controller {
private $userId;
private $stackService;
public function __construct($appName,
IRequest $request,
StackService $cardService,
$userId){
parent::__construct($appName, $request);
$this->userId = $userId;
$this->stackService = $cardService;
}
/**
* @NoAdminRequired
*/
public function index($boardId) {
return $this->stackService->findAll($boardId);
}
/**
* @NoAdminRequired
*/
public function archived($boardId) {
return $this->stackService->findAllArchived($boardId);
}
/**
* @NoAdminRequired
*/
public function read($boardId) {
return $this->stackService->find($this->userId, $boardId);
}
/**
* @NoAdminRequired
*/
public function create($title, $boardId, $order=999) {
return $this->stackService->create($title, $boardId, $order);
}
/**
* @NoAdminRequired
*/
public function update($id, $title, $boardId, $order) {
return $this->stackService->update($id, $title, $boardId, $order);
}
/**
* @NoAdminRequired
*/
public function delete($stackId) {
return $this->stackService->delete($this->userId, $stackId);
}
}

View File

@@ -0,0 +1,46 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Controller;
use OCP\IRequest;
use OCP\AppFramework\ApiController as BaseApiController;
class StyleController extends Controller {
private $defaults;
public function __construct($appName,
IRequest $request, OC_Defaults $defaults){
parent::__construct($appName, $request);
$this->defaults = $defaults;
}
/**
* @PublicPage
* @NoCSRFRequired
*/
public function generateCss() {
$color = $this->config->getAppValue($this->appName, 'color');
$responseCss .= '';
$response = new Http\DataDownloadResponse($responseCss, 'style', 'text/css');
}
}

61
lib/Db/Acl.php Normal file
View File

@@ -0,0 +1,61 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// db/author.php
namespace OCA\Deck\Db;
use JsonSerializable;
class Acl extends Entity implements JsonSerializable {
public $id;
protected $participant;
protected $type;
protected $boardId;
protected $permissionWrite;
protected $permissionInvite;
protected $permissionManage;
protected $owner;
public function __construct() {
$this->addType('id','integer');
$this->addType('boardId','integer');
$this->addType('permissionWrite', 'boolean');
$this->addType('permissionInvite', 'boolean');
$this->addType('permissionManage', 'boolean');
$this->addType('owner', 'boolean');
$this->addRelation('owner');
}
public function jsonSerialize() {
return [
'id' => $this->id,
'participant' => $this->participant,
'type' => $this->type,
'boardId' => $this->boardId,
'permissionWrite' => $this->permissionWrite,
'permissionInvite' => $this->permissionInvite,
'permissionManage' => $this->permissionManage,
'owner' => $this->owner
];
}
}

52
lib/Db/AclMapper.php Normal file
View File

@@ -0,0 +1,52 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Db;
use OCP\AppFramework\Db\Entity;
use OCP\IDb;
use OCP\AppFramework\Db\Mapper;
class AclMapper extends DeckMapper {
public function __construct(IDb $db) {
parent::__construct($db, 'deck_board_acl', '\OCA\Deck\Db\Acl');
}
public function findAll($boardId, $limit=null, $offset=null) {
$sql = 'SELECT id, board_id, type, participant, permission_write, permission_invite, permission_manage, 0 as owner FROM `*PREFIX*deck_board_acl` WHERE `board_id` = ? UNION SELECT 0, id, \'user\', owner, 1, 1, 1, 1 FROM `*PREFIX*deck_boards` WHERE `id` = ? ';
return $this->findEntities($sql, [$boardId, $boardId], $limit, $offset);
}
public function findAllForCard($cardId, $userId) {
$findBoardId = "(SELECT board_id from oc_deck_stacks WHERE id IN (SELECT stack_id from oc_deck_cards WHERE id = 15))";
$sql = "SELECT 0, id, 'user', owner, 1, 1, 1, 1 as owner FROM `oc_deck_boards` WHERE `id` IN (SELECT board_id from oc_deck_stacks WHERE id IN (SELECT stack_id from oc_deck_cards WHERE id = 15))
UNION
SELECT id, board_id, type, participant, permission_write, permission_invite, permission_manage, 0 FROM oc_deck_board_acl
WHERE participant = 'admin' AND board_id IN (SELECT board_id from oc_deck_stacks WHERE id IN (SELECT stack_id from oc_deck_cards WHERE id = 15));";
}
}

75
lib/Db/Board.php Normal file
View File

@@ -0,0 +1,75 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// db/author.php
namespace OCA\Deck\Db;
use JsonSerializable;
class Board extends \OCA\Deck\Db\Entity implements JsonSerializable {
public $id;
protected $title;
protected $owner;
protected $color;
protected $archived;
protected $labels;
protected $acl;
protected $shared;
public function __construct() {
$this->addType('id','integer');
$this->addType('shared','integer');
$this->addRelation('labels');
$this->addRelation('acl');
$this->addRelation('shared');
$this->shared = -1;
}
public function jsonSerialize() {
$result = [
'id' => $this->id,
'title' => $this->title,
'owner' => $this->owner,
'color' => $this->color,
'labels' => $this->labels,
'acl' => $this->acl,
];
if($this->shared!==-1) {
$result['shared'] = $this->shared;
}
return $result;
}
public function setLabels($labels) {
foreach ($labels as $l) {
$this->labels[] = $l;
}
}
public function setAcl($acl) {
foreach ($acl as $a) {
$this->acl[$a->id] = $a;
}
}
}

139
lib/Db/BoardMapper.php Normal file
View File

@@ -0,0 +1,139 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Db;
use OCP\IDb;
use OCP\AppFramework\Db\Mapper;
use Symfony\Component\Config\Definition\Exception\Exception;
class BoardMapper extends Mapper {
private $labelMapper;
private $_relationMappers = array();
public function addRelationMapper($name, $mapper) {
$this->_relationMappers[$name] = $mapper;
}
public function __construct(IDb $db, LabelMapper $labelMapper, AclMapper $aclMapper) {
parent::__construct($db, 'deck_boards', '\OCA\Deck\Db\Board');
$this->labelMapper = $labelMapper;
$this->aclMapper = $aclMapper;
}
/**
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
*/
public function find($id) {
$sql = 'SELECT id, title, owner, color, archived FROM `*PREFIX*deck_boards` ' .
'WHERE `id` = ?';
$board = $this->findEntity($sql, [$id]);
// Add labels
$labels = $this->labelMapper->findAll($id);
$board->setLabels($labels);
// Add acl
$acl = $this->aclMapper->findAll($id);
$board->setAcl($acl);
return $board;
}
/**
* Find all boards for a given user
* @param $userId
* @param null $limit
* @param null $offset
* @return array
*/
public function findAllByUser($userId, $limit=null, $offset=null) {
$sql = 'SELECT id, title, owner, color, archived, 0 as shared FROM oc_deck_boards WHERE owner = ? UNION ' .
'SELECT boards.id, title, owner, color, archived, 1 as shared FROM oc_deck_boards as boards ' .
'JOIN oc_deck_board_acl as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=\'user\' AND boards.owner != ?';
$entries = $this->findEntities($sql, [$userId, $userId, $userId], $limit, $offset);
/* @var Board $entry */
foreach ($entries as $entry) {
$acl = $this->aclMapper->findAll($entry->id);
$entry->setAcl($acl);
}
return $entries;
}
/**
* Find all boards for a given user
* @param $groups
* @param null $limit
* @param null $offset
* @return array
*/
public function findAllByGroups($userId, $groups, $limit=null, $offset=null) {
if(count($groups)<=0) {
return [];
}
$sql = 'SELECT boards.id, title, owner, color, archived, 2 as shared FROM oc_deck_boards as boards ' .
'INNER JOIN oc_deck_board_acl as acl ON boards.id=acl.board_id WHERE owner != ? AND type=\'group\' AND (';
$countGroups = 0;
foreach ($groups as $group) {
$sql .= 'acl.participant = ? ';
if(count($groups)>1 && $countGroups++<count($groups)-1)
$sql .= ' OR ';
}
$sql .= ');';
$entries = $this->findEntities($sql, array_merge([$userId], $groups), $limit, $offset);
/* @var Board $entry */
foreach ($entries as $entry) {
$acl = $this->aclMapper->findAll($entry->id);
$entry->setAcl($acl);
}
return $entries;
}
public function delete(\OCP\AppFramework\Db\Entity $entity) {
//$this->deleteRelationalEntities('label', $entity);
return parent::delete($entity);
}
public function userCanView($boardId, $userInfo) {
$board = $this->find($boardId);
if($board->getOwner()===$userInfo['user']) {
return true;
}
try {
$sql = 'SELECT acl.* FROM oc_deck_boards as boards ' .
'JOIN oc_deck_board_acl as acl ON boards.id=acl.board_id WHERE acl.participant=? AND acl.type=\'user\' AND boards.id = ? AND boards.owner != ?';
$acl = $this->find($sql, [$userInfo['user'], $boardId, $userInfo['user']], $limit, $offset);
return true;
} catch (Exception $e) { }
try {
$acl = $this->find($sql, [$userInfo['user'], $boardId, $userInfo['user']], $limit, $offset);
return true;
} catch (Exception $e) {
}
}
}

68
lib/Db/Card.php Normal file
View File

@@ -0,0 +1,68 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// db/author.php
namespace OCA\Deck\Db;
use JsonSerializable;
class Card extends Entity implements JsonSerializable {
public $id;
protected $title;
protected $description;
protected $stackId;
protected $type;
protected $lastModified;
protected $createdAt;
protected $labels;
protected $owner;
protected $order;
protected $archived;
public function __construct() {
$this->addType('id','integer');
$this->addType('stackId','integer');
$this->addType('order','integer');
$this->addType('lastModified', 'integer');
$this->addType('createdAt', 'integer');
$this->addType('archived','boolean');
$this->addRelation('labels');
}
public function jsonSerialize() {
return [
'id' => $this->id,
'title' => $this->title,
'description' => $this->description,
'type' => $this->type,
'lastModified' => $this->lastModified,
'createdAt' => $this->createdAt,
'owner' => $this->owner,
'order' => $this->order,
'stackId' => $this->stackId,
'labels' => $this->labels,
'archived' => $this->archived,
];
}
}

111
lib/Db/CardMapper.php Normal file
View File

@@ -0,0 +1,111 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Db;
use OCP\AppFramework\Db\Entity;
use OCP\IDb;
use OCP\AppFramework\Db\Mapper;
class CardMapper extends Mapper {
private $labelMapper;
public function __construct(IDb $db, LabelMapper $labelMapper) {
parent::__construct($db, 'deck_cards', '\OCA\Deck\Db\Card');
$this->labelMapper = $labelMapper;
}
public function insert(Entity $entity) {
$entity->setCreatedAt(time());
$entity->setLastModified(time());
return parent::insert($entity);
}
/**
* @param Entity $entity
* @return Entity
*/
public function update(Entity $entity) {
$entity->setLastModified(time());
return parent::update($entity);
}
/**
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
*/
public function find($id) {
$sql = 'SELECT * FROM `*PREFIX*deck_cards` ' .
'WHERE `id` = ?';
$card = $this->findEntity($sql, [$id]);
$labels = $this->labelMapper->findAssignedLabelsForCard($card->id);
$card->setLabels($labels);
return $card;
}
public function findAllByBoard($boardId, $limit=null, $offset=null) {
}
public function findAll($stackId, $limit=null, $offset=null) {
// TODO: Exclude fields like text
$sql = 'SELECT * FROM `*PREFIX*deck_cards`
WHERE `stack_id` = ? AND NOT archived ORDER BY `order`';
$entities = $this->findEntities($sql, [$stackId], $limit, $offset);
return $entities;
}
// TODO: test
public function findAllArchived($stackId, $limit=null, $offset=null) {
$sql = 'SELECT * FROM `*PREFIX*deck_cards` WHERE `stack_id`=? AND archived ORDER BY `last_modified`';
$entities = $this->findEntities($sql, [$stackId], $limit, $offset);
return $entities;
}
public function delete(Entity $entity) {
// FIXME: delete linked elements, because owncloud doesn't support foreign keys for apps
return parent::delete($entity);
}
public function assignLabel($card, $label) {
$sql = 'INSERT INTO `*PREFIX*deck_assigned_labels` (`label_id`,`card_id`) VALUES (?,?)';
$stmt = $this->db->prepare($sql);
$stmt->bindParam(1, $label, \PDO::PARAM_INT);
$stmt->bindParam(2, $card, \PDO::PARAM_INT);
$stmt->execute();
}
public function removeLabel($card, $label) {
$sql = 'DELETE FROM `*PREFIX*deck_assigned_labels` WHERE card_id = ? AND label_id = ?';
$stmt = $this->db->prepare($sql);
$stmt->bindParam(1, $card, \PDO::PARAM_INT);
$stmt->bindParam(2, $label, \PDO::PARAM_INT);
$stmt->execute();
}
}

53
lib/Db/DeckMapper.php Normal file
View File

@@ -0,0 +1,53 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Db;
use OCP\AppFramework\Db\Entity;
use OCP\AppFramework\Db\Mapper;
abstract class DeckMapper extends Mapper {
/**
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
*/
public function find($id) {
$sql = 'SELECT * FROM `' . $this->tableName . '` ' . 'WHERE `id` = ?';
return $this->findEntity($sql, [$id]);
}
/**
* Add relational data to an Entity by calling the related Mapper
* @param $entities
* @param $entityType
* @param $property
* addRelation($cards, $labels, function($one, $many) {
* if($one->id == $many->cardId)
* }
*/
public function addRelation($entities, $entityType, $property) {
}
}

70
lib/Db/Entity.php Normal file
View File

@@ -0,0 +1,70 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
/**
* Created by PhpStorm.
* User: jus
* Date: 22.06.16
* Time: 13:32
*/
namespace OCA\Deck\Db;
class Entity extends \OCP\AppFramework\Db\Entity {
private $_relations = array();
private $_updatedFields = array();
/**
* Mark a property as relation so it will not get updated using Mapper::update
* @param string $property Name of the property
*/
public function addRelation(string $property) {
if (!in_array($property, $this->_relations)) {
$this->_relations[] = $property;
}
}
/**
* Mark am attribute as updated
* overwritten from \OCP\AppFramework\Db\Entity to avoid writing relational attributes
* @param string $attribute the name of the attribute
* @since 7.0.0
*/
protected function markFieldUpdated($attribute){
if(!in_array($attribute, $this->_relations)) {
$this->_updatedFields[$attribute] = true;
}
}
/**
* overwritten from \OCP\AppFramework\Db\Entity to avoid writing relational attributes
* @return array Array of field's update status
*/
public function getUpdatedFields(){
return $this->_updatedFields;
}
}

48
lib/Db/Label.php Normal file
View File

@@ -0,0 +1,48 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// db/author.php
namespace OCA\Deck\Db;
use JsonSerializable;
class Label extends Entity implements JsonSerializable {
public $id;
protected $title;
protected $color;
protected $boardId;
protected $cardId;
public function __construct() {
$this->addType('id','integer');
}
public function jsonSerialize() {
return [
'id' => $this->id,
'title' => $this->title,
'boardId' => $this->boardId,
'cardId' => $this->cardId,
'color' => $this->color,
];
}
}

69
lib/Db/LabelMapper.php Normal file
View File

@@ -0,0 +1,69 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Db;
use OCP\AppFramework\Db\Entity;
use OCP\IDb;
use OCP\AppFramework\Db\Mapper;
class LabelMapper extends DeckMapper {
public function __construct(IDb $db) {
parent::__construct($db, 'deck_labels', '\OCA\Deck\Db\Label');
}
public function findAll($boardId, $limit=null, $offset=null) {
$sql = 'SELECT * FROM `*PREFIX*deck_labels` WHERE `board_id` = ? ORDER BY `id`';
return $this->findEntities($sql, [$boardId], $limit, $offset);
}
public function delete(Entity $entity) {
// FIXME: delete linked elements, because owncloud doesn't support foreign keys for apps
return parent::delete($entity);
}
public function findAssignedLabelsForCard($cardId) {
$sql = 'SELECT l.* FROM `*PREFIX*deck_assigned_labels` as al INNER JOIN *PREFIX*deck_labels as l ON l.id = al.label_id WHERE `card_id` = ? ORDER BY l.id';
return $this->findEntities($sql, [$cardId], $limit, $offset);
}
public function findAssignedLabelsForBoard($boardId, $limit=null, $offset=null) {
$sql = "SELECT c.id as card_id, l.id as id, l.title as title, l.color as color FROM oc_deck_cards as c " .
" INNER JOIN oc_deck_assigned_labels as al ON al.card_id = c.id INNER JOIN oc_deck_labels as l ON al.label_id = l.id WHERE board_id=? ORDER BY l.id";
$entities = $this->findEntities($sql, [$boardId], $limit, $offset);
return $entities;
}
public function getAssignedLabelsForBoard($boardId) {
$labels = $this->findAssignedLabelsForBoard($boardId);
$result = array();
foreach ($labels as $label) {
if(!is_array($result[$label->getCardId()])) {
$result[$label->getCardId()] = array();
}
$result[$label->getCardId()][] = $label;
}
return $result;
}
}

55
lib/Db/Stack.php Normal file
View File

@@ -0,0 +1,55 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
// db/author.php
namespace OCA\Deck\Db;
use JsonSerializable;
class Stack extends Entity implements JsonSerializable {
public $id;
protected $title;
protected $boardId;
protected $cards = array();
protected $order;
public function __construct() {
$this->addType('id','integer');
$this->addType('boardId','integer');
$this->addType('order','integer');
}
public function setCards($cards) {
$this->cards = $cards;
}
public function jsonSerialize() {
return [
'id' => $this->id,
'title' => $this->title,
'order' => $this->order,
'boardId' => $this->boardId,
'cards' => $this->cards,
];
}
}

62
lib/Db/StackMapper.php Normal file
View File

@@ -0,0 +1,62 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Db;
use OCP\AppFramework\Db\Entity;
use OCP\IDb;
use OCP\AppFramework\Db\Mapper;
class StackMapper extends Mapper {
private $cardMapper;
public function __construct(IDb $db, CardMapper $cardMapper) {
parent::__construct($db, 'deck_stacks', '\OCA\Deck\Db\Stack');
$this->cardMapper = $cardMapper;
}
/**
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
*/
public function find($id) {
$sql = 'SELECT * FROM `*PREFIX*deck_stacks` ' .
'WHERE `id` = ?';
return $this->findEntity($sql, [$id]);
}
public function findAll($boardId, $limit=null, $offset=null) {
$sql = 'SELECT * FROM `*PREFIX*deck_stacks` WHERE `board_id` = ? ORDER BY `order`';
return $this->findEntities($sql, [$boardId], $limit, $offset);
}
public function delete(Entity $entity) {
// FIXME: delete linked elements, because owncloud doesn't support foreign keys for apps
return parent::delete($entity);
}
}

View File

@@ -0,0 +1,139 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Service;
use OCA\Deck\Db\Acl;
use OCA\Deck\Db\AclMapper;
use OCA\Deck\Db\Label;
use OCP\ILogger;
use OCP\IL10N;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use \OCA\Deck\Db\Board;
use \OCA\Deck\Db\BoardMapper;
use \OCA\Deck\Db\LabelMapper;
class BoardService {
private $boardMapper;
private $aclMapper;
private $labelMapper;
private $logger;
private $l10n;
private $timeFactory;
public function __construct(BoardMapper $boardMapper,
ILogger $logger,
IL10N $l10n,
ITimeFactory $timeFactory,
LabelMapper $labelMapper,
AclMapper $aclMapper) {
$this->boardMapper = $boardMapper;
$this->labelMapper = $labelMapper;
$this->aclMapper = $aclMapper;
$this->logger = $logger;
$this->l10n = $l10n;
}
public function findAll($userInfo) {
$userBoards = $this->boardMapper->findAllByUser($userInfo['user']);
$groupBoards = $this->boardMapper->findAllByGroups($userInfo['user'], $userInfo['groups']);
return array_merge($userBoards, $groupBoards);
}
public function find($userId, $boardId) {
$board = $this->boardMapper->find($boardId);
if ($board->getOwner() === $userId)
return $board;
else
return null;
// FIXME: [share] Check for user permissions
}
public function create($title, $userId, $color) {
$board = new Board();
$board->setTitle($title);
$board->setOwner($userId);
$board->setColor($color);
$new_board = $this->boardMapper->insert($board);
// create new labels
$default_labels = [
'31CC7C' => $this->l10n->t('Finished'),
'317CCC' => $this->l10n->t('To review'),
'FF7A66' => $this->l10n->t('Action needed'),
'F1DB50' => $this->l10n->t('Maybe')];
$labels = [];
foreach ($default_labels as $color=>$title) {
$label = new Label();
$label->setColor($color);
$label->setTitle($title);
$label->setBoardId($new_board->getId());
$labels[] = $this->labelMapper->insert($label);
}
$new_board->setLabels($labels);
return $new_board;
}
public function delete($userId, $id) {
return $this->boardMapper->delete($this->find($userId, $id));
}
public function update($id, $title, $userId, $color) {
$board = $this->find($userId, $id);
$board->setTitle($title);
$board->setColor($color);
return $this->boardMapper->update($board);
}
public function addAcl($boardId, $type, $participant, $write, $invite, $manage) {
$acl = new Acl();
$acl->setBoardId($boardId);
$acl->setType($type);
$acl->setParticipant($participant);
$acl->setPermissionWrite($write);
$acl->setPermissionInvite($invite);
$acl->setPermissionManage($manage);
return $this->aclMapper->insert($acl);
}
public function updateAcl($id, $write, $invite, $manage) {
$acl = $this->aclMapper->find($id);
$acl->setPermissionWrite($write);
$acl->setPermissionInvite($invite);
$acl->setPermissionManage($manage);
return $this->aclMapper->update($acl);
}
public function deleteAcl($id) {
$acl = $this->aclMapper->find($id);
return $this->aclMapper->delete($acl);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Service;
class CardArchivedException extends \Exception {
/**
* Constructor
* @param string $msg the error message
*/
public function __construct($msg){
parent::__construct($msg);
}
}

138
lib/Service/CardService.php Normal file
View File

@@ -0,0 +1,138 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Service;
use OC\OCS\Exception;
use OCP\ILogger;
use OCP\IL10N;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use \OCA\Deck\Db\Card;
use \OCA\Deck\Db\CardMapper;
class CardService {
private $cardMapper;
private $logger;
public function __construct(CardMapper $cardMapper) {
$this->cardMapper = $cardMapper;
}
public function find($userId, $cardId) {
return $this->cardMapper->find($cardId);
}
public function create($title, $stackId, $type, $order, $owner) {
$card = new Card();
$card->setTitle($title);
$card->setStackId($stackId);
$card->setType($type);
$card->setOrder($order);
$card->setOwner($owner);
return $this->cardMapper->insert($card);
}
public function delete($userId, $id) {
return $this->cardMapper->delete($this->cardMapper->find($id));
}
public function update($id, $title, $stackId, $type, $order, $description, $owner) {
$card = $this->cardMapper->find($id);
if($card->getArchived()) {
throw new CardArchivedException();
}
$card->setTitle($title);
$card->setStackId($stackId);
$card->setType($type);
$card->setOrder($order);
$card->setOwner($owner);
$card->setDescription($description);
return $this->cardMapper->update($card);
}
public function rename($id, $title) {
$card = $this->cardMapper->find($id);
if($card->getArchived()) {
throw new CardArchivedException();
}
$card->setTitle($title);
return $this->cardMapper->update($card);
}
public function reorder($id, $stackId, $order) {
$cards = $this->cardMapper->findAll($stackId);
$i = 0;
foreach ($cards as $card) {
if($card->getArchived()) {
throw new CardArchivedException();
}
if($card->id === $id) {
$card->setOrder($order);
}
if($i === $order)
$i++;
if($card->id !== $id) {
$card->setOrder($i++);
}
$card->setLastModified(time());
$this->cardMapper->update($card);
}
// FIXME: return reordered cards without an additional db query
$cards = $this->cardMapper->findAll($stackId);
return $cards;
}
public function archive($id) {
$card = $this->cardMapper->find($id);
$card->setArchived(true);
return $this->cardMapper->update($card);
}
public function unarchive($id) {
$card = $this->cardMapper->find($id);
$card->setArchived(false);
return $this->cardMapper->update($card);
}
public function assignLabel($userId, $cardId, $labelId) {
$card = $this->cardMapper->find($cardId);
if($card->getArchived()) {
throw new CardArchivedException();
}
$this->cardMapper->assignLabel($cardId, $labelId);
}
public function removeLabel($userId, $cardId, $labelId) {
$card = $this->cardMapper->find($cardId);
if($card->getArchived()) {
throw new CardArchivedException();
}
$this->cardMapper->removeLabel($cardId, $labelId);
}
}

View File

@@ -0,0 +1,77 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Service;
use OCA\Deck\Db\Label;
use OCP\ILogger;
use OCP\IL10N;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use \OCA\Deck\Db\Board;
use \OCA\Deck\Db\BoardMapper;
use \OCA\Deck\Db\LabelMapper;
class LabelService {
private $labelMapper;
private $logger;
private $l10n;
private $timeFactory;
public function __construct(ILogger $logger,
IL10N $l10n,
ITimeFactory $timeFactory,
LabelMapper $labelMapper) {
$this->labelMapper = $labelMapper;
$this->logger = $logger;
}
public function find($userId, $labelId) {
$label = $this->labelMapper->find($labelId);
// FIXME: [share] Check for user permissions
return $label;
}
public function create($title, $userId, $color, $boardId) {
$label = new Label();
$label->setTitle($title);
$label->setColor($color);
$label->setBoardId($boardId);
return $this->labelMapper->insert($label);
}
public function delete($userId, $id) {
return $this->labelMapper->delete($this->find($userId, $id));
}
public function update($id, $title, $userId, $color) {
$label = $this->find($userId, $id);
$label->setTitle($title);
$label->setColor($color);
return $this->labelMapper->update($label);
}
}

View File

@@ -0,0 +1,34 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Service;
class ServicePermissionException extends \Exception {
/**
* Constructor
* @param string $msg the error message
*/
public function __construct($msg){
parent::__construct($msg);
}
}

View File

@@ -0,0 +1,103 @@
<?php
/**
* @copyright Copyright (c) 2016 Julius Härtl <jus@bitgrid.net>
*
* @author Julius Härtl <jus@bitgrid.net>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Deck\Service;
use OCA\Deck\Db\CardMapper;
use OCA\Deck\Db\LabelMapper;
use OCP\ILogger;
use OCP\IL10N;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Utility\ITimeFactory;
use \OCA\Deck\Db\Stack;
use \OCA\Deck\Db\StackMapper;
class StackService {
private $stackMapper;
private $cardMapper;
private $logger;
private $l10n;
private $timeFactory;
private $labelMapper;
public function __construct(StackMapper $stackMapper, CardMapper $cardMapper, LabelMapper $labelMapper, ILogger $logger,
IL10N $l10n,
ITimeFactory $timeFactory) {
$this->stackMapper = $stackMapper;
$this->cardMapper = $cardMapper;
$this->labelMapper = $labelMapper;
$this->logger = $logger;
}
public function findAll($boardId) {
$stacks = $this->stackMapper->findAll($boardId);
$labels = $this->labelMapper->getAssignedLabelsForBoard($boardId);
foreach ($stacks as $idx => $s) {
$cards = $this->cardMapper->findAll($s->id);
foreach ($cards as $idxc => $card) {
$cards[$idxc]->setLabels($labels[$card->id]);
}
$stacks[$idx]->setCards($cards);
}
return $stacks;
}
public function findAllArchived($boardId) {
$stacks = $this->stackMapper->findAll($boardId);
$labels = $this->labelMapper->getAssignedLabelsForBoard($boardId);
foreach ($stacks as $idx => $s) {
$cards = $this->cardMapper->findAllArchived($s->id);
foreach ($cards as $idxc => $card) {
$cards[$idxc]->setLabels($labels[$card->id]);
}
$stacks[$idx]->setCards($cards);
}
return $stacks;
}
public function create($title, $boardId, $order) {
$stack = new Stack();
$stack->setTitle($title);
$stack->setBoardId($boardId);
$stack->setOrder($order);
return $this->stackMapper->insert($stack);
}
public function delete($userId, $id) {
return $this->stackMapper->delete($this->stackMapper->find($id));
}
public function update($id, $title, $boardId, $order) {
$stack = $this->stackMapper->find($id);
$stack->setTitle($title);
$stack->setBoardId($boardId);
$stack->setOrder($order);
return $this->stackMapper->update($stack);
}
}