Alors voilà, j'ai 7 formulaires à imbriquer qui n'ont pas tous une relation directe avec le formulaire principale comme vous pouvez le voir sur le schéma. Le but est de faire un formulaire pour créer une intervention. Je dois notamment avoir le nom et le prénom du technicien sur mon formulaire d'intervention. J'ai ajouté une CollectionType dans mon formulaire Intervention. A l'heure actuelle je n'ai que le label mais pas d'employés. Je sèche, ça fait 2 jours que j'écume le web, j’ai trouvé des choses mais rien de concluant. SI quelqu'un a la solution à mon problème, je le bénie d'avance
Le résultat actuel
Ma base de données
InterventionType
InterventionController
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 <?php namespace GestionBundle\Form; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CollectionType; use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\OptionsResolver\OptionsResolver; class InterventionType extends AbstractType { /** * {@inheritdoc} */ public function buildForm(FormBuilderInterface $builder, array $options) { $builder->add('staffs', CollectionType::class , array ('entry_type' => StaffType::class, 'allow_add' => true , 'prototype' => true, 'by_reference' => false,)) ->add('interventionDate') ->add('weekNumber') ->add('numberHours') ->add('comments') ->add('interventionType'); } /** * {@inheritdoc} */ public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults(array( 'data_class' => 'GestionBundle\Entity\Intervention' )); } /** * {@inheritdoc} */ public function getBlockPrefix() { return 'gestionbundle_intervention'; } }
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 <?php namespace GestionBundle\Controller; use GestionBundle\Entity\Intervention; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; /** * Intervention controller. * */ class InterventionController extends Controller { /** * Lists all intervention entities. * */ public function indexAction() { $em = $this->getDoctrine()->getManager(); $interventions = $em->getRepository('GestionBundle:Intervention')->findAll(); return $this->render('intervention/index.html.twig', array( 'interventions' => $interventions, )); } /** * Creates a new intervention entity. * */ public function newAction(Request $request) { $intervention = new Intervention(); $form = $this->createForm('GestionBundle\Form\InterventionType', $intervention); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->persist($intervention); $em->flush(); return $this->redirectToRoute('intervention_show', array('idIntervention' => $intervention->getIdintervention())); } return $this->render('intervention/new.html.twig', array( 'intervention' => $intervention, 'form' => $form->createView(), )); } /** * Finds and displays a intervention entity. * */ public function showAction(Intervention $intervention) { $deleteForm = $this->createDeleteForm($intervention); return $this->render('intervention/show.html.twig', array( 'intervention' => $intervention, 'delete_form' => $deleteForm->createView(), )); } /** * Displays a form to edit an existing intervention entity. * */ public function editAction(Request $request, Intervention $intervention) { $deleteForm = $this->createDeleteForm($intervention); $editForm = $this->createForm('GestionBundle\Form\InterventionType', $intervention); $editForm->handleRequest($request); if ($editForm->isSubmitted() && $editForm->isValid()) { $this->getDoctrine()->getManager()->flush(); return $this->redirectToRoute('intervention_edit', array('idIntervention' => $intervention->getIdintervention())); } return $this->render('intervention/edit.html.twig', array( 'intervention' => $intervention, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), )); } /** * Deletes a intervention entity. * */ public function deleteAction(Request $request, Intervention $intervention) { $form = $this->createDeleteForm($intervention); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { $em = $this->getDoctrine()->getManager(); $em->remove($intervention); $em->flush(); } return $this->redirectToRoute('intervention_index'); } /** * Creates a form to delete a intervention entity. * * @param Intervention $intervention The intervention entity * * @return \Symfony\Component\Form\Form The form */ private function createDeleteForm(Intervention $intervention) { return $this->createFormBuilder() ->setAction($this->generateUrl('intervention_delete', array('idIntervention' => $intervention->getIdintervention()))) ->setMethod('DELETE') ->getForm() ; } }
Intervention
Staff
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247 <?php namespace GestionBundle\Entity; use DateTime; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; /** * Intervention * * @ORM\Table(name="intervention") * @ORM\Entity(repositoryClass="GestionBundle\Repository\InterventionRepository") */ class Intervention { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $idIntervention; /** * @var DateTime * * @ORM\Column(name="intervention_date", type="date") */ private $interventionDate; /** * @var int * * @ORM\Column(name="week_number", type="smallint") */ private $weekNumber; /** * @var float * * @ORM\Column(name="number_hours", type="float") */ private $numberHours; /** * @var string * * @ORM\Column(name="comments", type="text", nullable=true) */ private $comments; /** * @ORM\OneToMany(targetEntity="KindWork", mappedBy="intervention") */ private $kindWork; /** * * @ORM\ManyToOne(targetEntity="InterventionType", inversedBy="intervention") * */ private $interventionType; private $staffs; /** * Constructor/Constructeur */ function __construct() { $this->kindWork = new ArrayCollection(); $this -> staffs = new ArrayCollection (); } /** * Get idIntervention * * @return int */ public function getIdIntervention() { return $this->idIntervention; } /** * Set interventionDate * * @param DateTime $interventionDate * * @return Intervention */ public function setInterventionDate($interventionDate) { $this->interventionDate = $interventionDate; return $this; } /** * Get interventionDate * * @return DateTime */ public function getInterventionDate() { return $this->interventionDate; } /** * Set weekNumber * * @param integer $weekNumber * * @return Intervention */ public function setWeekNumber($weekNumber) { $this->weekNumber = $weekNumber; return $this; } /** * Get weekNumber * * @return int */ public function getWeekNumber() { return $this->weekNumber; } /** * Set numberHours * * @param float $numberHours * * @return Intervention */ public function setNumberHours($numberHours) { $this->numberHours = $numberHours; return $this; } /** * Get numberHours * * @return float */ public function getNumberHours() { return $this->numberHours; } /** * Set comments * * @param string $comments * * @return Intervention */ public function setComments($comments) { $this->comments = $comments; return $this; } /** * Get comments * * @return string */ public function getComments() { return $this->comments; } /** * Get kindWork * * @return int */ public function getKindWork() { return $this->kindWork; } /** * Get interventionType * * @return int */ public function getInterventionType() { return $this->interventionType; } /** * Generate by Doctrine * * Add kindWork * * @param KindWork $kindWork * * @return Intervention */ public function addKindWork(KindWork $kindWork) { $this->kindWork[] = $kindWork; return $this; } /** * Generate by Doctrine * * Remove kindWork * * @param KindWork $kindWork */ public function removeKindWork(KindWork $kindWork) { $this->kindWork->removeElement($kindWork); } /** * Generate by Doctrine * * Set interventionType * * @param InterventionType $interventionType * * @return Intervention */ public function setInterventionType(InterventionType $interventionType = null) { $this->interventionType = $interventionType; return $this; } public function getStaffs() { return $this->staffs; } /** * toString method/Méthode toString */ public function __toString() { return $this->interventionDate; } }
Formulaire pour créer une intervention
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330 <?php namespace GestionBundle\Entity; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Doctrine\ORM\Mapping\UniqueConstraint; use Symfony\Component\Validator\Constraints\DateTime; use Symfony\Component\Validator\Constraints\NotBlank; /** * Staff * * @ORM\Table(name="staff", uniqueConstraints={@UniqueConstraint(name="email",columns={"email"})}) * @ORM\Entity(repositoryClass="GestionBundle\Repository\StaffRepository") */ class Staff { /** * @var int * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") */ private $idStaff; /** * @NotBlank(message="staff.lastName.not_blank") * * @var string * * @ORM\Column(name="last_name", type="string", length=50) */ private $lastName; /** * @var string * * @ORM\Column(name="first_name", type="string", length=50) */ private $firstName; /** * @var string * * @ORM\Column(name="phone_number", type="string", nullable=true, length=12) */ private $phoneNumber; /** * @var string * * @ORM\Column(name="email", type="string", length=50, nullable=true, unique=true) */ private $email; /** * @var string * * @ORM\Column(name="password", type="string", length=15, nullable=true) */ private $password; /** * @var DateTime * * @ORM\Column(name="date_begin", type="date", nullable=true) */ private $dateBegin; /** * @var DateTime * * @ORM\Column(name="date_end", type="date", nullable=true) */ private $dateEnd; /** * @NotBlank(message="staff.profile.not_blank") * * @ORM\ManyToOne(targetEntity="Profile", inversedBy="staff") */ private $profile; /** * @ORM\ManyToMany(targetEntity="Place") */ private $place; /** * Constructor/Constructeur */ function __construct() { $this->place = new ArrayCollection(); } /** * Get idStaff * * @return int */ public function getIdStaff() { return $this->idStaff; } /** * Set lastName * * @param string $lastName * * @return Staff */ public function setLastName($lastName) { $this->lastName = $lastName; return $this; } /** * Get lastName * * @return string */ public function getLastName() { return $this->lastName; } /** * Set firstName * * @param string $firstName * * @return Staff */ public function setFirstName($firstName) { $this->firstName = $firstName; return $this; } /** * Get firstName * * @return string */ public function getFirstName() { return $this->firstName; } /** * Set phoneNumber * * @param string $phoneNumber * * @return Staff */ public function setPhoneNumber($phoneNumber) { $this->phoneNumber = $phoneNumber; return $this; } /** * Get phoneNumber * * @return string */ public function getPhoneNumber() { return $this->phoneNumber; } /** * Set email * * @param string $email * * @return Staff */ public function setEmail($email) { $this->email = $email; return $this; } /** * Get email * * @return string */ public function getEmail() { return $this->email; } /** * Set password * * @param string $password * * @return Staff */ public function setPassword($password) { $this->password = $password; return $this; } /** * Get password * * @return string */ public function getPassword() { return $this->password; } /** * Set dateBegin * * @param DateTime $dateBegin * * @return Staff */ public function setDateBegin($dateBegin) { $this->dateBegin = $dateBegin; return $this; } /** * Get dateBegin * * @return DateTime */ public function getDateBegin() { return $this->dateBegin; } /** * Set dateEnd * * @param DateTime $dateEnd * * @return Staff */ public function setDateEnd($dateEnd) { $this->dateEnd = $dateEnd; return $this; } /** * Get dateEnd * * @return DateTime */ public function getDateEnd() { return $this->dateEnd; } /** * Get profile * * @return int */ public function getProfile() { return $this->profile; } /** * Get place * * @return int */ public function getPlace() { return $this->place; } /** * Generate by Doctrine * * Set profile * * @param Profile $profile * * @return Staff */ public function setProfile(Profile $profile = null) { $this->profile = $profile; return $this; } /** * Generate by Doctrine * * Add place * * @param Place $place * * @return Staff */ public function addPlace(Place $place) { $this->place[] = $place; return $this; } /** * Generate by Doctrine * * Remove place * * @param Place $place */ public function removePlace(Place $place) { $this->place->removeElement($place); } /** * toString method/Méthode toString */ public function __toString() { return $this->lastName; } }
Ce à quoi ça doit tendre pour vous donner une idée.
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 {% extends 'base.html.twig' %} {#Form to create an intervention/Formulaire pour créer une intervention#} {% block body %} <h2>Créer une intervention</h2> {{ form_start(form) }} {{ form_errors(form) }} {{ form_row(form.staffs, {'label': 'Technicien'}) }} <ul class= "staffs" data-prototype= " {{ form_widget ( form.staffs.vars.prototype.lastName )| e ( 'html_attr' ) }} " > {% for staff in form.staffs %} <li> {{ form_row ( form.staffs.vars.prototype.lastName )| e }} </li> {% endfor %} </ul> {{ form_row(form.interventionDate, {'label': "Date d'intervention"}) }} {{ form_row(form.weekNumber, {'label': 'N° semaine'}) }} {{ form_row(form.numberHours, {'label': "Nombre d'heures"}) }} {{ form_row(form.comments, {'label': 'Commentaires'}) }} {{ form_row(form.interventionType, {'label': "Type d'intervention"})}} <input type="submit" value="Créer l'intervention" /> {{ form_end(form) }} <a href="{{ path('intervention_index') }}">Retour à la liste</a> {% endblock %}
![]()
Partager