45 lines
1.2 KiB
PHP
45 lines
1.2 KiB
PHP
<?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;
|
|
}
|
|
}
|
|
}
|
|
}
|