From 90ed412323f7169c69f39849672c24646393d200 Mon Sep 17 00:00:00 2001
From: Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de>
Date: Fri, 21 Jul 2023 15:06:34 +0000
Subject: [PATCH] fix order during export and linking, fixes #2959 and #1361

Closes #2959 and #1361

Merge request studip/studip!1991
---
 lib/models/Courseware/StructuralElement.php | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/lib/models/Courseware/StructuralElement.php b/lib/models/Courseware/StructuralElement.php
index 277e61bf5b2..890ba4183c0 100644
--- a/lib/models/Courseware/StructuralElement.php
+++ b/lib/models/Courseware/StructuralElement.php
@@ -982,9 +982,7 @@ SQL;
 
     private function linkChildren(User $user, StructuralElement $newElement): void
     {
-        $children = self::findBySQL('parent_id = ?', [$this->id]);
-
-        foreach ($children as $child) {
+        foreach ($this->children as $child) {
             $child->link($user, $newElement);
         }
     }
@@ -1041,9 +1039,8 @@ SQL;
 
     private function getChildrenPdfExport(int $depth, bool $with_children, $user, $doc)
     {
-        $children = self::findBySQL('parent_id = ?', [$this->id]);
         $depth++;
-        foreach ($children as $child) {
+        foreach ($this->children as $child) {
             $child->getElementPdfExport($depth, $with_children, $user, $doc);
         }
     }
-- 
GitLab