Commit 69cb95b2 authored by Mahmoud Aglan's avatar Mahmoud Aglan

Enforce no two groups on same cell, allow trainer overlap

- Group-to-group segment overlap is blocked (hard error)
- Trainer-to-group overlap is allowed (trainers supervise areas)
- Checks pending unsaved assignments, not just DB reservations
- Proper Arabic error message explaining the constraint
Co-Authored-By: 's avatarClaude Opus 4.6 <noreply@anthropic.com>
parent 4794a02c
...@@ -173,7 +173,28 @@ public function assignGroupToSegments(int $groupId, array $segmentIds): void ...@@ -173,7 +173,28 @@ public function assignGroupToSegments(int $groupId, array $segmentIds): void
return; return;
} }
// 2. Check group isn't already assigned in this slot (in current unsaved assignments) // 2. Check segments aren't already claimed by another group (group-to-group overlap is blocked)
// Trainers CAN overlap with groups (supervision), but two groups cannot share cells.
foreach ($this->assignments as $assignment) {
$assignType = $assignment['type'] ?? '';
if ($assignType === 'trainer') continue; // trainers don't block groups
$occupiedSegments = $assignment['segment_ids'] ?? [];
$overlap = array_intersect($segmentIds, $occupiedSegments);
if (!empty($overlap)) {
$ownerName = $assignment['group_name'] ?? $assignment['title'] ?? __('مجموعة أخرى');
$this->conflicts = [[
'category' => 'segment_taken',
'title' => $ownerName,
'message' => __('الخلايا المحددة مشغولة بالفعل بواسطة') . ' "' . $ownerName . '" — ' . __('لا يمكن لمجموعتين مشاركة نفس المساحة'),
'time' => $this->selectedSlotStart . ' - ' . $this->selectedSlotEnd,
]];
return;
}
}
// 3. Check same group isn't already assigned in this slot
foreach ($this->assignments as $assignment) { foreach ($this->assignments as $assignment) {
if (($assignment['group_id'] ?? null) === $groupId && ($assignment['type'] ?? '') !== 'existing') { if (($assignment['group_id'] ?? null) === $groupId && ($assignment['type'] ?? '') !== 'existing') {
$this->addError('assignment', __('هذه المجموعة معيّنة بالفعل في هذا الوقت')); $this->addError('assignment', __('هذه المجموعة معيّنة بالفعل في هذا الوقت'));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment