aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2025-03-10 11:03:26 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2025-03-10 11:03:26 +0000
commit7403c2be52ab969899bc9171fdba7c49c6deff89 (patch)
tree28cb58f4c2f9381a129b4aa16e9114fe8391e01f /lib
parent985d3701af01f716166f233144187693c9dbc88f (diff)
fix position on statusgroups upon creation and ordering, fixes #5356
Closes #5356 Merge request studip/studip!4026
Diffstat (limited to 'lib')
-rw-r--r--lib/models/Course.php1
-rw-r--r--lib/models/Statusgruppen.php8
2 files changed, 4 insertions, 5 deletions
diff --git a/lib/models/Course.php b/lib/models/Course.php
index df8be3b..5e6d7f4 100644
--- a/lib/models/Course.php
+++ b/lib/models/Course.php
@@ -130,6 +130,7 @@ class Course extends SimpleORMap implements Range, PrivacyObject, StudipItem, Fe
];
$config['has_many']['statusgruppen'] = [
'class_name' => Statusgruppen::class,
+ 'order_by' => 'ORDER BY position',
'on_delete' => 'delete',
'on_store' => 'store',
];
diff --git a/lib/models/Statusgruppen.php b/lib/models/Statusgruppen.php
index 78153dc..015a306 100644
--- a/lib/models/Statusgruppen.php
+++ b/lib/models/Statusgruppen.php
@@ -720,11 +720,9 @@ class Statusgruppen extends SimpleORMap implements PrivacyObject
public function cbAddPosition()
{
if ($this->position === null) {
- $sql = "SELECT MAX(position) FROM statusgruppen WHERE range_id = ?";
- $stmt = DBManager::get()->prepare($sql);
- $stmt->execute([$this->range_id]);
- $max_position = $stmt->fetchColumn();
- $this->position = $max_position === null ? 0 : $max_position + 1;
+ $sql = "SELECT MAX(`position`) FROM `statusgruppen` WHERE `range_id` = ?";
+ $max_position = DBManager::get()->fetchColumn($sql, [$this->range_id]);
+ $this->position = $max_position === null ? 0 : (int) $max_position + 1;
}
}