diff options
| author | Ron Lucke <lucke@elan-ev.de> | 2022-06-01 10:44:35 +0000 |
|---|---|---|
| committer | David Siegfried <david.siegfried@uni-vechta.de> | 2022-06-01 10:44:35 +0000 |
| commit | 9e316669dc9b7e8a13391f353d839e66513e80a5 (patch) | |
| tree | 7f231ca05071b8e0a3200e5de536d26b53abf14f /lib/models/Courseware/StructuralElement.php | |
| parent | ae12d3c86e59a392e835ece4be0a750bb80e460c (diff) | |
fix #1112
Closes #1112
Merge request studip/studip!670
Diffstat (limited to 'lib/models/Courseware/StructuralElement.php')
| -rwxr-xr-x | lib/models/Courseware/StructuralElement.php | 37 |
1 files changed, 26 insertions, 11 deletions
diff --git a/lib/models/Courseware/StructuralElement.php b/lib/models/Courseware/StructuralElement.php index 69d9d22..ac6116f 100755 --- a/lib/models/Courseware/StructuralElement.php +++ b/lib/models/Courseware/StructuralElement.php @@ -309,16 +309,19 @@ class StructuralElement extends \SimpleORMap } if ($this->isTask()) { - // TODO: Was tun wir, wenn dieses Strukturelement purpose=task aber keinen Task hat? - if (!$this->task) { - return false; + $task = $this->task; + if (!$task) { + $task = $this->findParentTask(); + if (!$task) { + return false; + } } - if ($this->task->isSubmitted() && $this->hasEditingPermission($user)) { + if ($task->isSubmitted() && $this->hasEditingPermission($user)) { return true; } - return $this->task->userIsASolver($user); + return $task->userIsASolver($user); } if ($this->canEdit($user)) { @@ -660,7 +663,7 @@ SQL; * * @return StructuralElement the copy of this instance */ - public function copy(User $user, StructuralElement $parent): StructuralElement + public function copy(User $user, StructuralElement $parent, string $purpose = ''): StructuralElement { $file_ref_id = self::copyImage($user, $parent); @@ -672,7 +675,7 @@ SQL; 'editor_id' => $user->id, 'edit_blocker_id' => null, 'title' => $this->title, - 'purpose' => $this->purpose, + 'purpose' => empty($purpose) ? $this->purpose : $purpose, 'position' => $parent->countChildren(), 'payload' => $this->payload, 'image_id' => $file_ref_id, @@ -682,12 +685,12 @@ SQL; self::copyContainers($user, $element); - self::copyChildren($user, $element); + self::copyChildren($user, $element, $purpose); return $element; } - private function copyImage(User $user, StructuralElement $parent) : ?String + private function copyImage(User $user, StructuralElement $parent) : ?string { $file_ref_id = null; @@ -764,12 +767,12 @@ SQL; } } - private function copyChildren(User $user, StructuralElement $newElement): void + private function copyChildren(User $user, StructuralElement $newElement, string $purpose = ''): void { $children = self::findBySQL('parent_id = ?', [$this->id]); foreach ($children as $child) { - $child->copy($user, $newElement); + $child->copy($user, $newElement, $purpose); } } @@ -837,4 +840,16 @@ SQL; return $html; } + + private function findParentTask() + { + if ($this->isRootNode()) { + return null; + } + if ($this->task) { + return $this->task; + } + + return $this->parent->findParentTask(); + } } |
