mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
dataFixtures made but not tested
This commit is contained in:
parent
158effe232
commit
f41e27d75a
@ -0,0 +1,91 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
<?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();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user