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
78 lines
2.3 KiB
PHP
78 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Models\Song;
|
|
use App\Models\SongArrangement;
|
|
use App\Models\SongArrangementGroup;
|
|
use App\Models\SongGroup;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class SongService
|
|
{
|
|
/**
|
|
* Default-Gruppen für ein neues Lied erstellen.
|
|
*
|
|
* @return \Illuminate\Database\Eloquent\Collection<int, SongGroup>
|
|
*/
|
|
public function createDefaultGroups(Song $song): \Illuminate\Database\Eloquent\Collection
|
|
{
|
|
$defaults = [
|
|
['name' => 'Strophe 1', 'color' => '#3B82F6', 'order' => 1],
|
|
['name' => 'Refrain', 'color' => '#10B981', 'order' => 2],
|
|
['name' => 'Bridge', 'color' => '#F59E0B', 'order' => 3],
|
|
];
|
|
|
|
foreach ($defaults as $groupData) {
|
|
$song->groups()->create($groupData);
|
|
}
|
|
|
|
return $song->groups()->orderBy('order')->get();
|
|
}
|
|
|
|
/**
|
|
* Standard "Normal"-Arrangement mit allen Gruppen erstellen.
|
|
*/
|
|
public function createDefaultArrangement(Song $song): SongArrangement
|
|
{
|
|
$arrangement = $song->arrangements()->create([
|
|
'name' => 'Normal',
|
|
'is_default' => true,
|
|
]);
|
|
|
|
$groups = $song->groups()->orderBy('order')->get();
|
|
|
|
foreach ($groups as $index => $group) {
|
|
$arrangement->arrangementGroups()->create([
|
|
'song_group_id' => $group->id,
|
|
'order' => $index + 1,
|
|
]);
|
|
}
|
|
|
|
return $arrangement->load('arrangementGroups');
|
|
}
|
|
|
|
/**
|
|
* Arrangement duplizieren mit neuem Namen.
|
|
*/
|
|
public function duplicateArrangement(SongArrangement $arrangement, string $name): SongArrangement
|
|
{
|
|
return DB::transaction(function () use ($arrangement, $name) {
|
|
$clone = $arrangement->replicate(['id', 'created_at', 'updated_at']);
|
|
$clone->name = $name;
|
|
$clone->is_default = false;
|
|
$clone->save();
|
|
|
|
foreach ($arrangement->arrangementGroups()->orderBy('order')->get() as $group) {
|
|
SongArrangementGroup::create([
|
|
'song_arrangement_id' => $clone->id,
|
|
'song_group_id' => $group->song_group_id,
|
|
'order' => $group->order,
|
|
]);
|
|
}
|
|
|
|
return $clone->load('arrangementGroups');
|
|
});
|
|
}
|
|
}
|