Chargement automatique des champs

Default
,

Bonjour,

Voila je rencontre un petit problème avec mon code.
Je suis débutant en symfony 4 et j'ai un petit problème concernat le chargement automatique des champs par des données

Ce que je fais

J'ai un Marché, une Sous_commission et Traitement. Chaque sous_commission peut étre lier aux plusieurs marchés pour lui faire des traitements.
Voici mes entitées

<?php

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;


/**
 * @ORM\Entity(repositoryClass="App\Repository\MarcheDAORepository")
 * @UniqueEntity("codeMarche")
 */
class MarcheDAO
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\Column(type="integer", unique=true)
     * 
     */
    private $codeMarche;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $natureDAO;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $typeDAO;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $nomMarche;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $description;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $bailleur;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $nomAC;

    /**
     * @ORM\Column(type="datetime")
     */
    private $dateLancement;

    /**
     * @ORM\Column(type="datetime")
     */
    private $dateDepot;

    /**
     * @ORM\Column(type="datetime")
     */
    private $dateCloture;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $gestionnaire;

    /**
     * @ORM\Column(type="string", length=255)
     * @Assert\File(mimeTypes={ "application/pdf" })
     */
    private $dce;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $etat;

    /**
     * @ORM\Column(type="string", length=255, nullable=true) 
     * @Assert\Image(
     *     minWidth = 200,
     *     maxWidth = 1000,
     *     minHeight = 200,
     *     maxHeight = 1000
     * )
     */
    private $annexe1;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Assert\Image(
     *     minWidth = 200,
     *     maxWidth = 1000,
     *     minHeight = 200,
     *     maxHeight = 1000
     * )
     */
    private $annexe2;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     * @Assert\Image(
     *     minWidth = 200,
     *     maxWidth = 1000,
     *     minHeight = 200,
     *     maxHeight = 1000
     * )
     */
    private $annexe3;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Traitement", mappedBy="marche", orphanRemoval=true)
     */
    private $traitements;

    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Soumission", mappedBy="marche", orphanRemoval=true)
     */
    private $soumissions;

    public function __construct()
    {
        $this->traitements = new ArrayCollection();
        $this->soumissions = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    public function getCodeMarche(): ?int
    {
        return $this->codeMarche;
    }

    public function setCodeMarche(int $codeMarche): self
    {
        $this->codeMarche = $codeMarche;

        return $this;
    }

    public function getNatureDAO(): ?string
    {
        return $this->natureDAO;
    }

    public function setNatureDAO(string $natureDAO): self
    {
        $this->natureDAO = $natureDAO;

        return $this;
    }

    public function getTypeDAO(): ?string
    {
        return $this->typeDAO;
    }

    public function setTypeDAO(string $typeDAO): self
    {
        $this->typeDAO = $typeDAO;

        return $this;
    }

    public function getNomMarche(): ?string
    {
        return $this->nomMarche;
    }

    public function setNomMarche(string $nomMarche): self
    {
        $this->nomMarche = $nomMarche;

        return $this;
    }

    public function getDescription(): ?string
    {
        return $this->description;
    }

    public function setDescription(string $description): self
    {
        $this->description = $description;

        return $this;
    }

    public function getBailleur(): ?string
    {
        return $this->bailleur;
    }

    public function setBailleur(string $bailleur): self
    {
        $this->bailleur = $bailleur;

        return $this;
    }

    public function getNomAC(): ?string
    {
        return $this->nomAC;
    }

    public function setNomAC(string $nomAC): self
    {
        $this->nomAC = $nomAC;

        return $this;
    }

    public function getDateLancement(): ?\DateTimeInterface
    {
        return $this->dateLancement;
    }

    public function setDateLancement(\DateTimeInterface $dateLancement): self
    {
        $this->dateLancement = $dateLancement;

        return $this;
    }

    public function getDateDepot(): ?\DateTimeInterface
    {
        return $this->dateDepot;
    }

    public function setDateDepot(\DateTimeInterface $dateDepot): self
    {
        $this->dateDepot = $dateDepot;

        return $this;
    }

    public function getDateCloture(): ?\DateTimeInterface
    {
        return $this->dateCloture;
    }

    public function setDateCloture(\DateTimeInterface $dateCloture): self
    {
        $this->dateCloture = $dateCloture;

        return $this;
    }

    public function getGestionnaire(): ?string
    {
        return $this->gestionnaire;
    }

    public function setGestionnaire(string $gestionnaire): self
    {
        $this->gestionnaire = $gestionnaire;

        return $this;
    }

    public function getDce()
    {
        return $this->dce;
    }

    public function setDce($dce)
    {
        $this->dce = $dce;

        return $this;
    }

    public function getEtat(): ?string
    {
        return $this->etat;
    }

    public function setEtat(string $etat): self
    {
        $this->etat = $etat;

        return $this;
    }

    public function getAnnexe1()
    {
        return $this->annexe1;
    }

    public function setAnnexe1( $annexe1)
    {
        $this->annexe1 = $annexe1;

        return $this;
    }

    public function getAnnexe2(): ?string
    {
        return $this->annexe2;
    }

    public function setAnnexe2(?string $annexe2): self
    {
        $this->annexe2 = $annexe2;

        return $this;
    }

    public function getAnnexe3(): ?string
    {
        return $this->annexe3;
    }

    public function setAnnexe3(?string $annexe3): self
    {
        $this->annexe3 = $annexe3;

        return $this;
    }

    /**
     * @return Collection|Traitement[]
     */
    public function getTraitements(): Collection
    {
        return $this->traitements;
    }

    public function addTraitement(Traitement $traitement): self
    {
        if (!$this->traitements->contains($traitement)) {
            $this->traitements[] = $traitement;
            $traitement->setMarche($this);
        }

        return $this;
    }

    public function removeTraitement(Traitement $traitement): self
    {
        if ($this->traitements->contains($traitement)) {
            $this->traitements->removeElement($traitement);
            // set the owning side to null (unless already changed)
            if ($traitement->getMarche() === $this) {
                $traitement->setMarche(null);
            }
        }

        return $this;
    }


    /**
     * @return Collection|Soumission[]
     */
    public function getSoumissions(): Collection
    {
        return $this->soumissions;
    }

    public function addSoumission(Soumission $soumission): self
    {
        if (!$this->soumissions->contains($soumission)) {
            $this->soumissions[] = $soumission;
            $soumission->setMarche($this);
        }

        return $this;
    }

    public function removeSoumission(Soumission $soumission): self
    {
        if ($this->soumissions->contains($soumission)) {
            $this->soumissions->removeElement($soumission);
            // set the owning side to null (unless already changed)
            if ($soumission->getMarche() === $this) {
                $soumission->setMarche(null);
            }
        }

        return $this;
    }


}

