schedule explicit set levels
This commit is contained in:
parent
a64df64b76
commit
3cf1aff6a9
10 changed files with 156 additions and 38 deletions
45
backend/database/seeders/SetLevelSeeder.php
Normal file
45
backend/database/seeders/SetLevelSeeder.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue