mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-11-04 03:08:25 +00:00 
			
		
		
		
	
							
								
								
									
										97
									
								
								DataFixtures/ORM/LoadEventTypes.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								DataFixtures/ORM/LoadEventTypes.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,97 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
namespace Chill\EventBundle\DataFixtures\ORM;
 | 
			
		||||
 | 
			
		||||
use Doctrine\Common\DataFixtures\AbstractFixture;
 | 
			
		||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
 | 
			
		||||
use Doctrine\Common\Persistence\ObjectManager;
 | 
			
		||||
use Chill\EventBundle\Entity\EventType;
 | 
			
		||||
use Chill\EventBundle\Entity\Role;
 | 
			
		||||
use Chill\EventBundle\Entity\Status;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Load a set of `EventType`, their `Role` and `Status`.
 | 
			
		||||
 *
 | 
			
		||||
 * @author Julien Fastré <julien.fastre@champs-libres.coop>
 | 
			
		||||
 * @author Champs Libres <info@champs-libres.coop>
 | 
			
		||||
 */
 | 
			
		||||
class LoadEventTypes extends AbstractFixture implements OrderedFixtureInterface
 | 
			
		||||
{
 | 
			
		||||
    public static $refs = array();
 | 
			
		||||
    
 | 
			
		||||
    public function getOrder()
 | 
			
		||||
    {
 | 
			
		||||
        return 30000;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function load(ObjectManager $manager)
 | 
			
		||||
    {
 | 
			
		||||
        $type = (new EventType())
 | 
			
		||||
              ->setActive(true)
 | 
			
		||||
              ->setLabel(array('fr' => 'Échange de savoirs', 'en' => 'Exchange of knowledge'))
 | 
			
		||||
              ;
 | 
			
		||||
        $manager->persist($type);
 | 
			
		||||
        $this->addReference('event_type_knowledge', $type);
 | 
			
		||||
        self::$refs[] = 'event_type_knowledge';
 | 
			
		||||
        
 | 
			
		||||
        $role = (new Role())
 | 
			
		||||
                ->setActive(true)
 | 
			
		||||
                ->setLabel(array('fr' => 'Participant', 'nl' => 'Deelneemer', 'en' => 'Participant'))
 | 
			
		||||
                ->setType($type)
 | 
			
		||||
              ;
 | 
			
		||||
        $manager->persist($role);
 | 
			
		||||
        
 | 
			
		||||
        $role = (new Role())
 | 
			
		||||
              ->setActive(true)
 | 
			
		||||
              ->setLabel(array('fr' => 'Animateur'))
 | 
			
		||||
              ->setType($type);
 | 
			
		||||
        $manager->persist($role);
 | 
			
		||||
        
 | 
			
		||||
        $status = (new Status())
 | 
			
		||||
              ->setActive(true)
 | 
			
		||||
              ->setLabel(array('fr' => 'Inscrit'))
 | 
			
		||||
              ->setType($type);
 | 
			
		||||
        $manager->persist($status);
 | 
			
		||||
        
 | 
			
		||||
        $status = (new Status())
 | 
			
		||||
              ->setActive(true)
 | 
			
		||||
              ->setLabel(array('fr' => 'Présent'))
 | 
			
		||||
              ->setType($type)
 | 
			
		||||
              ;
 | 
			
		||||
        $manager->persist($status);
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
        $type = (new EventType())
 | 
			
		||||
              ->setActive(true)
 | 
			
		||||
              ->setLabel(array('fr' => 'Formation', 'en' => 'Course', 'nl' => 'Opleiding'))
 | 
			
		||||
              ;
 | 
			
		||||
        $manager->persist($type);
 | 
			
		||||
        $this->addReference('event_type_course', $type);
 | 
			
		||||
        self::$refs[] = 'event_type_course';
 | 
			
		||||
        
 | 
			
		||||
        $role = (new Role())
 | 
			
		||||
                ->setActive(true)
 | 
			
		||||
                ->setLabel(array('fr' => 'Participant', 'nl' => 'Deelneemer', 'en' => 'Participant'))
 | 
			
		||||
                ->setType($type)
 | 
			
		||||
              ;
 | 
			
		||||
        $manager->persist($role);
 | 
			
		||||
        
 | 
			
		||||
        $status = (new Status())
 | 
			
		||||
              ->setActive(true)
 | 
			
		||||
              ->setLabel(array('fr' => 'Inscrit'))
 | 
			
		||||
              ->setType($type)
 | 
			
		||||
              ;
 | 
			
		||||
        $manager->persist($status);
 | 
			
		||||
        
 | 
			
		||||
        $status = (new Status())
 | 
			
		||||
              ->setActive(true)
 | 
			
		||||
              ->setLabel(array('fr' => 'En liste d\'attente'))
 | 
			
		||||
              ->setType($type)
 | 
			
		||||
              ;
 | 
			
		||||
        $manager->persist($status);
 | 
			
		||||
        
 | 
			
		||||
        $manager->flush();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										92
									
								
								DataFixtures/ORM/LoadParticipation.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								DataFixtures/ORM/LoadParticipation.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,92 @@
 | 
			
		||||
<?php
 | 
			
		||||
 | 
			
		||||
namespace Chill\EventBundle\DataFixtures\ORM;
 | 
			
		||||
 | 
			
		||||
use Doctrine\Common\DataFixtures\AbstractFixture;
 | 
			
		||||
use Doctrine\Common\Persistence\ObjectManager;
 | 
			
		||||
use Doctrine\Common\DataFixtures\OrderedFixtureInterface;
 | 
			
		||||
use Chill\EventBundle\Entity\Participation;
 | 
			
		||||
use Chill\MainBundle\Entity\Center;
 | 
			
		||||
use Chill\EventBundle\Entity\Event;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Load Events and Participation
 | 
			
		||||
 *
 | 
			
		||||
 * @author Julien Fastré <julien.fastre@champs-libres.coop>
 | 
			
		||||
 * @author Champs Libres <info@champs-libres.coop>
 | 
			
		||||
 */
 | 
			
		||||
class LoadParticipation extends AbstractFixture implements OrderedFixtureInterface
 | 
			
		||||
{
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * @var \Faker\Generator
 | 
			
		||||
     */
 | 
			
		||||
    protected $faker;
 | 
			
		||||
    
 | 
			
		||||
    public function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        $this->faker = \Faker\Factory::create('fr_FR');
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function getOrder()
 | 
			
		||||
    {
 | 
			
		||||
        return 30010;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public function load(ObjectManager $manager)
 | 
			
		||||
    {
 | 
			
		||||
        $centers = $manager->getRepository('ChillMainBundle:Center')
 | 
			
		||||
              ->findAll();
 | 
			
		||||
        
 | 
			
		||||
        foreach($centers as $center) {
 | 
			
		||||
            
 | 
			
		||||
            $people = $manager->getRepository('ChillPersonBundle:Person')
 | 
			
		||||
              ->findBy(array('center' => $center));
 | 
			
		||||
            $events = $this->createEvents($center, $manager);
 | 
			
		||||
 | 
			
		||||
            /* @var $person \Chill\PersonBundle\Entity\Person */
 | 
			
		||||
            foreach ($people as $person) {
 | 
			
		||||
                $nb = rand(0,3);
 | 
			
		||||
                
 | 
			
		||||
                for ($i=0; $i<$nb; $i++) {
 | 
			
		||||
                    $event = $events[array_rand($events)];
 | 
			
		||||
                    $role = $event->getType()->getRoles()->get(
 | 
			
		||||
                          array_rand($event->getType()->getRoles()->toArray()));
 | 
			
		||||
                    $status = $event->getType()->getStatuses()->get(
 | 
			
		||||
                          array_rand($event->getType()->getStatuses()->toArray()));
 | 
			
		||||
 | 
			
		||||
                    $participation = (new Participation())
 | 
			
		||||
                          ->setPerson($person)
 | 
			
		||||
                          ->setRole($role)
 | 
			
		||||
                          ->setStatus($status)
 | 
			
		||||
                          ->setEvent($event)
 | 
			
		||||
                          ;
 | 
			
		||||
                    $manager->persist($participation);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        $manager->flush();
 | 
			
		||||
        
 | 
			
		||||
        
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function createEvents(Center $center, ObjectManager $manager)
 | 
			
		||||
    {
 | 
			
		||||
        $expectedNumber = 20;
 | 
			
		||||
        $events = array();
 | 
			
		||||
        
 | 
			
		||||
        for($i=0; $i<$expectedNumber; $i++) {
 | 
			
		||||
            $event = (new Event())
 | 
			
		||||
                  ->setDate($this->faker->dateTimeBetween('-2 years', '+6 months'))
 | 
			
		||||
                  ->setLabel($this->faker->words(rand(2,4), true))
 | 
			
		||||
                  ->setType($this->getReference(LoadEventTypes::$refs[array_rand(LoadEventTypes::$refs)]))
 | 
			
		||||
                  ->setCenter($center)
 | 
			
		||||
                  ;
 | 
			
		||||
            $manager->persist($event);
 | 
			
		||||
            $events[] = $event;
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        return $events;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -22,6 +22,18 @@ class Event
 | 
			
		||||
     */
 | 
			
		||||
    private $date;
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * @var \Chill\MainBundle\Entity\Center
 | 
			
		||||
     */
 | 
			
		||||
    private $center;
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     *
 | 
			
		||||
     * @var EventType
 | 
			
		||||
     */
 | 
			
		||||
    private $type;
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * @var \Doctrine\Common\Collections\Collection
 | 
			
		||||
     */
 | 
			
		||||
@@ -77,7 +89,7 @@ class Event
 | 
			
		||||
     *
 | 
			
		||||
     * @return Event
 | 
			
		||||
     */
 | 
			
		||||
    public function setDate($date)
 | 
			
		||||
    public function setDate(\DateTime $date)
 | 
			
		||||
    {
 | 
			
		||||
        $this->date = $date;
 | 
			
		||||
 | 
			
		||||
@@ -93,6 +105,42 @@ class Event
 | 
			
		||||
    {
 | 
			
		||||
        return $this->date;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public function setCenter(\Chill\MainBundle\Entity\Center $center)
 | 
			
		||||
    {
 | 
			
		||||
        $this->center = $center;
 | 
			
		||||
        
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * 
 | 
			
		||||
     * @return EventType
 | 
			
		||||
     */
 | 
			
		||||
    public function getType()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->type;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 
 | 
			
		||||
     * @param \Chill\EventBundle\Entity\EventType $type
 | 
			
		||||
     * @return \Chill\EventBundle\Entity\Event
 | 
			
		||||
     */
 | 
			
		||||
    public function setType(EventType $type)
 | 
			
		||||
    {
 | 
			
		||||
        $this->type = $type;
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * 
 | 
			
		||||
     * @return \Chill\MainBundle\Entity\Center
 | 
			
		||||
     */
 | 
			
		||||
    public function getCenter()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->center;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Add participation
 | 
			
		||||
 
 | 
			
		||||
@@ -21,7 +21,25 @@ class EventType
 | 
			
		||||
     * @var boolean
 | 
			
		||||
     */
 | 
			
		||||
    private $active;
 | 
			
		||||
    
 | 
			
		||||
    /**
 | 
			
		||||
     * @var \Doctrine\Common\Collections\Collection
 | 
			
		||||
     */
 | 
			
		||||
    private $roles;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var \Doctrine\Common\Collections\Collection
 | 
			
		||||
     */
 | 
			
		||||
    private $statuses;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructor
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        $this->roles = new \Doctrine\Common\Collections\ArrayCollection();
 | 
			
		||||
        $this->statuses = new \Doctrine\Common\Collections\ArrayCollection();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get id
 | 
			
		||||
@@ -80,24 +98,6 @@ class EventType
 | 
			
		||||
    {
 | 
			
		||||
        return $this->active;
 | 
			
		||||
    }
 | 
			
		||||
    /**
 | 
			
		||||
     * @var \Doctrine\Common\Collections\Collection
 | 
			
		||||
     */
 | 
			
		||||
    private $roles;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var \Doctrine\Common\Collections\Collection
 | 
			
		||||
     */
 | 
			
		||||
    private $statuses;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Constructor
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct()
 | 
			
		||||
    {
 | 
			
		||||
        $this->roles = new \Doctrine\Common\Collections\ArrayCollection();
 | 
			
		||||
        $this->statuses = new \Doctrine\Common\Collections\ArrayCollection();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Add role
 | 
			
		||||
 
 | 
			
		||||
@@ -55,9 +55,9 @@ class Participation
 | 
			
		||||
     *
 | 
			
		||||
     * @return Participation
 | 
			
		||||
     */
 | 
			
		||||
    public function setLastUpdate($lastUpdate)
 | 
			
		||||
    protected function update()
 | 
			
		||||
    {
 | 
			
		||||
        $this->lastUpdate = $lastUpdate;
 | 
			
		||||
        $this->lastUpdate = new \DateTime('now');
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
    }
 | 
			
		||||
@@ -82,6 +82,10 @@ class Participation
 | 
			
		||||
     */
 | 
			
		||||
    public function setEvent(\Chill\EventBundle\Entity\Event $event = null)
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->event !== $event) {
 | 
			
		||||
            $this->update();
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        $this->event = $event;
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
@@ -106,6 +110,10 @@ class Participation
 | 
			
		||||
     */
 | 
			
		||||
    public function setPerson(\Chill\PersonBundle\Entity\Person $person = null)
 | 
			
		||||
    {
 | 
			
		||||
        if ($person !== $this->person) {
 | 
			
		||||
            $this->update();
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        $this->person = $person;
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
@@ -130,6 +138,9 @@ class Participation
 | 
			
		||||
     */
 | 
			
		||||
    public function setRole(\Chill\EventBundle\Entity\Role $role = null)
 | 
			
		||||
    {
 | 
			
		||||
        if ($role !== $this->role) {
 | 
			
		||||
            $this->update();
 | 
			
		||||
        }
 | 
			
		||||
        $this->role = $role;
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
@@ -154,6 +165,10 @@ class Participation
 | 
			
		||||
     */
 | 
			
		||||
    public function setStatus(\Chill\EventBundle\Entity\Status $status = null)
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->status !== $status) {
 | 
			
		||||
            $this->update();
 | 
			
		||||
        }
 | 
			
		||||
        
 | 
			
		||||
        $this->status = $status;
 | 
			
		||||
 | 
			
		||||
        return $this;
 | 
			
		||||
 
 | 
			
		||||
@@ -17,4 +17,9 @@ Chill\EventBundle\Entity\Event:
 | 
			
		||||
        participations:
 | 
			
		||||
            targetEntity: Chill\EventBundle\Entity\Participation
 | 
			
		||||
            mappedBy: event
 | 
			
		||||
    manyToOne:
 | 
			
		||||
        center:
 | 
			
		||||
            targetEntity: Chill\MainBundle\Entity\Center
 | 
			
		||||
        type:
 | 
			
		||||
            targetEntity: Chill\EventBundle\Entity\EventType
 | 
			
		||||
    lifecycleCallbacks: {  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user