SousCommission.php

<?php

namespace App\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\SousCommissionRepository")
 */
class SousCommission
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\MembreCommission", inversedBy="sousCommissions")
     */
    private $Membres;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $responsabilite;

    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\MarcheDAO")
     */
    private $marches;


    public function __construct()
    {
        $this->Membres = new ArrayCollection();
        $this->marches = new ArrayCollection();
    }

    public function getId(): ?int
    {
        return $this->id;
    }

    /**
     * @return Collection|MembreCommission[]
     */
    public function getMembres(): Collection
    {
        return $this->Membres;
    }

    public function addMembre(MembreCommission $membre): self
    {
        if (!$this->Membres->contains($membre)) {
            $this->Membres[] = $membre;
        }

        return $this;
    }

    public function removeMembre(MembreCommission $membre): self
    {
        if ($this->Membres->contains($membre)) {
            $this->Membres->removeElement($membre);
        }

        return $this;
    }

    public function getResponsabilite(): ?string
    {
        return $this->responsabilite;
    }

    public function setResponsabilite(string $responsabilite): self
    {
        $this->responsabilite = $responsabilite;

        return $this;
    }

    /**
     * @return Collection|MarcheDAO[]
     */
    public function getMarches(): Collection
    {
        return $this->marches;
    }

    public function addMarch(MarcheDAO $march): self
    {
        if (!$this->marches->contains($march)) {
            $this->marches[] = $march;
        }

        return $this;
    }

    public function removeMarch(MarcheDAO $march): self
    {
        if ($this->marches->contains($march)) {
            $this->marches->removeElement($march);
        }

        return $this;
    }


}

Traitement.php

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity(repositoryClass="App\Repository\TraitementRepository")
 */
