mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
rdv: add fixture for calendar range
This commit is contained in:
parent
afad23eb0f
commit
323434f34e
@ -0,0 +1,58 @@
|
||||
<?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();
|
||||
|
||||
foreach ($arr as $a) {
|
||||
$startEvent = new DateTimeImmutable('+'.$a.' days');
|
||||
$endEvent = new DateTimeImmutable('+'.$a.' days + 2 hours');
|
||||
$calendarRange= (new CalendarRange())
|
||||
->setUser($users[array_rand($users, 1)])
|
||||
->setStartDate($startEvent)
|
||||
->setEndDate($endEvent);
|
||||
|
||||
$manager->persist($calendarRange);
|
||||
}
|
||||
|
||||
$manager->flush();
|
||||
}
|
||||
}
|
@ -1,8 +1,13 @@
|
||||
---
|
||||
services:
|
||||
Chill\CalendarBundle\DataFixtures\ORM\LoadCancelReason:
|
||||
tags:
|
||||
- { 'name': doctrine.fixture.orm }
|
||||
tags:
|
||||
- { 'name': doctrine.fixture.orm }
|
||||
Chill\CalendarBundle\DataFixtures\ORM\LoadInvite:
|
||||
tags:
|
||||
- { 'name': doctrine.fixture.orm }
|
||||
Chill\CalendarBundle\DataFixtures\ORM\LoadCalendarRange:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
tags:
|
||||
- { 'name': doctrine.fixture.orm }
|
Loading…
x
Reference in New Issue
Block a user