Files
oficial/app/tests/extension/Seeds/Promotions.php
Juan Pablo Vial a18465cacf Seeds
2025-09-09 16:23:48 -03:00

56 lines
1.6 KiB
PHP

<?php
namespace Tests\Extension\Seeds;
use DateInterval;
use Tests\Extension\AbstractSeed;
class Promotions extends AbstractSeed
{
public function getDependencies(): array
{
return [
Proyectos::class,
];
}
public function run(): void
{
$projects = $this->loadValues('proyecto', columns: 'id');
$data = [];
$count = $this->faker->numberBetween(1, 10);
for ($i = 0; $i < $count; $i++) {
$start = $this->faker->dateTimeBetween('-1 year');
$end = $this->faker->dateTimeBetween($start, $start->add(new DateInterval('P1Y')));
$data[] = [
'description' => $this->faker->sentence,
'type' => 1,
'amount' => $this->faker->randomFloat(2, 0, 1),
'start_date' => $start,
'end_date' => $end,
'valid_until' => $this->faker->dateTimeBetween($end, $end->add(new DateInterval('P1M'))),
'state' => 1,
];
}
$this->table('promotions')->insertValues($data)->save();
$promotions = $this->loadValues('promotions', columns: 'id');
$data = [];
foreach ($projects as $project) {
$hasPromo = $this->faker->boolean(10);
if (!$hasPromo) {
continue;
}
$data []= [
'promotion_id' => $this->faker->randomElement($promotions),
'project_id' => $project,
];
}
if (count($data) > 0) {
$this->table('promotion_projects')->insertValues($data)->save();
}
}
}