move to PSR-4
This commit is contained in:
139
lib/Service/BoardService.php
Normal file
139
lib/Service/BoardService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
34
lib/Service/CardArchivedException.php
Normal file
34
lib/Service/CardArchivedException.php
Normal 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
138
lib/Service/CardService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
77
lib/Service/LabelService.php
Normal file
77
lib/Service/LabelService.php
Normal 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);
|
||||
}
|
||||
|
||||
}
|
||||
34
lib/Service/ServicePermissionException.php
Normal file
34
lib/Service/ServicePermissionException.php
Normal 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);
|
||||
}
|
||||
}
|
||||
103
lib/Service/StackService.php
Normal file
103
lib/Service/StackService.php
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user