ajout fixtures

This commit is contained in:
Gael Peltey 2020-02-19 12:57:53 +01:00
parent dc741916c4
commit 7e99995c98
4 changed files with 230 additions and 12 deletions

View File

@ -3,6 +3,7 @@
namespace App\DataFixtures;
use App\Entity\Project;
use App\Entity\Request;
use App\Entity\User;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
@ -14,15 +15,77 @@ class ProjectFixtures extends Fixture implements DependentFixtureInterface
public function load(ObjectManager $manager)
{
$dev1 = $manager
//NEW PROJECT
$user = $manager
->getRepository(User::class)
->findOneByUsername('dev1')
;
$project1 = new Project();
$project1->setName("Test");
$project1->addUser($dev1);
$manager->persist($project1);
$project = new Project();
$request = $manager
->getRepository(Request::class)
->findOneByTitle('Demande num 1')
;
$project->addRequest($request);
$request = $manager
->getRepository(Request::class)
->findOneByTitle('Demande num 2')
;
$project->addRequest($request);
$request = $manager
->getRepository(Request::class)
->findOneByTitle('Demande num 3')
;
$project->addRequest($request);
$project->setName("Projet 1");
$project->addUser($user);
$manager->persist($project);
//NEW PROJECT
$user = $manager
->getRepository(User::class)
->findOneByUsername('client1')
;
$project = new Project();
$request = $manager
->getRepository(Request::class)
->findOneByTitle('Demande num 4')
;
$project->addRequest($request);
$request = $manager
->getRepository(Request::class)
->findOneByTitle('Demande num 5')
;
$project->addRequest($request);
$project->setName("Projet 2");
$project->addUser($user);
$manager->persist($project);
//NEW PROJECT
$user = $manager
->getRepository(User::class)
->findOneByUsername('client1')
;
$project = new Project();
$project->setName("Projet 3");
$project->addUser($user);
$manager->persist($project);
//NEW PROJECT
$user = $manager
->getRepository(User::class)
->findOneByUsername('client2')
;
$project = new Project();
$project->setName("Projet 4");
$project->addUser($user);
$manager->persist($project);
$manager->flush();
@ -32,6 +95,7 @@ class ProjectFixtures extends Fixture implements DependentFixtureInterface
{
return [
UserFixtures::class,
RequestFixtures::class
];
}

View File

@ -0,0 +1,121 @@
<?php
namespace App\DataFixtures;
use App\Entity\Request;
use App\Entity\RequestStatus;
use App\Entity\User;
use DateTime;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Common\Persistence\ObjectManager;
class RequestFixtures extends Fixture implements DependentFixtureInterface
{
public function load(ObjectManager $manager)
{
//NEW REQUEST
$user = $manager
->getRepository(User::class)
->findOneByUsername('client1')
;
$status = $manager
->getRepository(RequestStatus::class)
->findOneBySlug('en-attente')
;
$request = new Request();
$request->setTitle("Demande num 1");
$request->setAuthor($user);
$request->setCreatedAt(new DateTime());
$request->setStatus($status);
$manager->persist($request);
//NEW REQUEST
$user = $manager
->getRepository(User::class)
->findOneByUsername('client1')
;
$status = $manager
->getRepository(RequestStatus::class)
->findOneBySlug('pris-en-compte')
;
$request = new Request();
$request->setTitle("Demande num 2");
$request->setAuthor($user);
$request->setCreatedAt(new DateTime());
$request->setStatus($status);
$manager->persist($request);
//NEW REQUEST
$user = $manager
->getRepository(User::class)
->findOneByUsername('client1')
;
$status = $manager
->getRepository(RequestStatus::class)
->findOneBySlug('en-cours-de-traitement')
;
$request = new Request();
$request->setTitle("Demande num 3");
$request->setAuthor($user);
$request->setCreatedAt(new DateTime());
$request->setStatus($status);
$manager->persist($request);
//NEW REQUEST
$user = $manager
->getRepository(User::class)
->findOneByUsername('client2')
;
$status = $manager
->getRepository(RequestStatus::class)
->findOneBySlug('traite')
;
$request = new Request();
$request->setTitle("Demande num 4");
$request->setAuthor($user);
$request->setCreatedAt(new DateTime());
$request->setStatus($status);
$manager->persist($request);
//NEW REQUEST
$user = $manager
->getRepository(User::class)
->findOneByUsername('client2')
;
$status = $manager
->getRepository(RequestStatus::class)
->findOneBySlug('clos')
;
$request = new Request();
$request->setTitle("Demande num 5");
$request->setAuthor($user);
$request->setCreatedAt(new DateTime());
$request->setStatus($status);
$manager->persist($request);
$manager->flush();
}
public function getDependencies()
{
return [
RequestStatusFixtures::class,
UserFixtures::class,
];
}
}

View File

@ -11,16 +11,32 @@ class RequestStatusFixtures extends Fixture
public function load(ObjectManager $manager)
{
$statuses = [
'En attente',
'Pris en compte',
'En cours de traitement',
'Traité',
'Clos',
[
'label' => 'En attente',
'slug' => 'en-attente'
],
[
'label' => 'Pris en compte',
'slug' => 'pris-en-compte'
],
[
'label' => 'En cours de traitement',
'slug' => 'en-cours-de-traitement'
],
[
'label' => 'Traité',
'slug' => 'traite'
],
[
'label' => 'Clos',
'slug' => 'clos'
],
];
foreach($statuses as $statusLabel) {
foreach($statuses as $s) {
$status = new RequestStatus();
$status->setLabel($statusLabel);
$status->setLabel($s['label']);
$status->setSlug($s['slug']);
$manager->persist($status);
}

View File

@ -23,6 +23,11 @@ class RequestStatus
*/
private $label;
/**
* @ORM\Column(type="string", length=64)
*/
private $slug;
/**
* @ORM\OneToMany(targetEntity="App\Entity\Request", mappedBy="status")
*/
@ -50,6 +55,18 @@ class RequestStatus
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(string $slug): self
{
$this->slug = $slug;
return $this;
}
/**
* @return Collection|Request[]
*/