diff --git a/app/Story/DefaultTalksStory.php b/app/Story/DefaultTalksStory.php index 70976028..ca6fde6a 100644 --- a/app/Story/DefaultTalksStory.php +++ b/app/Story/DefaultTalksStory.php @@ -14,6 +14,7 @@ namespace App\Story; use App\Factory\TalkFactory; +use function Zenstruck\Foundry\faker; use Zenstruck\Foundry\Story; final class DefaultTalksStory extends Story @@ -23,6 +24,35 @@ public function build(): void TalkFactory::new()->withStartingDate(new \DateTimeImmutable('first day of january this year'))->many(3)->create(); TalkFactory::new()->withStartingDate(new \DateTimeImmutable('today'))->many(2)->create(); - TalkFactory::createMany(100); + $this->createTalksSpreadOverLastAndCurrentYears(); + } + + /** + * Creates a random number of talks for each month of the previous and the current years, + * so the dashboard statistics chart is filled whatever the selected period. + */ + private function createTalksSpreadOverLastAndCurrentYears(): void + { + $months = new \DatePeriod( + new \DateTimeImmutable('first day of january last year'), + new \DateInterval('P1M'), + new \DateTimeImmutable('first day of january next year'), + ); + + foreach ($months as $firstDayOfMonth) { + $lastDayOfMonth = $firstDayOfMonth->modify('last day of this month 23:59:59'); + + for ($i = 0, $count = faker()->numberBetween(10, 40); $i < $count; ++$i) { + $startsAt = \DateTimeImmutable::createFromMutable( + faker()->dateTimeBetween($firstDayOfMonth->format('Y-m-d H:i:s'), $lastDayOfMonth->format('Y-m-d H:i:s')), + ); + + TalkFactory::new() + ->withStartingDate($startsAt) + ->withEndingDate($startsAt->modify('+45 minutes')) + ->create() + ; + } + } } }