2021-08-19 16:07:44 +02:00

82 lines
2.1 KiB
PHP

<?php
namespace Chill\CalendarBundle\DataFixtures\ORM;
use Chill\CalendarBundle\Entity\CalendarRange;
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
use Chill\MainBundle\Entity\User;
use DateTimeImmutable;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\Persistence\ObjectManager;
class LoadCalendarRange extends Fixture implements FixtureGroupInterface, OrderedFixtureInterface
{
public function __construct(
EntityManagerInterface $em
) {
$this->userRepository = $em->getRepository(User::class);
}
public function getOrder(): int
{
return 40003;
}
public static function getGroups(): array
{
return ['calendar'];
}
public static $references = [];
public function load(ObjectManager $manager): void
{
$arr = range(-50, 50);
print "Creating calendar range ('plage de disponibilités')\n";
$users = $this->userRepository->findAll();
$days = [
'2021-08-23',
'2021-08-24',
'2021-08-25',
'2021-08-26',
'2021-08-30',
'2021-08-31',
'2021-09-01',
'2021-09-02',
];
$hours = [
'10:00:00',
'11:30:00',
'13:30:00',
'15:00:00'
];
foreach ($users as $u) {
foreach ($days as $d) {
foreach ($hours as $h){
$event = $d.' '.$h;
$startEvent = new DateTimeImmutable($event);
$endEvent = new DateTimeImmutable($event.' + 1 hours');
$calendarRange= (new CalendarRange())
->setUser($u)
->setStartDate($startEvent)
->setEndDate($endEvent);
$manager->persist($calendarRange);
}
}
}
$manager->flush();
}
}