From 846bd12f9030e68f02aca5a467e282aa6593e163 Mon Sep 17 00:00:00 2001 From: Thorsten Bus Date: Sun, 3 May 2026 22:27:21 +0200 Subject: [PATCH] feat(models): add Label/Macro/MacroAssignment/ServiceMacro models and remove SongGroup --- app/Models/Label.php | 42 +++++++++++++++ app/Models/Macro.php | 51 +++++++++++++++++++ app/Models/MacroAssignment.php | 27 ++++++++++ app/Models/MacroCollection.php | 29 +++++++++++ app/Models/ServiceMacroAssignment.php | 33 ++++++++++++ app/Models/ServiceMacroOverride.php | 26 ++++++++++ app/Models/Song.php | 5 -- app/Models/SongArrangement.php | 4 +- ...mentGroup.php => SongArrangementLabel.php} | 8 +-- app/Models/SongGroup.php | 35 ------------- app/Models/SongSlide.php | 6 +-- database/factories/LabelFactory.php | 21 ++++++++ database/factories/MacroFactory.php | 27 ++++++++++ .../factories/SongArrangementGroupFactory.php | 22 -------- .../factories/SongArrangementLabelFactory.php | 22 ++++++++ database/factories/SongGroupFactory.php | 22 -------- database/factories/SongSlideFactory.php | 4 +- 17 files changed, 289 insertions(+), 95 deletions(-) create mode 100644 app/Models/Label.php create mode 100644 app/Models/Macro.php create mode 100644 app/Models/MacroAssignment.php create mode 100644 app/Models/MacroCollection.php create mode 100644 app/Models/ServiceMacroAssignment.php create mode 100644 app/Models/ServiceMacroOverride.php rename app/Models/{SongArrangementGroup.php => SongArrangementLabel.php} (71%) delete mode 100644 app/Models/SongGroup.php create mode 100644 database/factories/LabelFactory.php create mode 100644 database/factories/MacroFactory.php delete mode 100644 database/factories/SongArrangementGroupFactory.php create mode 100644 database/factories/SongArrangementLabelFactory.php delete mode 100644 database/factories/SongGroupFactory.php diff --git a/app/Models/Label.php b/app/Models/Label.php new file mode 100644 index 0000000..e28ae87 --- /dev/null +++ b/app/Models/Label.php @@ -0,0 +1,42 @@ + 'datetime', + 'last_imported_at' => 'datetime', + ]; + } + + public function songSlides(): HasMany + { + return $this->hasMany(SongSlide::class); + } + + public function macroAssignments(): HasMany + { + return $this->hasMany(MacroAssignment::class); + } + + public function isHidden(): bool + { + return $this->hidden_at !== null; + } +} diff --git a/app/Models/Macro.php b/app/Models/Macro.php new file mode 100644 index 0000000..e2cb7b0 --- /dev/null +++ b/app/Models/Macro.php @@ -0,0 +1,51 @@ + 'boolean', + 'hidden_at' => 'datetime', + 'last_imported_at' => 'datetime', + ]; + } + + public function collections(): BelongsToMany + { + return $this->belongsToMany(MacroCollection::class, 'macro_collection_macros') + ->withPivot('order') + ->orderBy('macro_collection_macros.order'); + } + + public function assignments(): HasMany + { + return $this->hasMany(MacroAssignment::class); + } + + public function isHidden(): bool + { + return $this->hidden_at !== null; + } +} diff --git a/app/Models/MacroAssignment.php b/app/Models/MacroAssignment.php new file mode 100644 index 0000000..a0cac4c --- /dev/null +++ b/app/Models/MacroAssignment.php @@ -0,0 +1,27 @@ +belongsTo(Macro::class); + } + + public function label(): BelongsTo + { + return $this->belongsTo(Label::class); + } +} diff --git a/app/Models/MacroCollection.php b/app/Models/MacroCollection.php new file mode 100644 index 0000000..9fbd8fe --- /dev/null +++ b/app/Models/MacroCollection.php @@ -0,0 +1,29 @@ + 'datetime', + ]; + } + + public function macros(): BelongsToMany + { + return $this->belongsToMany(Macro::class, 'macro_collection_macros') + ->withPivot('order') + ->orderBy('macro_collection_macros.order'); + } +} diff --git a/app/Models/ServiceMacroAssignment.php b/app/Models/ServiceMacroAssignment.php new file mode 100644 index 0000000..8006a85 --- /dev/null +++ b/app/Models/ServiceMacroAssignment.php @@ -0,0 +1,33 @@ +belongsTo(Service::class); + } + + public function macro(): BelongsTo + { + return $this->belongsTo(Macro::class); + } + + public function label(): BelongsTo + { + return $this->belongsTo(Label::class); + } +} diff --git a/app/Models/ServiceMacroOverride.php b/app/Models/ServiceMacroOverride.php new file mode 100644 index 0000000..7bca5ba --- /dev/null +++ b/app/Models/ServiceMacroOverride.php @@ -0,0 +1,26 @@ +belongsTo(Service::class); + } + + public function assignments(): HasMany + { + return $this->hasMany(ServiceMacroAssignment::class, 'service_id', 'service_id') + ->where('part_type', $this->part_type); + } +} diff --git a/app/Models/Song.php b/app/Models/Song.php index 0ef5573..571e5f1 100644 --- a/app/Models/Song.php +++ b/app/Models/Song.php @@ -33,11 +33,6 @@ protected function casts(): array ]; } - public function groups(): HasMany - { - return $this->hasMany(SongGroup::class); - } - public function arrangements(): HasMany { return $this->hasMany(SongArrangement::class); diff --git a/app/Models/SongArrangement.php b/app/Models/SongArrangement.php index 39281ca..6dd55b6 100644 --- a/app/Models/SongArrangement.php +++ b/app/Models/SongArrangement.php @@ -29,9 +29,9 @@ public function song(): BelongsTo return $this->belongsTo(Song::class); } - public function arrangementGroups(): HasMany + public function arrangementLabels(): HasMany { - return $this->hasMany(SongArrangementGroup::class); + return $this->hasMany(SongArrangementLabel::class)->orderBy('order'); } public function serviceSongs(): HasMany diff --git a/app/Models/SongArrangementGroup.php b/app/Models/SongArrangementLabel.php similarity index 71% rename from app/Models/SongArrangementGroup.php rename to app/Models/SongArrangementLabel.php index 9f9490f..d3b9f7f 100644 --- a/app/Models/SongArrangementGroup.php +++ b/app/Models/SongArrangementLabel.php @@ -6,13 +6,13 @@ use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; -class SongArrangementGroup extends Model +class SongArrangementLabel extends Model { use HasFactory; protected $fillable = [ 'song_arrangement_id', - 'song_group_id', + 'label_id', 'order', ]; @@ -21,8 +21,8 @@ public function arrangement(): BelongsTo return $this->belongsTo(SongArrangement::class, 'song_arrangement_id'); } - public function group(): BelongsTo + public function label(): BelongsTo { - return $this->belongsTo(SongGroup::class, 'song_group_id'); + return $this->belongsTo(Label::class); } } diff --git a/app/Models/SongGroup.php b/app/Models/SongGroup.php deleted file mode 100644 index fa093c0..0000000 --- a/app/Models/SongGroup.php +++ /dev/null @@ -1,35 +0,0 @@ -belongsTo(Song::class); - } - - public function slides(): HasMany - { - return $this->hasMany(SongSlide::class); - } - - public function arrangementGroups(): HasMany - { - return $this->hasMany(SongArrangementGroup::class); - } -} diff --git a/app/Models/SongSlide.php b/app/Models/SongSlide.php index 2d3b839..05dd849 100644 --- a/app/Models/SongSlide.php +++ b/app/Models/SongSlide.php @@ -11,15 +11,15 @@ class SongSlide extends Model use HasFactory; protected $fillable = [ - 'song_group_id', + 'label_id', 'order', 'text_content', 'text_content_translated', 'notes', ]; - public function group(): BelongsTo + public function label(): BelongsTo { - return $this->belongsTo(SongGroup::class, 'song_group_id'); + return $this->belongsTo(Label::class); } } diff --git a/database/factories/LabelFactory.php b/database/factories/LabelFactory.php new file mode 100644 index 0000000..6dc013d --- /dev/null +++ b/database/factories/LabelFactory.php @@ -0,0 +1,21 @@ + $this->faker->unique()->words(2, true), + 'color' => sprintf('#%06X', mt_rand(0, 0xFFFFFF)), + 'hidden_at' => null, + 'last_imported_at' => null, + ]; + } +} diff --git a/database/factories/MacroFactory.php b/database/factories/MacroFactory.php new file mode 100644 index 0000000..becc39f --- /dev/null +++ b/database/factories/MacroFactory.php @@ -0,0 +1,27 @@ + strtoupper(Str::uuid()->toString()), + 'name' => $this->faker->words(3, true), + 'color' => sprintf('#%06X', mt_rand(0, 0xFFFFFF)), + 'trigger_on_startup' => false, + 'image_type' => 0, + 'action_count' => 0, + 'hidden_at' => null, + 'last_imported_at' => null, + 'last_imported_filename' => null, + ]; + } +} diff --git a/database/factories/SongArrangementGroupFactory.php b/database/factories/SongArrangementGroupFactory.php deleted file mode 100644 index a02f13c..0000000 --- a/database/factories/SongArrangementGroupFactory.php +++ /dev/null @@ -1,22 +0,0 @@ - SongArrangement::factory(), - 'song_group_id' => SongGroup::factory(), - 'order' => $this->faker->numberBetween(1, 12), - ]; - } -} diff --git a/database/factories/SongArrangementLabelFactory.php b/database/factories/SongArrangementLabelFactory.php new file mode 100644 index 0000000..b4a649c --- /dev/null +++ b/database/factories/SongArrangementLabelFactory.php @@ -0,0 +1,22 @@ + SongArrangement::factory(), + 'label_id' => Label::factory(), + 'order' => $this->faker->numberBetween(0, 10), + ]; + } +} diff --git a/database/factories/SongGroupFactory.php b/database/factories/SongGroupFactory.php deleted file mode 100644 index cba2662..0000000 --- a/database/factories/SongGroupFactory.php +++ /dev/null @@ -1,22 +0,0 @@ - Song::factory(), - 'name' => $this->faker->randomElement(['Verse 1', 'Verse 2', 'Chorus', 'Bridge']), - 'color' => $this->faker->hexColor(), - 'order' => $this->faker->numberBetween(1, 10), - ]; - } -} diff --git a/database/factories/SongSlideFactory.php b/database/factories/SongSlideFactory.php index e42e04a..4b042ad 100644 --- a/database/factories/SongSlideFactory.php +++ b/database/factories/SongSlideFactory.php @@ -2,7 +2,7 @@ namespace Database\Factories; -use App\Models\SongGroup; +use App\Models\Label; use App\Models\SongSlide; use Illuminate\Database\Eloquent\Factories\Factory; @@ -13,7 +13,7 @@ class SongSlideFactory extends Factory public function definition(): array { return [ - 'song_group_id' => SongGroup::factory(), + 'label_id' => Label::factory(), 'order' => $this->faker->numberBetween(1, 12), 'text_content' => implode("\n", $this->faker->sentences(3)), 'text_content_translated' => $this->faker->optional()->sentence(),