@@ 500-526 (lines=27) @@ | ||
497 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
|
498 | * @throws BadRequestException |
|
499 | */ |
|
500 | public function assignLabel($cardId, $labelId) { |
|
501 | ||
502 | if (is_numeric($cardId) === false) { |
|
503 | throw new BadRequestException('card id must be a number'); |
|
504 | } |
|
505 | ||
506 | if (is_numeric($labelId) === false) { |
|
507 | throw new BadRequestException('label id must be a number'); |
|
508 | } |
|
509 | ||
510 | $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); |
|
511 | if ($this->boardService->isArchived($this->cardMapper, $cardId)) { |
|
512 | throw new StatusException('Operation not allowed. This board is archived.'); |
|
513 | } |
|
514 | $card = $this->cardMapper->find($cardId); |
|
515 | if ($card->getArchived()) { |
|
516 | throw new StatusException('Operation not allowed. This card is archived.'); |
|
517 | } |
|
518 | $label = $this->labelMapper->find($labelId); |
|
519 | $this->cardMapper->assignLabel($cardId, $labelId); |
|
520 | $this->changeHelper->cardChanged($cardId, false); |
|
521 | $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_ASSIGN, ['label' => $label]); |
|
522 | ||
523 | $this->eventDispatcher->dispatch( |
|
524 | '\OCA\Deck\Card::onUpdate', new GenericEvent(null, ['id' => $cardId, 'card' => $card]) |
|
525 | ); |
|
526 | } |
|
527 | ||
528 | /** |
|
529 | * @param $cardId |
|
@@ 537-563 (lines=27) @@ | ||
534 | * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException |
|
535 | * @throws BadRequestException |
|
536 | */ |
|
537 | public function removeLabel($cardId, $labelId) { |
|
538 | ||
539 | if (is_numeric($cardId) === false) { |
|
540 | throw new BadRequestException('card id must be a number'); |
|
541 | } |
|
542 | ||
543 | if (is_numeric($labelId) === false) { |
|
544 | throw new BadRequestException('label id must be a number'); |
|
545 | } |
|
546 | ||
547 | $this->permissionService->checkPermission($this->cardMapper, $cardId, Acl::PERMISSION_EDIT); |
|
548 | if ($this->boardService->isArchived($this->cardMapper, $cardId)) { |
|
549 | throw new StatusException('Operation not allowed. This board is archived.'); |
|
550 | } |
|
551 | $card = $this->cardMapper->find($cardId); |
|
552 | if ($card->getArchived()) { |
|
553 | throw new StatusException('Operation not allowed. This card is archived.'); |
|
554 | } |
|
555 | $label = $this->labelMapper->find($labelId); |
|
556 | $this->cardMapper->removeLabel($cardId, $labelId); |
|
557 | $this->changeHelper->cardChanged($cardId, false); |
|
558 | $this->activityManager->triggerEvent(ActivityManager::DECK_OBJECT_CARD, $card, ActivityManager::SUBJECT_LABEL_UNASSING, ['label' => $label]); |
|
559 | ||
560 | $this->eventDispatcher->dispatch( |
|
561 | '\OCA\Deck\Card::onUpdate', new GenericEvent(null, ['id' => $cardId, 'card' => $card]) |
|
562 | ); |
|
563 | } |
|
564 | ||
565 | /** |
|
566 | * @param $cardId |