T8: Service List Page - ServiceController with index, finalize, reopen actions - Services/Index.vue with status indicators (songs mapped/arranged, slides uploaded) - German UI with finalize/reopen toggle buttons - Status aggregation via SQL subqueries for efficiency - Tests: 3 passing (46 assertions) T9: Song CRUD Backend - SongController with full REST API (index, store, show, update, destroy) - SongService for default groups/arrangements creation - SongRequest validation (title required, ccli_id unique) - Search by title and CCLI ID - last_used_in_service accessor via service_songs join - Tests: 20 passing (85 assertions) T10: Slide Upload Component - SlideController with store, destroy, updateExpireDate - SlideUploader.vue with vue3-dropzone drag-and-drop - SlideGrid.vue with thumbnail grid and inline expire date editing - Multi-format support: images (sync), PPT (async job), ZIP (extract) - Type validation: information (global), moderation/sermon (service-specific) - Tests: 15 passing (37 assertions) T11: Arrangement Configurator - ArrangementController with store, clone, update, destroy - ArrangementConfigurator.vue with vue-draggable-plus - Drag-and-drop arrangement editor with colored group pills - Clone from default or existing arrangement - Color picker for group customization - Prevent deletion of last arrangement - Tests: 4 passing (17 assertions) T12: Song Matching Service - SongMatchingService with autoMatch, manualAssign, requestCreation, unassign - ServiceSongController API endpoints for song assignment - Auto-match by CCLI ID during CTS sync - Manual assignment with searchable song select - Email request for missing songs (MissingSongRequest mailable) - Tests: 14 passing (33 assertions) T13: Translation Service - TranslationService with fetchFromUrl, importTranslation, removeTranslation - TranslationController API endpoints - URL scraping (best-effort HTTP fetch with strip_tags) - Line-count distribution algorithm (match original slide line counts) - Mark song as translated, remove translation - Tests: 18 passing (18 assertions) All tests passing: 103/103 (488 assertions) Build: ✓ Vite production build successful German UI: All user-facing text in German with 'Du' form
165 lines
5.3 KiB
PHP
165 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Song;
|
|
use App\Models\SongArrangement;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Validation\ValidationException;
|
|
|
|
class ArrangementController extends Controller
|
|
{
|
|
public function store(Request $request, Song $song): RedirectResponse
|
|
{
|
|
$data = $request->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
]);
|
|
|
|
DB::transaction(function () use ($song, $data): void {
|
|
$arrangement = $song->arrangements()->create([
|
|
'name' => $data['name'],
|
|
'is_default' => false,
|
|
]);
|
|
|
|
$source = $song->arrangements()
|
|
->where('is_default', true)
|
|
->with('arrangementGroups')
|
|
->first();
|
|
|
|
if ($source === null) {
|
|
$source = $song->arrangements()
|
|
->with('arrangementGroups')
|
|
->orderBy('id')
|
|
->first();
|
|
}
|
|
|
|
$this->cloneGroups($source, $arrangement);
|
|
});
|
|
|
|
return back()->with('success', 'Arrangement wurde hinzugefügt.');
|
|
}
|
|
|
|
public function clone(Request $request, SongArrangement $arrangement): RedirectResponse
|
|
{
|
|
$data = $request->validate([
|
|
'name' => ['required', 'string', 'max:255'],
|
|
]);
|
|
|
|
DB::transaction(function () use ($arrangement, $data): void {
|
|
$arrangement->loadMissing('arrangementGroups');
|
|
|
|
$clone = $arrangement->song->arrangements()->create([
|
|
'name' => $data['name'],
|
|
'is_default' => false,
|
|
]);
|
|
|
|
$this->cloneGroups($arrangement, $clone);
|
|
});
|
|
|
|
return back()->with('success', 'Arrangement wurde geklont.');
|
|
}
|
|
|
|
public function update(Request $request, SongArrangement $arrangement): RedirectResponse
|
|
{
|
|
$data = $request->validate([
|
|
'groups' => ['array'],
|
|
'groups.*.song_group_id' => ['required', 'integer', 'exists:song_groups,id'],
|
|
'groups.*.order' => ['required', 'integer', 'min:1'],
|
|
'group_colors' => ['sometimes', 'array'],
|
|
'group_colors.*' => ['required', 'string', 'regex:/^#[0-9A-Fa-f]{6}$/'],
|
|
]);
|
|
|
|
$groupIds = collect($data['groups'] ?? [])->pluck('song_group_id')->values();
|
|
$uniqueGroupIds = $groupIds->unique()->values();
|
|
|
|
$validGroupIds = $arrangement->song->groups()
|
|
->whereIn('id', $uniqueGroupIds)
|
|
->pluck('id');
|
|
|
|
if ($uniqueGroupIds->count() !== $validGroupIds->count()) {
|
|
throw ValidationException::withMessages([
|
|
'groups' => 'Du kannst nur Gruppen aus diesem Song verwenden.',
|
|
]);
|
|
}
|
|
|
|
DB::transaction(function () use ($arrangement, $groupIds, $data): void {
|
|
$arrangement->arrangementGroups()->delete();
|
|
|
|
$rows = $groupIds
|
|
->values()
|
|
->map(fn (int $songGroupId, int $index) => [
|
|
'song_arrangement_id' => $arrangement->id,
|
|
'song_group_id' => $songGroupId,
|
|
'order' => $index + 1,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
])
|
|
->all();
|
|
|
|
if ($rows !== []) {
|
|
$arrangement->arrangementGroups()->insert($rows);
|
|
}
|
|
|
|
if (!empty($data['group_colors'])) {
|
|
foreach ($data['group_colors'] as $groupId => $color) {
|
|
$arrangement->song->groups()
|
|
->whereKey((int) $groupId)
|
|
->update(['color' => $color]);
|
|
}
|
|
}
|
|
});
|
|
|
|
return back()->with('success', 'Arrangement wurde gespeichert.');
|
|
}
|
|
|
|
public function destroy(SongArrangement $arrangement): RedirectResponse
|
|
{
|
|
$song = $arrangement->song;
|
|
|
|
if ($song->arrangements()->count() <= 1) {
|
|
return back()->with('error', 'Das letzte Arrangement kann nicht gelöscht werden.');
|
|
}
|
|
|
|
DB::transaction(function () use ($arrangement, $song): void {
|
|
$deletedWasDefault = $arrangement->is_default;
|
|
$arrangement->delete();
|
|
|
|
if ($deletedWasDefault) {
|
|
$song->arrangements()
|
|
->orderBy('id')
|
|
->limit(1)
|
|
->update(['is_default' => true]);
|
|
}
|
|
});
|
|
|
|
return back()->with('success', 'Arrangement wurde gelöscht.');
|
|
}
|
|
|
|
private function cloneGroups(?SongArrangement $source, SongArrangement $target): void
|
|
{
|
|
if ($source === null) {
|
|
return;
|
|
}
|
|
|
|
$groups = $source->arrangementGroups
|
|
->sortBy('order')
|
|
->values();
|
|
|
|
$rows = $groups
|
|
->map(fn ($arrangementGroup) => [
|
|
'song_arrangement_id' => $target->id,
|
|
'song_group_id' => $arrangementGroup->song_group_id,
|
|
'order' => $arrangementGroup->order,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
])
|
|
->all();
|
|
|
|
if ($rows !== []) {
|
|
$target->arrangementGroups()->insert($rows);
|
|
}
|
|
}
|
|
}
|