<?php
namespace App\Controller\Front;
use App\Entity\Colonie;
use App\Entity\ColonieStatus;
use App\Entity\Ruche;
use App\Entity\Rucher;
use App\Entity\Customer;
use App\Entity\EnsembleType;
use App\Entity\HiveType;
use App\Entity\Materiel;
use App\Entity\MaterielGroup;
use App\Entity\MaterielSpecs;
use App\Entity\MaterielStatus;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class FrontDefaultController extends AbstractController
{
protected EntityManagerInterface $em;
/**
* UserController constructor.
* @param EntityManagerInterface|null $em
*/
public function __construct(EntityManagerInterface $em)
{
$this->em = $em;
}
/**
* @Route("/", name="app_home")
*/
public function index()
{
//$this->addFlash('info', "Front mlessage");
//$this->testCreateCustomer();
//$this->testCreateRucher();
//$this->testCreateGroup();
//$this->testCreateEnsembleType();
//$this->testCreateRuches();
/*
$materiels = $this->em->getRepository(Materiel::class)->findAll();
foreach ($materiels as $key => $mat) {
$mat->setUpdatedAt(new \DateTime());
}
$this->em->flush();
*/
return $this->render('front/page/index.html.twig', [
]);
}
private function testCreateEnsembleType() {
$me = $this->getUser();
$customer = $me->getCustomer();
$ens = new EnsembleType();
$ens->setCustomer($customer);
$ens->setAuthor($me);
$ens->setName("Ma Ruche Dadant 10 Hybride");
$ens->setHiveType($this->em->getRepository(HiveType::class)->findOneById(1));
$ens->setCorps($this->em->getRepository(MaterielSpecs::class)->findOneById(1));
$ens->setPlancher($this->em->getRepository(MaterielSpecs::class)->findOneById(2));
$ens->setToit($this->em->getRepository(MaterielSpecs::class)->findOneById(3));
$ens->setNourrisseur($this->em->getRepository(MaterielSpecs::class)->findOneById(11));
$this->em->persist($ens);
$this->em->flush();
}
private function testCreateGroup() {
$me = $this->getUser();
$customer = $me->getCustomer();
$typeD10 = $this->em->getRepository(HiveType::class)->findOneById(1);
$matGroupe = new MaterielGroup();
$matGroupe->setCustomer($customer);
$matGroupe->setAuthor($me);
$matGroupe->setName("Ruche Dadant 10");
$matGroupe->setPrefix("R");
$matGroupe->setHiveType($typeD10);
$this->em->persist($matGroupe);
$this->em->flush();
}
private function testCreateCustomer() {
$company = new Customer();
$company->setName("Le rucher de Sainte Trinide");
$company->setAddress1("1724 che de la Piole Paul Venel");
$company->setZipcode("83110");
$company->setCity("Sanary sur Mer");
$company->setContactEmail("bluestart83@gmail.com");
$company->setContactFirstName("Arnaud");
$company->setContactLastName("Lio");
$this->em->persist($company);
$this->em->flush();
}
private function testCreateRucher() {
$rucher = new Rucher();
$rucher->setCity("Sanary sur Mer");
$rucher->setName("Rucher Ste Trinide");
$rucher->setAuthor($this->getUser());
$customerRepo = $this->em->getRepository(Customer::class);
$company = $customerRepo->findOneById(1);
$rucher->setCustomer($company);
$this->em->persist($rucher);
$this->em->flush();
}
private function testCreateRuches() {
$me = $this->getUser();
$customer = $me->getCustomer();
$matStatusNew = $this->em->getRepository(MaterielStatus::class)->findOneById(1);
$coloStatusOK = $this->em->getRepository(ColonieStatus::class)->findOneById(1);
$corpsD10Pin = $this->em->getRepository(MaterielSpecs::class)->findOneById(1);
$groupD10 = $this->em->getRepository(MaterielGroup::class)->findOneById(1);
$ensType = $this->em->getRepository(EnsembleType::class)->findOneById(1);
//echo $groupD10->getId(); die;
for($i=0; $i<1; $i++) {
$ruche = new Ruche();
$ruche->setAuthor($me);
$ruche->setCustomer($customer);
$ruche->setType($ensType);
$ruche->setDateFirstUse(new \DateTime());
$corps = new Materiel();
$corps->setAuthor($me);
$corps->setCustomer($customer);
$corps->setCurrentRuche($ruche);
$corps->setSpecs($corpsD10Pin);
$corps->setGroup($groupD10);
$corps->setStatus($matStatusNew);
$ruche->setCorpsMain($corps);
$this->em->persist($ruche);
$this->em->flush();
$colo = new Colonie();
$colo->setAuthor($me);
$colo->setCustomer($customer);
$colo->setStatus($coloStatusOK);
$ruche->setColonie($colo);
//$this->em->flush();
}
$this->em->flush();
}
}