Files
deck/lib/Service/StackService.php
Julius Haertl 33e99b9e7c move to PSR-4
2016-08-19 18:10:07 +02:00

103 lines
3.3 KiB
PHP

<?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);
}
}