Skip to content

Commit d6af11e

Browse files
committed
assign label
Signed-off-by: Jakob Röhrl <[email protected]>
1 parent 1dce89e commit d6af11e

File tree

4 files changed

+136
-28
lines changed

4 files changed

+136
-28
lines changed

lib/Db/AssignedLabels.php

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2020 Jakob Röhrl <[email protected]>
4+
*
5+
* @author Jakob Röhrl <[email protected]>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
namespace OCA\Deck\Db;
25+
26+
use JsonSerializable;
27+
28+
class AssignedLabels extends RelationalEntity implements JsonSerializable {
29+
public $id;
30+
protected $label;
31+
protected $cardId;
32+
33+
public function __construct() {
34+
$this->addType('id', 'integer');
35+
$this->addType('cardId', 'integer');
36+
$this->addResolvable('label');
37+
}
38+
}

lib/Db/AssignedLabelsMapper.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2020 Jakob Röhrl <[email protected]>
4+
*
5+
* @author Jakob Röhrl <[email protected]>
6+
*
7+
* @license GNU AGPL version 3 or any later version
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
25+
namespace OCA\Deck\Db;
26+
27+
use OCP\AppFramework\Db\Entity;
28+
use OCP\IDBConnection;
29+
use OCP\IGroupManager;
30+
use OCP\IUserManager;
31+
32+
class AssignedLabelsMapper extends DeckMapper {
33+
private $cardMapper;
34+
private $userManager;
35+
/**
36+
* @var IGroupManager
37+
*/
38+
private $groupManager;
39+
40+
public function __construct(IDBConnection $db, CardMapper $cardMapper, IUserManager $userManager, IGroupManager $groupManager) {
41+
parent::__construct($db, 'deck_assigned_labels', Labels::class);
42+
$this->cardMapper = $cardMapper;
43+
$this->userManager = $userManager;
44+
$this->groupManager = $groupManager;
45+
}
46+
47+
/**
48+
*
49+
* @param $cardId
50+
* @return array|Entity
51+
*/
52+
public function find($cardId) {
53+
$sql = 'SELECT l.*,card_id FROM `*PREFIX*deck_assigned_labels` as al ' .
54+
'INNER JOIN `*PREFIX*deck_labels` as l ON l.id = al.label_id ' .
55+
'WHERE `card_id` = ?';
56+
57+
$labels = $this->findEntities($sql, [$cardId]);
58+
return $labels;
59+
}
60+
61+
}

lib/Service/StackService.php

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
use OCA\Deck\BadRequestException;
3030
use OCA\Deck\Db\Acl;
3131
use OCA\Deck\Db\AssignedUsersMapper;
32+
use OCA\Deck\Db\AssignedUsers;
33+
use OCA\Deck\Db\AssignedLabelsMapper;
34+
use OCA\Deck\Db\AssignedLabels;
3235
use OCA\Deck\Db\BoardMapper;
3336
use OCA\Deck\Db\Card;
3437
use OCA\Deck\Db\CardMapper;
@@ -52,6 +55,7 @@ class StackService {
5255
private $boardService;
5356
private $cardService;
5457
private $assignedUsersMapper;
58+
private $assignedLabelsMapper;
5559
private $attachmentService;
5660

5761
private $activityManager;
@@ -70,6 +74,7 @@ public function __construct(
7074
BoardService $boardService,
7175
CardService $cardService,
7276
AssignedUsersMapper $assignedUsersMapper,
77+
AssignedLabelsMapper $assignedLabelsMapper,
7378
AttachmentService $attachmentService,
7479
ActivityManager $activityManager,
7580
EventDispatcherInterface $eventDispatcher,
@@ -85,6 +90,7 @@ public function __construct(
8590
$this->boardService = $boardService;
8691
$this->cardService = $cardService;
8792
$this->assignedUsersMapper = $assignedUsersMapper;
93+
$this->assignedLabelsMapper = $assignedLabelsMapper;
8894
$this->attachmentService = $attachmentService;
8995
$this->activityManager = $activityManager;
9096
$this->eventDispatcher = $eventDispatcher;
@@ -417,6 +423,7 @@ public function clone($id, $boardId, $userId) {
417423
);
418424

419425
$cards = $this->cardMapper->findAll($id);
426+
$c = [];
420427
foreach ($cards as $card) {
421428

422429
$newCard = new Card();
@@ -439,40 +446,42 @@ public function clone($id, $boardId, $userId) {
439446
);
440447

441448
if ($boardId === $stack->getBoardId()) {
442-
$labels = $this->labelMapper->findAll($card->getId());
443-
$labels = $this->labelMapper->findAssignedLabelsForCard($card->id);
444-
449+
450+
$assignedLabels = $this->assignedLabelsMapper->find($card->getId());
445451
$l = [];
446-
foreach ($labels as $label) {
447-
$l = $this->cardMapper->assignLabel($newCard->getId(), $label->getId());
452+
foreach ($assignedLabels as $assignedLabel) {
453+
454+
$assignment = $assignedLabel;
455+
$assignment->setCardId($newCard->getId());
456+
$assignment = $this->assignedLabelsMapper->insert($assignment);
457+
458+
459+
// $assignment = new AssignedLabels();
460+
// $assignment->setCardId($newCard->getId());
461+
// $assignment->setLabel($assignedLabel);
462+
// $assignment = $this->assignedLabelsMapper->insert($assignment);
463+
$l[] = $assignment;
448464
}
449465
$newCard->setLabels($l);
450466

451-
452467
$assignedUsers = $this->assignedUsersMapper->find($card->getId());
453-
/* foreach ($assignedUsers as $assignedUser) {
454-
$u = $this->assignmentService->assignUser($newCard->getId(), $assignedUser->getId());
455-
$newCard->setAssignedUsers($u);
456-
} */
457-
458-
//attachments???
459-
460-
461-
468+
$u = [];
469+
foreach ($assignedUsers as $assignedUser) {
470+
$assignment = new AssignedUsers();
471+
$assignment->setCardId($newCard->getId());
472+
$assignment->setParticipant($assignedUser->getParticipant());
473+
$assignment->setType($assignedUser->getType());
474+
$assignment = $this->assignedUsersMapper->insert($assignment);
475+
$u[] = $assignment;
476+
}
477+
$newCard->setAssignedUsers($u);
478+
$c[] = $newCard;
462479

463480
}
464481

465482
}
466483

467-
$createdCards = $this->cardMapper->findAll($newStack->getId());
468-
$newStack->setCards($createdCards);
469-
470-
471-
472-
473-
474-
475-
484+
$newStack->setCards($c);
476485
return $newStack;
477486
}
478487
}

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)