class Traitement
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;

    // /**
    //  * @ORM\Column(type="string", length=255)
    //  */
    // private $numero;

    /**
     * @ORM\Column(type="datetime")
     */
    private $date;

    /**
     * @ORM\Column(type="string", length=255)
     */
    private $nature;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $observation;

    /**
     * @ORM\Column(type="string", length=255, nullable=true)
     */
    private $avis;


    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\SousCommission")
     * @ORM\JoinColumn(nullable=false)
     */
    private $sousCommission;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $reserve;

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    private $motif;

    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\MarcheDAO", inversedBy="traitements")
     * @ORM\JoinColumn(nullable=false,  onDelete="CASCADE")
     */
    private $marche;

    public function getId(): ?int
    {
        return $this->id;
    }

    // public function getNumero(): ?string
    // {
    //     return $this->numero;
    // }

    // public function setNumero(string $numero): self
    // {
    //     $this->numero = $numero;

    //     return $this;
    // }

    public function getDate(): ?\DateTimeInterface
    {
        return $this->date;
    }

    public function setDate(\DateTimeInterface $date): self
    {
        $this->date = $date;

        return $this;
    }

    public function getNature(): ?string
    {
        return $this->nature;
    }

    public function setNature(string $nature): self
    {
        $this->nature = $nature;

        return $this;
    }

    public function getObservation(): ?string
    {
        return $this->observation;
    }

    public function setObservation(?string $observation): self
    {
        $this->observation = $observation;

        return $this;
    }

    public function getAvis(): ?string
    {
        return $this->avis;
    }

    public function setAvis(?string $avis): self
    {
        $this->avis = $avis;

        return $this;
    }



    public function getSousCommission(): ?SousCommission
    {
        return $this->sousCommission;
    }

    public function setSousCommission(?SousCommission $sousCommission): self
    {
        $this->sousCommission = $sousCommission;

        return $this;
    }

    public function getReserve(): ?string
    {
        return $this->reserve;
    }

    public function setReserve(?string $reserve): self
    {
        $this->reserve = $reserve;

        return $this;
    }

    public function getMotif(): ?string
    {
        return $this->motif;
    }

    public function setMotif(?string $motif): self
    {
        $this->motif = $motif;

        return $this;
    }

    public function getMarche(): ?MarcheDAO
    {
        return $this->marche;
    }

    public function setMarche(?MarcheDAO $marche): self
    {
        $this->marche = $marche;

        return $this;
    }
}

TraitementController.php

  // Action ajouterTraitement
        $traitement = new Traitement();
        $form = $this->createForm(TraitementType::class, $traitement);
        //Traitement de formulaire
        $form->handleRequest($request);
        if($form->isSubmitted() && $form->isValid()){
            $date= new \DateTime();
            $traitement->setDate($date);
            $manager->persist($traitement);
            $manager->flush();
            $this->addFlash('success', ' Un nouveau traitement ajouté avec succès!!');

            return $this->redirectToRoute('traitement');
        }

TraitementType.php

<?php

namespace App\Form;

use App\Entity\MarcheDAO;
use App\Entity\Traitement;
use App\Entity\SousCommission;

use Doctrine\ORM\EntityRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\TextType;

use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\DateTimeType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;


class TraitementType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $now = new \DateTime();
        $builder
            ->add('marche', EntityType::class,[
                'label'=>'Marché',
                'placeholder'=>'',
                'class' => MarcheDAO::class,
                'query_builder' => function (EntityRepository $er) use($now){
                    return $er->createQueryBuilder('m')
                        ->addSelect('m')
                        ->where('m.dateCloture > :date')
                        ->setParameter('date',$now);
                },
                'choice_label' => 'nomMarche',
                'multiple'=>false
                ])
            ->add('sousCommission', EntityType::class,[
                    'class' => SousCommission::class,
                    'query_builder' => function (EntityRepository $er) {
                        return $er->createQueryBuilder('sc')
                            ->addSelect('sc');
                    },
                    'placeholder'=>'',
                    'label'=>'La sous commission ',
                    'choice_label' => 'responsabilite'
                ])
            ->add('nature', ChoiceType::class,[
                'placeholder'=>'',
                'label' => 'Nature de traitement',
                'choices'=>[
                    'AT'=>'Traitement Téchnique',
                    'AF'=>'Traitement Financiér',
                    'FT'=>'Traitement Téchnique et Financiér']
                ])
            ->add('observation', TextareaType::class, [
                'required'=>false,
                'label'=> 'L\'obsérvation',
                'attr' => ['class' => 'tinymce'],
            ])
            ->add('avis', TextType::class, [
                'label'=>'Avis/Décision',
                'required'=>false,
            ])
            ->add('reserve', TextareaType::class, [
                'attr' => ['class' => 'tinymce'],
                'label'=>'Si réserve/préciser',
                'required'=>false,
            ])
            ->add('motif', TextareaType::class, [
                'attr' => ['class' => 'tinymce'],
                'label'=>'Si infructueux/Motifs',
                'required'=>false,
            ])

        ;
    }

    public function configureOptions(OptionsResolver $resolver)
    {
        $resolver->setDefaults([
            'data_class' => Traitement::class,
        ]);
    }
}

Ce que je veux

Au moment des traitement, je veux quand je sélection un marché parmi des marchés je reccupére automatiquement sa SousCommission,
Sachant que la SousCommission et attribué à un marché au moment de sa création.

Ce que j'obtiens

J'ai obtien un formulaire mais, j'ai sais pas comment charger automatiquement certains champs en se basant sur d'autres.

J'aimerai bien que quelqu'un m'aide.
Merci