diff options
| author | Ron Lucke <lucke@elan-ev.de> | 2023-12-11 10:37:55 +0000 |
|---|---|---|
| committer | Ron Lucke <lucke@elan-ev.de> | 2023-12-11 10:37:55 +0000 |
| commit | f2767008ffcf723bc73a4ea8781b31f23c2b68e5 (patch) | |
| tree | 55d6c4b96b65f42545d9a624263089f5f5cb06a4 /lib/models/Courseware/Unit.php | |
| parent | 47e23c2e78b4cc099dc6217fa0827a033ef0dc9f (diff) | |
TIC #3111
Closes #3111
Merge request studip/studip!2295
Diffstat (limited to 'lib/models/Courseware/Unit.php')
| -rw-r--r-- | lib/models/Courseware/Unit.php | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/models/Courseware/Unit.php b/lib/models/Courseware/Unit.php index 6f3535d..bf08328 100644 --- a/lib/models/Courseware/Unit.php +++ b/lib/models/Courseware/Unit.php @@ -172,4 +172,33 @@ class Unit extends \SimpleORMap implements \PrivacyObject $stmt = $db->prepare($query); $stmt->execute($args); } + + public function hasRootLayout() + { + return !isset($this->config['root_layout']) || $this->config['root_layout'] !== 'none'; + } + + public function findOrCreateFirstElement(): StructuralElement + { + if ($this->hasRootLayout()) { + return $this->structural_element; + } + + $children = $this->structural_element->children; + if (count($children) > 0) { + return $children[0]; + } + + $struct = StructuralElement::create([ + 'parent_id' => $this->structural_element->id, + 'range_id' => $this->range_id, + 'range_type' => $this->range_type, + 'owner_id' => $this->structural_element->owner_id, + 'editor_id' => $this->structural_element->editor_id, + 'title' => _('neue Seite'), + ]); + + + return $struct; + } } |
