@@ -673,4 +673,71 @@ public function getCardUrl(int $cardId): string {
673673 public function getRedirectUrlForCard (int $ cardId ): string {
674674 return $ this ->urlGenerator ->linkToRouteAbsolute ('deck.page.redirectToCard ' , ['cardId ' => $ cardId ]);
675675 }
676+
677+ /**
678+ * @throws StatusException
679+ * @throws \OCA\Deck\NoPermissionException
680+ * @throws \OCP\AppFramework\Db\DoesNotExistException
681+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
682+ * @throws BadRequestException
683+ */
684+ public function assignDependentCard (int $ cardId , int $ dependentCardId ): Card {
685+ $ this ->permissionService ->checkPermission ($ this ->cardMapper , $ cardId , Acl::PERMISSION_EDIT );
686+ $ this ->permissionService ->checkPermission ($ this ->cardMapper , $ dependentCardId , Acl::PERMISSION_READ );
687+
688+ if ($ this ->boardService ->isArchived ($ this ->cardMapper , $ cardId )) {
689+ throw new StatusException ('Operation not allowed. This board is archived. ' );
690+ }
691+
692+ $ card = $ this ->cardMapper ->find ($ cardId );
693+ if ($ card ->getArchived ()) {
694+ throw new StatusException ('Operation not allowed. This card is archived. ' );
695+ }
696+
697+ $ dependentCards = $ card ->getDependentCards () ?? [];
698+ if (!in_array ($ dependentCardId , $ dependentCards , true )) {
699+ $ dependentCards [] = $ dependentCardId ;
700+ $ card ->setDependentCards ($ dependentCards );
701+ $ card = $ this ->cardMapper ->update ($ card );
702+ $ this ->changeHelper ->cardChanged ($ cardId );
703+ $ this ->activityManager ->triggerEvent (ActivityManager::DECK_OBJECT_CARD , $ card , ActivityManager::SUBJECT_CARD_UPDATE );
704+ }
705+
706+ [$ card ] = $ this ->enrichCards ([$ card ]);
707+ return $ card ;
708+ }
709+
710+ /**
711+ * @throws StatusException
712+ * @throws \OCA\Deck\NoPermissionException
713+ * @throws \OCP\AppFramework\Db\DoesNotExistException
714+ * @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException
715+ * @throws BadRequestException
716+ */
717+ public function removeDependentCard (int $ cardId , int $ dependentCardId ): Card {
718+ $ this ->permissionService ->checkPermission ($ this ->cardMapper , $ cardId , Acl::PERMISSION_EDIT );
719+ $ this ->permissionService ->checkPermission ($ this ->cardMapper , $ dependentCardId , Acl::PERMISSION_READ );
720+
721+ if ($ this ->boardService ->isArchived ($ this ->cardMapper , $ cardId )) {
722+ throw new StatusException ('Operation not allowed. This board is archived. ' );
723+ }
724+
725+ $ card = $ this ->cardMapper ->find ($ cardId );
726+ if ($ card ->getArchived ()) {
727+ throw new StatusException ('Operation not allowed. This card is archived. ' );
728+ }
729+
730+ $ dependentCards = $ card ->getDependentCards () ?? [];
731+ $ key = array_search ($ dependentCardId , $ dependentCards , true );
732+ if ($ key !== false ) {
733+ unset($ dependentCards [$ key ]);
734+ $ card ->setDependentCards (array_values ($ dependentCards ));
735+ $ card = $ this ->cardMapper ->update ($ card );
736+ $ this ->changeHelper ->cardChanged ($ cardId );
737+ $ this ->activityManager ->triggerEvent (ActivityManager::DECK_OBJECT_CARD , $ card , ActivityManager::SUBJECT_CARD_UPDATE );
738+ }
739+
740+ [$ card ] = $ this ->enrichCards ([$ card ]);
741+ return $ card ;
742+ }
676743}
0 commit comments