diff --git a/lib/Db/AssignedLabels.php b/lib/Db/AssignedLabels.php new file mode 100644 index 000000000..68625aecb --- /dev/null +++ b/lib/Db/AssignedLabels.php @@ -0,0 +1,38 @@ + + * + * @author Jakob Röhrl + * + * @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 . + * + */ + +namespace OCA\Deck\Db; + +use JsonSerializable; + +class AssignedLabels extends RelationalEntity implements JsonSerializable { + public $id; + protected $label; + protected $cardId; + + public function __construct() { + $this->addType('id', 'integer'); + $this->addType('cardId', 'integer'); + $this->addResolvable('label'); + } +} diff --git a/lib/Db/AssignedLabelsMapper.php b/lib/Db/AssignedLabelsMapper.php new file mode 100644 index 000000000..236976695 --- /dev/null +++ b/lib/Db/AssignedLabelsMapper.php @@ -0,0 +1,61 @@ + + * + * @author Jakob Röhrl + * + * @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 . + * + */ + + +namespace OCA\Deck\Db; + +use OCP\AppFramework\Db\Entity; +use OCP\IDBConnection; +use OCP\IGroupManager; +use OCP\IUserManager; + +class AssignedLabelsMapper extends DeckMapper { + private $cardMapper; + private $userManager; + /** + * @var IGroupManager + */ + private $groupManager; + + public function __construct(IDBConnection $db, CardMapper $cardMapper, IUserManager $userManager, IGroupManager $groupManager) { + parent::__construct($db, 'deck_assigned_labels', Labels::class); + $this->cardMapper = $cardMapper; + $this->userManager = $userManager; + $this->groupManager = $groupManager; + } + + /** + * + * @param $cardId + * @return array|Entity + */ + public function find($cardId) { + $sql = 'SELECT l.*,card_id FROM `*PREFIX*deck_assigned_labels` as al ' . + 'INNER JOIN `*PREFIX*deck_labels` as l ON l.id = al.label_id ' . + 'WHERE `card_id` = ?'; + + $labels = $this->findEntities($sql, [$cardId]); + return $labels; + } + +} diff --git a/lib/Service/StackService.php b/lib/Service/StackService.php index e8158241c..65214528a 100644 --- a/lib/Service/StackService.php +++ b/lib/Service/StackService.php @@ -29,6 +29,9 @@ use OCA\Deck\Activity\ChangeSet; use OCA\Deck\BadRequestException; use OCA\Deck\Db\Acl; use OCA\Deck\Db\AssignedUsersMapper; +use OCA\Deck\Db\AssignedUsers; +use OCA\Deck\Db\AssignedLabelsMapper; +use OCA\Deck\Db\AssignedLabels; use OCA\Deck\Db\BoardMapper; use OCA\Deck\Db\Card; use OCA\Deck\Db\CardMapper; @@ -52,6 +55,7 @@ class StackService { private $boardService; private $cardService; private $assignedUsersMapper; + private $assignedLabelsMapper; private $attachmentService; private $activityManager; @@ -70,6 +74,7 @@ class StackService { BoardService $boardService, CardService $cardService, AssignedUsersMapper $assignedUsersMapper, + AssignedLabelsMapper $assignedLabelsMapper, AttachmentService $attachmentService, ActivityManager $activityManager, EventDispatcherInterface $eventDispatcher, @@ -85,6 +90,7 @@ class StackService { $this->boardService = $boardService; $this->cardService = $cardService; $this->assignedUsersMapper = $assignedUsersMapper; + $this->assignedLabelsMapper = $assignedLabelsMapper; $this->attachmentService = $attachmentService; $this->activityManager = $activityManager; $this->eventDispatcher = $eventDispatcher; @@ -415,6 +421,7 @@ class StackService { ); $cards = $this->cardMapper->findAll($id); + $c = []; foreach ($cards as $card) { $newCard = new Card(); @@ -437,40 +444,42 @@ class StackService { ); if ($boardId === $stack->getBoardId()) { - $labels = $this->labelMapper->findAll($card->getId()); - $labels = $this->labelMapper->findAssignedLabelsForCard($card->id); - + + $assignedLabels = $this->assignedLabelsMapper->find($card->getId()); $l = []; - foreach ($labels as $label) { - $l = $this->cardMapper->assignLabel($newCard->getId(), $label->getId()); + foreach ($assignedLabels as $assignedLabel) { + + $assignment = $assignedLabel; + $assignment->setCardId($newCard->getId()); + $assignment = $this->assignedLabelsMapper->insert($assignment); + + + // $assignment = new AssignedLabels(); + // $assignment->setCardId($newCard->getId()); + // $assignment->setLabel($assignedLabel); + // $assignment = $this->assignedLabelsMapper->insert($assignment); + $l[] = $assignment; } $newCard->setLabels($l); - $assignedUsers = $this->assignedUsersMapper->find($card->getId()); - /* foreach ($assignedUsers as $assignedUser) { - $u = $this->assignmentService->assignUser($newCard->getId(), $assignedUser->getId()); - $newCard->setAssignedUsers($u); - } */ - - //attachments??? - - - + $u = []; + foreach ($assignedUsers as $assignedUser) { + $assignment = new AssignedUsers(); + $assignment->setCardId($newCard->getId()); + $assignment->setParticipant($assignedUser->getParticipant()); + $assignment->setType($assignedUser->getType()); + $assignment = $this->assignedUsersMapper->insert($assignment); + $u[] = $assignment; + } + $newCard->setAssignedUsers($u); + $c[] = $newCard; } } - $createdCards = $this->cardMapper->findAll($newStack->getId()); - $newStack->setCards($createdCards); - - - - - - - + $newStack->setCards($c); return $newStack; } }