aboutsummaryrefslogtreecommitdiff
path: root/lib/models/Modul.php
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2023-03-23 14:33:04 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2023-03-23 14:33:04 +0000
commit2a697c4ba43f5521c2c5348f25cb3254894ce91a (patch)
tree4a02017e994f36a8b63c9ef66c41e808db67c420 /lib/models/Modul.php
parent78e742eb1c2efad1c90444da3f3ce3f299faba8e (diff)
fix responsible institute assignment for modules, fixes #2434
Closes #2434 Merge request studip/studip!1625
Diffstat (limited to 'lib/models/Modul.php')
-rw-r--r--lib/models/Modul.php20
1 files changed, 13 insertions, 7 deletions
diff --git a/lib/models/Modul.php b/lib/models/Modul.php
index a3d7d9c..80e2753 100644
--- a/lib/models/Modul.php
+++ b/lib/models/Modul.php
@@ -397,15 +397,21 @@ class Modul extends ModuleManagementModelTreeItem
if (!$institute) {
return false;
}
- if ($this->responsible_institute && $this->responsible_institute->institut_id != $institut_id) {
- $this->responsible_institute && $this->responsible_institute->delete();
- $resp_institute = new ModulInst();
- $resp_institute->institut_id = $institute->id;
- $resp_institute->modul_id = $this->id;
- $resp_institute->gruppe = 'hauptverantwortlich';
- $this->responsible_institute = $resp_institute;
+
+ if (!$this->responsible_institute || $this->responsible_institute->institut_id !== $institut_id) {
+ if ($this->responsible_institute) {
+ $this->responsible_institute->delete();
+ }
+
+ $this->responsible_institute = ModulInst::build([
+ 'institut_id' => $institute->id,
+ 'modul_id' => $this->id,
+ 'gruppe' => 'hauptverantwortlich',
+ ]);
}
+
$this->assigned_institutes->unsetBy('institut_id', $institute->id);
+
return true;
}