From 03f78457836ef7271e30edc549cb28f9dbb9dce1 Mon Sep 17 00:00:00 2001 From: Alexander Killing Date: Wed, 18 Oct 2023 08:46:27 +0200 Subject: [PATCH] exc irss, ii --- .../Assignment/class.ilExAssignment.php | 16 ++---------- Modules/Exercise/IRSS/CollectionWrapper.php | 21 ++++++++++++++-- .../InstructionFileManager.php | 8 ++++++ .../InstructionFileRepository.php | 25 ++++++++++++++++--- 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/Modules/Exercise/Assignment/class.ilExAssignment.php b/Modules/Exercise/Assignment/class.ilExAssignment.php index 63ae1b4d2673..ba8a89dec127 100644 --- a/Modules/Exercise/Assignment/class.ilExAssignment.php +++ b/Modules/Exercise/Assignment/class.ilExAssignment.php @@ -864,20 +864,8 @@ public function delete(): void $reminder->deleteReminders($this->getId()); // delete resource collections and resources - $this->deleteResourceCollection( - $this->getInstructionFileRCID(), - new ilExcInstructionFilesStakeholder() - ); - } - - private function deleteResourceCollection( - ?ResourceCollectionIdentification $rcid, - ResourceStakeholder $stakeholder - ): void { - if ($rcid === null) { - return; - } - $this->irss->collection()->remove($rcid, $stakeholder, true); + $this->domain->assignment()->instructionFiles($this->getId()) + ->deleteCollection(); } diff --git a/Modules/Exercise/IRSS/CollectionWrapper.php b/Modules/Exercise/IRSS/CollectionWrapper.php index 825251b5100a..684db1a09998 100644 --- a/Modules/Exercise/IRSS/CollectionWrapper.php +++ b/Modules/Exercise/IRSS/CollectionWrapper.php @@ -34,21 +34,38 @@ public function __construct() $this->upload = $DIC->upload(); } - public function getNewCollectionId() :ResourceCollectionIdentification + protected function getNewCollectionId() :ResourceCollectionIdentification { return $this->irss->collection()->id(); } - public function getNewCollectionIdAsString() : string + protected function getNewCollectionIdAsString() : string { return $this->getNewCollectionId()->serialize(); } + public function createEmptyCollection() : string + { + $new_id = $this->getNewCollectionId(); + $new_collection = $this->irss->collection()->get($new_id); + $this->irss->collection()->store($new_collection); + return $new_id->serialize(); + } + public function getCollectionForIdString(string $rcid) : ResourceCollection { return $this->irss->collection()->get($this->irss->collection()->id($rcid)); } + public function deleteCollectionForIdString( + string $rcid, + ResourceStakeholder $stakeholder + ): void + { + $id = $this->irss->collection()->id($rcid); + $this->irss->collection()->remove($id, $this->stakeholder, true); + } + public function importFilesFromLegacyUploadToCollection( ResourceCollection $collection, array $file_input, diff --git a/Modules/Exercise/InstructionFile/InstructionFileManager.php b/Modules/Exercise/InstructionFile/InstructionFileManager.php index cd7944c00f0c..10eec0f6b6fa 100644 --- a/Modules/Exercise/InstructionFile/InstructionFileManager.php +++ b/Modules/Exercise/InstructionFile/InstructionFileManager.php @@ -51,4 +51,12 @@ public function importFromLegacyUpload(array $file_input) : void $this->stakeholder ); } + + public function deleteCollection(): void { + $this->repo->deleteCollection( + $this->ass_id, + $this->stakeholder + ); + } + } \ No newline at end of file diff --git a/Modules/Exercise/InstructionFile/InstructionFileRepository.php b/Modules/Exercise/InstructionFile/InstructionFileRepository.php index a803963b2552..3dd25246e574 100644 --- a/Modules/Exercise/InstructionFile/InstructionFileRepository.php +++ b/Modules/Exercise/InstructionFile/InstructionFileRepository.php @@ -40,7 +40,7 @@ public function __construct( public function createCollection(int $ass_id) : void { - $new_id = $this->wrapper->getNewCollectionIdAsString(); + $new_id = $this->wrapper->createEmptyCollection(); $this->db->update("exc_assignment", [ "if_rcid" => ["text", $new_id] ], [ // where @@ -49,7 +49,7 @@ public function createCollection(int $ass_id) : void ); } - public function getCollection(int $ass_id) : ?ResourceCollection + protected function getIdStringForAssId(int $ass_id) : string { $set = $this->db->queryF("SELECT if_rcid FROM exc_assignment " . " WHERE id = %s ", @@ -57,7 +57,12 @@ public function getCollection(int $ass_id) : ?ResourceCollection [$ass_id] ); $rec = $this->db->fetchAssoc($set); - $rcid = ($rec["if_rcid"] ?? ""); + return ($rec["if_rcid"] ?? ""); + } + + public function getCollection(int $ass_id) : ?ResourceCollection + { + $rcid = $this->getIdStringForAssId($ass_id); if ($rcid !== "") { return $this->wrapper->getCollectionForIdString($rcid); } @@ -80,4 +85,18 @@ public function importFromLegacyUpload( } } + public function deleteCollection( + int $ass_id, + ResourceStakeholder $stakeholder + ): void { + $rcid = $this->getIdStringForAssId($ass_id); + if ($rcid === "") { + return; + } + $this->wrapper->deleteCollectionForIdString( + $rcid, + $stakeholder + ); + } + } \ No newline at end of file