diff --git a/lib/models/Courseware/Container.php b/lib/models/Courseware/Container.php index b42856d56eff0060018b001a1fd1cffe5c488fae..1f621e5c88343efef56dbc2a2c5dd5ce91e649b8 100644 --- a/lib/models/Courseware/Container.php +++ b/lib/models/Courseware/Container.php @@ -120,7 +120,7 @@ class Container extends \SimpleORMap $container->store(); - $blockMap = self::copyBlocks($user, $container, $this); + $blockMap = $this->copyBlocks($user, $container); $container['payload'] = $container->type->copyPayload($blockMap); @@ -129,13 +129,11 @@ class Container extends \SimpleORMap return $container; } - private function copyBlocks(User $user, Container $newContainer, Container $remoteContainer): array + private function copyBlocks(User $user, Container $newContainer): array { $blockMap = []; - $blocks = Block::findBySQL('container_id = ?', [$remoteContainer->id]); - - foreach ($blocks as $block) { + foreach ($this->blocks as $block) { $newBlock = $block->copy($user, $newContainer); $blockMap[$block->id] = $newBlock->id; } diff --git a/lib/models/Courseware/StructuralElement.php b/lib/models/Courseware/StructuralElement.php index 5b834e9cd97a7ba3e730c0a35d3c9972c7faf833..8edabadb5fcb4e67ca8c49954e05bd60d6daaf65 100644 --- a/lib/models/Courseware/StructuralElement.php +++ b/lib/models/Courseware/StructuralElement.php @@ -678,7 +678,7 @@ SQL; */ public function copy(User $user, StructuralElement $parent, string $purpose = ''): StructuralElement { - $file_ref_id = self::copyImage($user, $parent); + $file_ref_id = $this->copyImage($user, $parent); $element = self::build([ 'parent_id' => $parent->id, @@ -696,9 +696,9 @@ SQL; $element->store(); - self::copyContainers($user, $element); + $this->copyContainers($user, $element); - self::copyChildren($user, $element, $purpose); + $this->copyChildren($user, $element, $purpose); return $element; } @@ -724,7 +724,7 @@ SQL; { // merge with target if (!$target->image_id) { - $target->image_id = self::copyImage($user, $target); + $target->image_id = $this->copyImage($user, $target); } if ($target->title === 'neue Seite' || $target->title === 'New page') { @@ -762,29 +762,24 @@ SQL; $target->store(); // add Containers to target - self::copyContainers($user, $target); + $this->copyContainers($user, $target); // copy Children - - self::copyChildren($user, $target); + $this->copyChildren($user, $target); return $this; } private function copyContainers(User $user, StructuralElement $newElement): void { - $containers = \Courseware\Container::findBySQL('structural_element_id = ?', [$this->id]); - - foreach ($containers as $container) { + foreach ($this->containers as $container) { $container->copy($user, $newElement); } } private function copyChildren(User $user, StructuralElement $newElement, string $purpose = ''): void { - $children = self::findBySQL('parent_id = ?', [$this->id]); - - foreach ($children as $child) { + foreach ($this->children as $child) { $child->copy($user, $newElement, $purpose); } }