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