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
87 lines
2.2 KiB
PHP
87 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Services;
|
|
|
|
use App\Mail\MissingSongRequest;
|
|
use App\Models\ServiceSong;
|
|
use App\Models\Song;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\Config;
|
|
use Illuminate\Support\Facades\Mail;
|
|
|
|
class SongMatchingService
|
|
{
|
|
/**
|
|
* Auto-match a service song to a song in the DB by CCLI ID.
|
|
*
|
|
* Returns true if a match was found and assigned, false otherwise.
|
|
* Skips if already matched or no CCLI ID present.
|
|
*/
|
|
public function autoMatch(ServiceSong $serviceSong): bool
|
|
{
|
|
if ($serviceSong->song_id !== null) {
|
|
return false;
|
|
}
|
|
|
|
if ($serviceSong->cts_ccli_id === null || $serviceSong->cts_ccli_id === '') {
|
|
return false;
|
|
}
|
|
|
|
$song = Song::where('ccli_id', $serviceSong->cts_ccli_id)->first();
|
|
|
|
if ($song === null) {
|
|
return false;
|
|
}
|
|
|
|
$serviceSong->update([
|
|
'song_id' => $song->id,
|
|
'matched_at' => Carbon::now(),
|
|
]);
|
|
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Manually assign a song to a service song.
|
|
* Overwrites any existing assignment.
|
|
*/
|
|
public function manualAssign(ServiceSong $serviceSong, Song $song): void
|
|
{
|
|
$serviceSong->update([
|
|
'song_id' => $song->id,
|
|
'matched_at' => Carbon::now(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Send a missing song request email and record the timestamp.
|
|
*/
|
|
public function requestCreation(ServiceSong $serviceSong): void
|
|
{
|
|
$service = $serviceSong->service;
|
|
|
|
$recipientEmail = (string) Config::get('services.song_request.email', 'songs@example.com');
|
|
|
|
Mail::to($recipientEmail)->send(new MissingSongRequest(
|
|
songName: $serviceSong->cts_song_name,
|
|
ccliId: $serviceSong->cts_ccli_id,
|
|
service: $service,
|
|
));
|
|
|
|
$serviceSong->update([
|
|
'request_sent_at' => Carbon::now(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Remove song assignment from a service song.
|
|
*/
|
|
public function unassign(ServiceSong $serviceSong): void
|
|
{
|
|
$serviceSong->update([
|
|
'song_id' => null,
|
|
'matched_at' => null,
|
|
]);
|
|
}
|
|
}
|