mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-12-30 22:15:44 +00:00
66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Chill is a software for social workers
|
|
*
|
|
* For the full copyright and license information, please view
|
|
* the LICENSE file that was distributed with this source code.
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Chill\AsideActivityBundle\DataFixtures\ORM;
|
|
|
|
use Chill\AsideActivityBundle\Entity\AsideActivity;
|
|
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
|
use Chill\MainBundle\Repository\UserRepository;
|
|
use DateInterval;
|
|
use DateTimeImmutable;
|
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
|
use Doctrine\Persistence\ObjectManager;
|
|
|
|
use function random_int;
|
|
|
|
class LoadAsideActivity extends Fixture implements DependentFixtureInterface
|
|
{
|
|
private UserRepository $userRepository;
|
|
|
|
public function __construct(UserRepository $userRepository)
|
|
{
|
|
$this->userRepository = $userRepository;
|
|
}
|
|
|
|
public function getDependencies(): array
|
|
{
|
|
return [
|
|
LoadUsers::class,
|
|
LoadAsideActivityCategory::class,
|
|
];
|
|
}
|
|
|
|
public function load(ObjectManager $manager)
|
|
{
|
|
$user = $this->userRepository->findOneBy(['username' => 'center a_social']);
|
|
|
|
for ($i = 0; 50 > $i; ++$i) {
|
|
$activity = new AsideActivity();
|
|
$activity
|
|
->setAgent($user)
|
|
->setCreatedAt(new DateTimeImmutable('now'))
|
|
->setCreatedBy($user)
|
|
->setUpdatedAt(new DateTimeImmutable('now'))
|
|
->setUpdatedBy($user)
|
|
->setType(
|
|
$this->getReference('aside_activity_category_0')
|
|
)
|
|
->setDate((new DateTimeImmutable('today'))
|
|
->sub(new DateInterval('P' . random_int(1, 100) . 'D')));
|
|
|
|
$manager->persist($activity);
|
|
}
|
|
|
|
$manager->flush();
|
|
}
|
|
}
|