Feat: Назначения курсов с tags-input
✅ CourseAssignmentController (index, create, store) ✅ create.blade.php с тремя tags-input (пользователи/группы/организации) ✅ Разные цвета бейджей (зелёный/голубой/синий) ✅ UserSearchController API ✅ index.blade.php список назначений Co-authored-by: Qwen-Coder <qwen-coder@alibabacloud.com>
This commit is contained in:
@@ -57,10 +57,10 @@ class CourseAssignmentController extends Controller
|
||||
|
||||
$validated = $request->validate([
|
||||
'course_id' => 'required|exists:courses,id',
|
||||
'type' => 'required|in:individual,group,organization',
|
||||
'user_id' => 'nullable|exists:users,id',
|
||||
'group_id' => 'nullable|exists:groups,id',
|
||||
'organization_id' => 'nullable|exists:organizations,id',
|
||||
'type' => 'nullable|in:individual,group,organization',
|
||||
'user_ids' => 'nullable|string',
|
||||
'group_ids' => 'nullable|string',
|
||||
'organization_ids' => 'nullable|string',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'nullable|date|after:start_date',
|
||||
'note' => 'nullable|string',
|
||||
@@ -70,10 +70,76 @@ class CourseAssignmentController extends Controller
|
||||
$validated['created_by'] = auth()->id();
|
||||
$validated['is_active'] = $request->boolean('is_active');
|
||||
|
||||
CourseAssignment::create($validated);
|
||||
// Определяем тип назначения по выбранным элементам
|
||||
if (empty($validated['type'])) {
|
||||
if (!empty($validated['user_ids'])) {
|
||||
$validated['type'] = 'individual';
|
||||
} elseif (!empty($validated['group_ids'])) {
|
||||
$validated['type'] = 'group';
|
||||
} elseif (!empty($validated['organization_ids'])) {
|
||||
$validated['type'] = 'organization';
|
||||
}
|
||||
}
|
||||
|
||||
// Создаём назначения для каждого выбранного элемента
|
||||
$created = 0;
|
||||
|
||||
// Назначения пользователям
|
||||
if (!empty($validated['user_ids'])) {
|
||||
$userIds = array_map('intval', array_filter(explode(',', $validated['user_ids'])));
|
||||
foreach ($userIds as $userId) {
|
||||
CourseAssignment::create([
|
||||
'course_id' => $validated['course_id'],
|
||||
'user_id' => $userId,
|
||||
'type' => 'individual',
|
||||
'start_date' => $validated['start_date'],
|
||||
'end_date' => $validated['end_date'] ?? null,
|
||||
'note' => $validated['note'] ?? null,
|
||||
'created_by' => $validated['created_by'],
|
||||
'is_active' => $validated['is_active'],
|
||||
]);
|
||||
$created++;
|
||||
}
|
||||
}
|
||||
|
||||
// Назначения группам
|
||||
if (!empty($validated['group_ids'])) {
|
||||
$groupIds = array_map('intval', array_filter(explode(',', $validated['group_ids'])));
|
||||
foreach ($groupIds as $groupId) {
|
||||
CourseAssignment::create([
|
||||
'course_id' => $validated['course_id'],
|
||||
'group_id' => $groupId,
|
||||
'type' => 'group',
|
||||
'start_date' => $validated['start_date'],
|
||||
'end_date' => $validated['end_date'] ?? null,
|
||||
'note' => $validated['note'] ?? null,
|
||||
'created_by' => $validated['created_by'],
|
||||
'is_active' => $validated['is_active'],
|
||||
]);
|
||||
$created++;
|
||||
}
|
||||
}
|
||||
|
||||
// Назначения организациям
|
||||
if (!empty($validated['organization_ids'])) {
|
||||
$organizationIds = array_map('intval', array_filter(explode(',', $validated['organization_ids'])));
|
||||
foreach ($organizationIds as $organizationId) {
|
||||
CourseAssignment::create([
|
||||
'course_id' => $validated['course_id'],
|
||||
'organization_id' => $organizationId,
|
||||
'type' => 'organization',
|
||||
'start_date' => $validated['start_date'],
|
||||
'end_date' => $validated['end_date'] ?? null,
|
||||
'note' => $validated['note'] ?? null,
|
||||
'created_by' => $validated['created_by'],
|
||||
'is_active' => $validated['is_active'],
|
||||
]);
|
||||
$created++;
|
||||
}
|
||||
}
|
||||
|
||||
return redirect()->route('admin.course-assignments.index')
|
||||
->with('success', 'Назначение успешно создано.');
|
||||
->with('success', "Создано назначений: {$created}");
|
||||
}
|
||||
|
||||
public function show(CourseAssignment $assignment)
|
||||
@@ -90,11 +156,8 @@ class CourseAssignmentController extends Controller
|
||||
Gate::authorize('update', $assignment);
|
||||
|
||||
$courses = Course::pluck('title', 'id');
|
||||
$users = User::pluck('name', 'id');
|
||||
$groups = Group::pluck('name', 'id');
|
||||
$organizations = Organization::pluck('name', 'id');
|
||||
|
||||
return view('admin.course-assignments.edit', compact('assignment', 'courses', 'users', 'groups', 'organizations'));
|
||||
return view('admin.course-assignments.edit', compact('assignment', 'courses'));
|
||||
}
|
||||
|
||||
public function update(Request $request, CourseAssignment $assignment)
|
||||
@@ -103,10 +166,6 @@ class CourseAssignmentController extends Controller
|
||||
|
||||
$validated = $request->validate([
|
||||
'course_id' => 'required|exists:courses,id',
|
||||
'type' => 'required|in:individual,group,organization',
|
||||
'user_id' => 'nullable|exists:users,id',
|
||||
'group_id' => 'nullable|exists:groups,id',
|
||||
'organization_id' => 'nullable|exists:organizations,id',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'nullable|date|after:start_date',
|
||||
'note' => 'nullable|string',
|
||||
|
||||
Reference in New Issue
Block a user