Bonjour,
Je n'ai pas d'erreur, mais je ne sais simplement pas comment m'y prendre. Actuellement, j'ai un système qui récupère une liste de cours, l'utilisateur choisie son cours, d'autres paramètres, et soumet le formulaire en base.
J'ai les tables suivantes :
cours : id(PK) + nom
cours_planning: id + id du cours(FK de l'id Cours)
Visuellement, on a "Cours":
Nom : cours.png
Affichages : 79
Taille : 19,2 Ko
puis Cours_planning:
Nom : lk.png
Affichages : 83
Taille : 5,5 Ko
Je ne veux récupérer, dans ma liste, que les cours qui font partis de cours_planning. Je veux que l'utilisateur visualise la liste des cours (leur nom, seulement ceux dont je retrouve l'id dans cours_planning), et j'insers ensuite l'id du choix sélectionné.
Mon code actuelle :
FORM
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
 
    $formation = $options['formation'];
 
    $builder
        ->add('cours', EntityType::class, array(
          'class' => Cours::class,
          'label' => false,
          'placeholder' => 'Cours',
          'required' => true,
          'choice_label' => 'nomUe',
          'choices' => 'id',
          'attr' => array('class' => 'custom-select')
        ))
Mes entités. Cours:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
 
<?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\CoursRepository")
 */
class Cours
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;
 
    /**
     * @ORM\Column(type="string", length=255)
     */
    private $nomUe;
    /**
     * @ORM\Column(type="integer", length=255)
     */
    private $groupeTd;
    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Formation", mappedBy="cours")
     */
    private $formation;
 
    /**
     * @ORM\OneToMany(targetEntity="App\Entity\Pointage", mappedBy="cours")
     */
    private $pointage;
 
    /**
     * @ORM\ManyToMany(targetEntity="App\Entity\Utilisateur", mappedBy="cours")
     */
    private $utilisateurs;
 
    public function __construct()
    {
        $this->formation = new ArrayCollection();
        $this->pointage = new ArrayCollection();
        $this->utilisateurs = new ArrayCollection();
    }
 
    public function getId(): ?int
    {
        return $this->id;
    }
 
    public function getNomUe(): ?string
    {
        return $this->nomUe;
    }
 
    public function setNomUe(string $nomUe): self
    {
        $this->nomUe = $nomUe;
 
        return $this;
    }
    public function getGroupeTd(): ?string
    {
        return $this->groupeTd;
    }
 
    public function setGroupeTd(string $groupeTd): self
    {
        $this->groupeTd = $groupeTd;
 
        return $this;
    }
    public function getDate(): ?string
    {
        return $this->date;
    }
 
    public function setDate()
    {
        $date = new \DateTime("now");
        $this->date = date_format($date, 'Y-m-d H:i:s');
        //$this->date = new \DateTime("now");
    }
 
    /**
     * @return Collection|Formation[]
     */
    public function getFormation(): Collection
    {
        return $this->formation;
    }
 
    public function addFormation(Formation $formation): self
    {
        if (!$this->formation->contains($formation)) {
            $this->formation[] = $formation;
            $formation->addCour($this);
        }
 
        return $this;
    }
 
    public function removeFormation(Formation $formation): self
    {
        if ($this->formation->contains($formation)) {
            $this->formation->removeElement($formation);
            $formation->removeCour($this);
        }
 
        return $this;
    }
 
    /**
     * @return Collection|Pointage[]
     */
    public function getPointage(): Collection
    {
        return $this->pointage;
    }
 
    public function addPointage(Pointage $pointage): self
    {
        if (!$this->pointage->contains($pointage)) {
            $this->pointage[] = $pointage;
            $pointage->setCours($this);
        }
 
        return $this;
    }
 
    public function removePointage(Pointage $pointage): self
    {
        if ($this->pointage->contains($pointage)) {
            $this->pointage->removeElement($pointage);
            // set the owning side to null (unless already changed)
            if ($pointage->getCours() === $this) {
                $pointage->setCours(null);
            }
        }
 
        return $this;
    }
 
	public function __toString()
               	{
               		return $this->getNomUe();
               	}
 
    /**
     * @return Collection|Utilisateur[]
     */
    public function getUtilisateurs(): Collection
    {
        return $this->utilisateurs;
    }
 
    public function addUtilisateur(Utilisateur $utilisateur): self
    {
        if (!$this->utilisateurs->contains($utilisateur)) {
            $this->utilisateurs[] = $utilisateur;
            $utilisateur->addCour($this);
        }
 
        return $this;
    }
 
    public function removeUtilisateur(Utilisateur $utilisateur): self
    {
        if ($this->utilisateurs->contains($utilisateur)) {
            $this->utilisateurs->removeElement($utilisateur);
            $utilisateur->removeCour($this);
        }
 
        return $this;
    }
 
 
	protected $admin;
 
	public function getAdmin()
	{
		return $this->admin;
	}
}
CoursPlanning:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
 
<?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\CoursPlanningRepository")
 */
class CoursPlanning
{
    /**
     * @ORM\Id()
     * @ORM\GeneratedValue()
     * @ORM\Column(type="integer")
     */
    private $id;
 
    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\Cours")
     * @ORM\JoinColumn(name="cours", referencedColumnName="id")
     */
    private $cours;
    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\PlageHoraire", inversedBy="pointage")
     * @ORM\JoinColumn(nullable=false)
     */
    private $plageHoraire;
    /**
     * @ORM\ManyToOne(targetEntity="App\Entity\DateCours")
     * @ORM\JoinColumn(name="date_cours", referencedColumnName="id")
     */
    private $dateCours;
 
    public function __construct()
    {
        $this->formation = new ArrayCollection();
        $this->pointage = new ArrayCollection();
        $this->utilisateurs = new ArrayCollection();
    }
 
    public function getId(): ?int
    {
        return $this->id;
    }
 
    public function getCours(): ?int
    {
        return $this->cours;
    }
 
    public function setCours(int $cours): self
    {
        $this->cours = $cours;
 
        return $this;
    }
    public function getPlageHoraire(): ?int
    {
        return $this->plageHoraire;
    }
 
    public function setPlageHoraire(int $plageHoraire): self
    {
        $this->plageHoraire = $plageHoraire;
 
        return $this;
    }
    public function getDateCours(): ?int
    {
        return $this->dateCours;
    }
 
    public function setDateCours(int $dateCours): self
    {
        $this->dateCours = $dateCours;
 
        return $this;
    }
}
Comment puis-je m'y prendre au niveau de mon form? Si possible sans avoir besoin de construire une requête SQL, simplement en travaillant avec le FORM, les entités, le controller.
Merci