Skip to content

Commit

Permalink
exc irss, ii
Browse files Browse the repository at this point in the history
  • Loading branch information
alex40724 committed Oct 18, 2023
1 parent fc3d0ca commit 03f7845
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
16 changes: 2 additions & 14 deletions Modules/Exercise/Assignment/class.ilExAssignment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}


Expand Down
21 changes: 19 additions & 2 deletions Modules/Exercise/IRSS/CollectionWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions Modules/Exercise/InstructionFile/InstructionFileManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

}
25 changes: 22 additions & 3 deletions Modules/Exercise/InstructionFile/InstructionFileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -49,15 +49,20 @@ 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 ",
["integer"],
[$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);
}
Expand All @@ -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
);
}

}

0 comments on commit 03f7845

Please sign in to comment.