only(['search', 'educational_group_id', 'education_form_id']); $data = $this->listSchedulesAction->run($filters); return Inertia::render('Dashboard/Schedules/Index', $data); } /** * Показывает форму создания расписания */ public function create(): \Inertia\Response { $data = $this->listSchedulesAction->run([]); return Inertia::render('Dashboard/Schedules/Create', [ 'educationalGroups' => $data['educationalGroups'], 'educationForms' => $data['educationForms'], ]); } /** * Создает новое расписание */ public function store(StoreScheduleRequest $request): RedirectResponse { try { $validated = $request->validated(); // Обработка файла if (!empty($validated['file'][0]['path'])) { $file = $validated['file'][0]['path']; $filename = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME) . '-' . Carbon::now()->timestamp) . '.' . $file->getClientOriginalExtension(); $path = $file->storeAs('schedules', $filename, 'public'); $validated['file'] = [ [ 'title' => $validated['file'][0]['title'], 'path' => $path, ], ]; } $this->createScheduleAction->run($validated); return redirect()->route('dashboard.schedules.index') ->with('success', 'Расписание успешно создано!'); } catch (\Exception $e) { return back() ->withInput() ->with('error', 'Ошибка при создании расписания: ' . $e->getMessage()); } } /** * Показывает форму редактирования расписания */ public function edit(Schedule $schedule): \Inertia\Response { $schedule->load(['educationalGroup.faculty']); $data = $this->listSchedulesAction->run([]); return Inertia::render('Dashboard/Schedules/Edit', [ 'schedule' => $schedule, 'educationalGroups' => $data['educationalGroups'], 'educationForms' => $data['educationForms'], ]); } /** * Обновляет существующее расписание */ public function update(UpdateScheduleRequest $request, Schedule $schedule): RedirectResponse { try { $validated = $request->validated(); // Обработка нового файла если загружен if (!empty($validated['file'][0]['path'])) { $file = $validated['file'][0]['path']; $filename = Str::slug(pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME) . '-' . Carbon::now()->timestamp) . '.' . $file->getClientOriginalExtension(); $path = $file->storeAs('schedules', $filename, 'public'); $validated['file'] = [ [ 'title' => $validated['file'][0]['title'], 'path' => $path, ], ]; } else { // Оставляем старый файл unset($validated['file']); } $this->updateScheduleAction->run($schedule, $validated); return redirect()->route('dashboard.schedules.index') ->with('success', 'Расписание успешно обновлено!'); } catch (\Exception $e) { return back() ->withInput() ->with('error', 'Ошибка при обновлении расписания: ' . $e->getMessage()); } } /** * Удаляет расписание */ public function destroy(Schedule $schedule): RedirectResponse { try { $this->deleteScheduleAction->run($schedule); return redirect()->route('dashboard.schedules.index') ->with('success', 'Расписание успешно удалено!'); } catch (\Exception $e) { return back() ->with('error', 'Ошибка при удалении расписания: ' . $e->getMessage()); } } /** * Массовое удаление расписаний */ public function bulkDestroy(Request $request): RedirectResponse { $request->validate(['ids' => 'required|array', 'ids.*' => 'integer|exists:schedules,id']); try { $count = $this->bulkDeleteSchedulesAction->run($request->ids); return redirect()->back() ->with('success', "Удалено {$count} расписаний"); } catch (\Exception $e) { return back() ->with('error', 'Ошибка при удалении: ' . $e->getMessage()); } } /** * Все ID расписаний с учётом фильтров (для массового выделения) */ public function allIds(Request $request): \Illuminate\Http\JsonResponse { $filters = $request->only(['search', 'educational_group_id', 'education_form_id']); $ids = $this->getAllScheduleIdsAction->run($filters); return response()->json(['ids' => $ids, 'total' => count($ids)]); } }