mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-14 06:14:23 +00:00
fix data provider
This commit is contained in:
parent
6fa0d229af
commit
6fe78b7177
@ -1,91 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Chill\ActivityBundle\DataFixtures\ORM;
|
|
||||||
|
|
||||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
|
||||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
|
||||||
use Doctrine\Persistence\ObjectManager;
|
|
||||||
use Faker\Factory as FakerFactory;
|
|
||||||
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
|
||||||
use Chill\AsideActivityBundle\DataFixtures\LoadAsideActivityCategory;
|
|
||||||
use Chill\AsideActivityBundle\Entity\AsideActivity;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Load reports into DB
|
|
||||||
*
|
|
||||||
* @author Champs-Libres Coop
|
|
||||||
*/
|
|
||||||
class LoadActivity extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
|
|
||||||
{
|
|
||||||
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Faker\Generator
|
|
||||||
*/
|
|
||||||
private $faker;
|
|
||||||
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
$this->faker = FakerFactory::create('fr_FR');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getOrder()
|
|
||||||
{
|
|
||||||
return 16400;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a random asideActivityCategory
|
|
||||||
*
|
|
||||||
* @return \Chill\AsideActivityBundle\Entity\AsideActivityCategory
|
|
||||||
*/
|
|
||||||
private function getRandomAsideActivityCategory()
|
|
||||||
{
|
|
||||||
$catRef = LoadAsideActivityCategory::$references[array_rand(LoadAsideActivityCategory::$references)];
|
|
||||||
return $this->getReference($catRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a random user
|
|
||||||
*
|
|
||||||
* @return \Chill\MainBundle\Entity\User
|
|
||||||
*/
|
|
||||||
private function getRandomUser()
|
|
||||||
{
|
|
||||||
$userRef = array_rand(LoadUsers::$refs);
|
|
||||||
return $this->getReference($userRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function newRandomActivity()
|
|
||||||
{
|
|
||||||
$asideactivity = (new AsideActivity())
|
|
||||||
->setAgent($this->getRandomUser())
|
|
||||||
->setDate($this->faker->dateTimeThisYear())
|
|
||||||
->setDuration($this->faker->dateTime(36000))
|
|
||||||
->setType($this->getRandomAsideActivityCategory());
|
|
||||||
|
|
||||||
return $asideactivity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
|
||||||
{
|
|
||||||
$users = $this->container->get('doctrine.orm.entity_manager')
|
|
||||||
->getRepository('ChillMainBundle:User')
|
|
||||||
->findAll();
|
|
||||||
|
|
||||||
foreach($users as $user) {
|
|
||||||
$activityNbr = rand(0,3);
|
|
||||||
$ref = 'activity_'.$user->getUsernameCanonical();
|
|
||||||
|
|
||||||
for($i = 0; $i < $activityNbr; $i ++) {
|
|
||||||
print "Creating an aside activity for : ".$user." (ref: ".$ref.") \n";
|
|
||||||
$asideactivity = $this->newRandomActivity($user);
|
|
||||||
$manager->persist($asideactivity);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->setReference($ref, $asideactivity);
|
|
||||||
}
|
|
||||||
$manager->flush();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
Namespace Chill\AsideActivityBundle\DataFixtures;
|
|
||||||
|
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
||||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
|
||||||
use Doctrine\Persistence\ObjectManager;
|
|
||||||
use Chill\ActivityBundle\Entity\ActivityTypeCategory;
|
|
||||||
use Chill\AsideActivityBundle\Entity\AsideActivityCategory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Fixtures for AsideActivityCategory
|
|
||||||
*
|
|
||||||
* @author Champs-Libres Coop
|
|
||||||
*/
|
|
||||||
class LoadAsideActivityCategory extends Fixture implements OrderedFixtureInterface
|
|
||||||
{
|
|
||||||
public static $references = array();
|
|
||||||
|
|
||||||
public function getOrder()
|
|
||||||
{
|
|
||||||
return 16050;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
|
||||||
{
|
|
||||||
$categories = [
|
|
||||||
[
|
|
||||||
'title' => ['fr' => 'Formation', 'en' => 'Training'],
|
|
||||||
'ref' => 'training',
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'title' => ['fr' => 'Team building', 'en' => 'Team building'],
|
|
||||||
'ref' => 'teambuilding',
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($categories as $cat) {
|
|
||||||
print "Creating aside activity type category : " . $cat['ref'] . "\n";
|
|
||||||
|
|
||||||
$newCat = (new AsideActivityCategory())
|
|
||||||
->setTitle(($cat['title']));
|
|
||||||
|
|
||||||
$manager->persist($newCat);
|
|
||||||
$reference = 'activity_type_cat_'.$cat['ref'];
|
|
||||||
|
|
||||||
$this->addReference($reference, $newCat);
|
|
||||||
static::$references[] = $reference;
|
|
||||||
}
|
|
||||||
|
|
||||||
$manager->flush();
|
|
||||||
}
|
|
||||||
}
|
|
@ -2,99 +2,50 @@
|
|||||||
|
|
||||||
namespace Chill\AsideActivityBundle\DataFixtures\ORM;
|
namespace Chill\AsideActivityBundle\DataFixtures\ORM;
|
||||||
|
|
||||||
use Doctrine\Common\DataFixtures\AbstractFixture;
|
|
||||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
|
||||||
use Doctrine\Persistence\ObjectManager;
|
|
||||||
use Faker\Factory as FakerFactory;
|
|
||||||
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
|
||||||
use Chill\AsideActivityBundle\DataFixtures\ORM\LoadAsideActivityCategory;
|
|
||||||
use Chill\AsideActivityBundle\Entity\AsideActivity;
|
use Chill\AsideActivityBundle\Entity\AsideActivity;
|
||||||
use Chill\AsideActivityBundle\Entity\AsideActivityCategory;
|
use Chill\MainBundle\DataFixtures\ORM\LoadUsers;
|
||||||
use Chill\MainBundle\Entity\User;
|
|
||||||
use Chill\MainBundle\Repository\UserRepository;
|
use Chill\MainBundle\Repository\UserRepository;
|
||||||
use DateTime;
|
use Doctrine\Bundle\FixturesBundle\Fixture;
|
||||||
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
|
|
||||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
|
|
||||||
/**
|
class LoadAsideActivity extends Fixture implements DependentFixtureInterface
|
||||||
* Load reports into DB
|
|
||||||
*
|
|
||||||
* @author Champs-Libres Coop
|
|
||||||
*/
|
|
||||||
class LoadAsideActivity extends AbstractFixture implements DependentFixtureInterface, ContainerAwareInterface
|
|
||||||
{
|
{
|
||||||
use \Symfony\Component\DependencyInjection\ContainerAwareTrait;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var \Faker\Generator
|
|
||||||
*/
|
|
||||||
private $faker;
|
|
||||||
|
|
||||||
private array $cacheUsers = [];
|
|
||||||
|
|
||||||
private UserRepository $userRepository;
|
private UserRepository $userRepository;
|
||||||
|
|
||||||
public function __construct(UserRepository $userRepository)
|
public function __construct(UserRepository $userRepository)
|
||||||
{
|
{
|
||||||
$this->faker = FakerFactory::create('fr_FR');
|
|
||||||
$this->userRepository = $userRepository;
|
$this->userRepository = $userRepository;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDependencies()
|
public function getDependencies(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
LoadAsideActivityCategory::class,
|
|
||||||
LoadUsers::class,
|
LoadUsers::class,
|
||||||
|
LoadAsideActivityCategory::class
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a random asideActivityCategory
|
|
||||||
*
|
|
||||||
* @return \Chill\AsideActivityBundle\Entity\AsideActivityCategory
|
|
||||||
*/
|
|
||||||
private function getRandomAsideActivityCategory(): AsideActivityCategory
|
|
||||||
{
|
|
||||||
$catRef = LoadAsideActivityCategory::$references[array_rand(LoadAsideActivityCategory::$references)];
|
|
||||||
|
|
||||||
return $this->getReference($catRef);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Return a random user
|
|
||||||
*
|
|
||||||
* @return \Chill\MainBundle\Entity\User
|
|
||||||
*/
|
|
||||||
private function getRandomUser(): User
|
|
||||||
{
|
|
||||||
if (0 === count($this->cacheUsers)){
|
|
||||||
$this->cacheUsers = $this->container->get('doctrine.orm.entity_manager')
|
|
||||||
->getRepository('ChillMainBundle:User')
|
|
||||||
->findAll();
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->cacheUsers[array_rand($this->cacheUsers)];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function newRandomActivity()
|
|
||||||
{
|
|
||||||
$asideactivity = ($activity = new AsideActivity())
|
|
||||||
->setAgent($this->getRandomUser())
|
|
||||||
->setDate($this->faker->dateTimeThisYear())
|
|
||||||
->setCreatedAt(new DateTime())
|
|
||||||
->setCreatedBy($activity->getAgent())
|
|
||||||
//->setDuration(3600)
|
|
||||||
->setType($this->getRandomAsideActivityCategory());
|
|
||||||
|
|
||||||
return $asideactivity;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
{
|
{
|
||||||
for($i = 0; $i < 100; $i ++) {
|
$user = $this->userRepository->findOneBy(['username' => 'center a_social']);
|
||||||
$asideactivity = $this->newRandomActivity();
|
|
||||||
$manager->persist($asideactivity);
|
for ($i = 0; $i < 50; $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();
|
$manager->flush();
|
||||||
|
@ -1,48 +1,22 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
Namespace Chill\AsideActivityBundle\DataFixtures\ORM;
|
namespace Chill\AsideActivityBundle\DataFixtures\ORM;
|
||||||
|
|
||||||
use Doctrine\Bundle\FixturesBundle\Fixture;
|
|
||||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
|
|
||||||
use Doctrine\Persistence\ObjectManager;
|
|
||||||
use Chill\ActivityBundle\Entity\ActivityTypeCategory;
|
|
||||||
use Chill\AsideActivityBundle\Entity\AsideActivityCategory;
|
use Chill\AsideActivityBundle\Entity\AsideActivityCategory;
|
||||||
use Doctrine\Bundle\FixturesBundle\FixtureGroupInterface;
|
use Doctrine\Persistence\ObjectManager;
|
||||||
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
|
|
||||||
|
|
||||||
/**
|
class LoadAsideActivityCategory extends \Doctrine\Bundle\FixturesBundle\Fixture
|
||||||
* Fixtures for AsideActivityCategory
|
|
||||||
*
|
|
||||||
* @author Champs-Libres Coop
|
|
||||||
*/
|
|
||||||
class LoadAsideActivityCategory extends Fixture
|
|
||||||
{
|
{
|
||||||
public static $references = array();
|
|
||||||
|
|
||||||
public function load(ObjectManager $manager)
|
public function load(ObjectManager $manager)
|
||||||
{
|
{
|
||||||
$categories = [
|
foreach ([
|
||||||
[
|
'Appel téléphonique',
|
||||||
'title' => ['fr' => 'Formation', 'en' => 'Training'],
|
'Formation'
|
||||||
'ref' => 'training',
|
] as $key => $label) {
|
||||||
],
|
$category = new AsideActivityCategory();
|
||||||
[
|
$category->setTitle(['fr' => $label]);
|
||||||
'title' => ['fr' => 'Team building', 'en' => 'Team building'],
|
$manager->persist($category);
|
||||||
'ref' => 'teambuilding',
|
$this->setReference('aside_activity_category_'.$key, $category);
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
foreach ($categories as $cat) {
|
|
||||||
print "Creating aside activity type category : " . $cat['ref'] . "\n";
|
|
||||||
|
|
||||||
$newCat = (new AsideActivityCategory())
|
|
||||||
->setTitle(($cat['title']));
|
|
||||||
|
|
||||||
$manager->persist($newCat);
|
|
||||||
$reference = 'activity_type_cat_'.$cat['ref'];
|
|
||||||
|
|
||||||
$this->addReference($reference, $newCat);
|
|
||||||
static::$references[] = $reference;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$manager->flush();
|
$manager->flush();
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
services:
|
||||||
|
Chill\AsideActivityBundle\DataFixtures\:
|
||||||
|
resource: './../DataFixtures'
|
||||||
|
autowire: true
|
||||||
|
autoconfigure: true
|
Loading…
x
Reference in New Issue
Block a user