schedule explicit set levels

This commit is contained in:
Yisroel Baum 2026-08-11 22:57:15 +03:00
parent a64df64b76
commit 3cf1aff6a9
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9
10 changed files with 156 additions and 38 deletions

View file

@ -0,0 +1,45 @@
<?php
namespace Database\Seeders;
use App\Set\CreateSetLevelDto;
use App\Set\SetLevelRepository;
use App\Set\SetRepository;
use Illuminate\Database\Seeder;
class SetLevelSeeder extends Seeder
{
private const array KINDS_BY_SET = [
'Bible' => ['book', 'portion', 'chapter'],
'Course' => ['module', 'lesson'],
'Fitness Program' => ['phase', 'workout', 'exercise'],
];
public function run(): void
{
$repository = app(SetLevelRepository::class);
foreach (app(SetRepository::class)->all() as $set) {
$kinds = self::KINDS_BY_SET[$set->getName()] ?? null;
if ($kinds === null) {
continue;
}
$existingKinds = array_map(function ($level): string {
return $level->getKind();
}, $repository->findBySet($set));
foreach ($kinds as $kind) {
if (in_array($kind, $existingKinds, true)) {
continue;
}
$repository->create(new CreateSetLevelDto(
set: $set,
kind: $kind,
));
$existingKinds[] = $kind;
}
}
}
}