Doctrine vytáhnutí dat do multipleru formuláře

Petr Parolek
Člen | 455
+
0
-

Ahoj, jak mám prosím z Doctriny vytáhnout data a vytvořit požadované pole na ř. 131?

<?php
$this->values = [];

$qb = $this->userFascade->getQueryBuilder(UserFascade::CHILD_BUS_CHOICES_REPOSITORY, 'c')
	->select('c')
	->where('c.child = :childId')
	->setParameter('childId', $this->id);
$choices = $qb->getQuery()->getResult();

foreach ($choices as $choice) {
	bdump($choice);
	$lineId = $choice->getLine()->getId();
	$dayId = $choice->getDay()->getId();
	// tady nevím, co dal
}


$this->values['days1'] = [1, 3, 4];
$this->values['days20'] = [1, 4];
bdump($this->values);
$form->setDefaults($this->values);

?>
1 App\Model\User\Entities\ChildBusChoice #cf31
2 id private => 1
3 child private => Kdyby\GeneratedProxy\__CG__\App\Model\User\Entities\Child #58ca
4 line private => Kdyby\GeneratedProxy\__CG__\App\Model\BusTimetable\Entities\Line #1fd2
5 day private => Kdyby\GeneratedProxy\__CG__\App\Model\BusTimetable\Entities\Day #8ae5
6 __initializer__ => Closure #0355
7 file => "/home/vagrant/bus-is/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php" (80)
8 line => 130
9 variables => array (3)
10 entityPersister => Doctrine\ORM\Persisters\Entity\BasicEntityPersister #8335
11 classMetadata => Kdyby\Doctrine\Mapping\ClassMetadata #f3e8
12 wakeupProxy => false
13 parameters => "$proxy" (6)
14 __cloner__ => Closure #f74e
15 file => "/home/vagrant/bus-is/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php" (80)
16 line => 182
17 variables => array (2)
18 entityPersister => Doctrine\ORM\Persisters\Entity\BasicEntityPersister #8335
19 classMetadata => Kdyby\Doctrine\Mapping\ClassMetadata #f3e8
20 parameters => "$proxy" (6)
21 __isInitialized__ => false
22 id private => 1
23 name private => null
24 childBusChoices private => null
25 in .../components/forms/User/EditChildForm.php:103
26
27 App\Model\User\Entities\ChildBusChoice #cdf2
28 id private => 2
29 child private => Kdyby\GeneratedProxy\__CG__\App\Model\User\Entities\Child #58ca
30 line private => Kdyby\GeneratedProxy\__CG__\App\Model\BusTimetable\Entities\Line #6921
31 day private => Kdyby\GeneratedProxy\__CG__\App\Model\BusTimetable\Entities\Day #8ae5
32 __initializer__ => Closure #0355
33 file => "/home/vagrant/bus-is/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php" (80)
34 line => 130
35 variables => array (3)
36 entityPersister => Doctrine\ORM\Persisters\Entity\BasicEntityPersister #8335
37 classMetadata => Kdyby\Doctrine\Mapping\ClassMetadata #f3e8
38 wakeupProxy => false
39 parameters => "$proxy" (6)
40 __cloner__ => Closure #f74e
41 file => "/home/vagrant/bus-is/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php" (80)
42 line => 182
43 variables => array (2)
44 entityPersister => Doctrine\ORM\Persisters\Entity\BasicEntityPersister #8335
45 classMetadata => Kdyby\Doctrine\Mapping\ClassMetadata #f3e8
46 parameters => "$proxy" (6)
47 __isInitialized__ => false
48 id private => 1
49 name private => null
50 childBusChoices private => null
51 in .../components/forms/User/EditChildForm.php:103
52
53 App\Model\User\Entities\ChildBusChoice #e325
54 id private => 3
55 child private => Kdyby\GeneratedProxy\__CG__\App\Model\User\Entities\Child #58ca
56 line private => Kdyby\GeneratedProxy\__CG__\App\Model\BusTimetable\Entities\Line #1fd2
57 day private => Kdyby\GeneratedProxy\__CG__\App\Model\BusTimetable\Entities\Day #2848
58 __initializer__ => Closure #0355
59 file => "/home/vagrant/bus-is/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php" (80)
60 line => 130
61 variables => array (3)
62 entityPersister => Doctrine\ORM\Persisters\Entity\BasicEntityPersister #8335
63 classMetadata => Kdyby\Doctrine\Mapping\ClassMetadata #f3e8
64 wakeupProxy => false
65 parameters => "$proxy" (6)
66 __cloner__ => Closure #f74e
67 file => "/home/vagrant/bus-is/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php" (80)
68 line => 182
69 variables => array (2)
70 entityPersister => Doctrine\ORM\Persisters\Entity\BasicEntityPersister #8335
71 classMetadata => Kdyby\Doctrine\Mapping\ClassMetadata #f3e8
72 parameters => "$proxy" (6)
73 __isInitialized__ => false
74 id private => 3
75 name private => null
76 childBusChoices private => null
77 in .../components/forms/User/EditChildForm.php:103
78
79 App\Model\User\Entities\ChildBusChoice #0ff1
80 id private => 4
81 child private => Kdyby\GeneratedProxy\__CG__\App\Model\User\Entities\Child #58ca
82 line private => Kdyby\GeneratedProxy\__CG__\App\Model\BusTimetable\Entities\Line #1fd2
83 day private => Kdyby\GeneratedProxy\__CG__\App\Model\BusTimetable\Entities\Day #8766
84 __initializer__ => Closure #0355
85 file => "/home/vagrant/bus-is/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php" (80)
86 line => 130
87 variables => array (3)
88 entityPersister => Doctrine\ORM\Persisters\Entity\BasicEntityPersister #8335
89 classMetadata => Kdyby\Doctrine\Mapping\ClassMetadata #f3e8
90 wakeupProxy => false
91 parameters => "$proxy" (6)
92 __cloner__ => Closure #f74e
93 file => "/home/vagrant/bus-is/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php" (80)
94 line => 182
95 variables => array (2)
96 entityPersister => Doctrine\ORM\Persisters\Entity\BasicEntityPersister #8335
97 classMetadata => Kdyby\Doctrine\Mapping\ClassMetadata #f3e8
98 parameters => "$proxy" (6)
99 __isInitialized__ => false
100 id private => 4
101 name private => null
102 childBusChoices private => null
103 in .../components/forms/User/EditChildForm.php:103
104
105 App\Model\User\Entities\ChildBusChoice #0e3f
106 id private => 5
107 child private => Kdyby\GeneratedProxy\__CG__\App\Model\User\Entities\Child #58ca
108 line private => Kdyby\GeneratedProxy\__CG__\App\Model\BusTimetable\Entities\Line #6921
109 day private => Kdyby\GeneratedProxy\__CG__\App\Model\BusTimetable\Entities\Day #8766
110 __initializer__ => Closure #0355
111 file => "/home/vagrant/bus-is/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php" (80)
112 line => 130
113 variables => array (3)
114 entityPersister => Doctrine\ORM\Persisters\Entity\BasicEntityPersister #8335
115 classMetadata => Kdyby\Doctrine\Mapping\ClassMetadata #f3e8
116 wakeupProxy => false
117 parameters => "$proxy" (6)
118 __cloner__ => Closure #f74e
119 file => "/home/vagrant/bus-is/vendor/doctrine/orm/lib/Doctrine/ORM/Proxy/ProxyFactory.php" (80)
120 line => 182
121 variables => array (2)
122 entityPersister => Doctrine\ORM\Persisters\Entity\BasicEntityPersister #8335
123 classMetadata => Kdyby\Doctrine\Mapping\ClassMetadata #f3e8
124 parameters => "$proxy" (6)
125 __isInitialized__ => false
126 id private => 4
127 name private => null
128 childBusChoices private => null
129 in .../components/forms/User/EditChildForm.php:103
130
131 array (7)
132 days1 => array (3)
133 0 => 1
134 1 => 3
135 2 => 4
136 days20 => array (2)
137 0 => 1
138 1 => 4
139 in .../components/forms/User/EditChildForm.php:112
Petr Parolek
Člen | 455
+
0
-

Vyřešeno:

		$qb = $this->userFascade->getQueryBuilder(UserFascade::CHILD_BUS_CHOICES_REPOSITORY, 'c')
			->select('c')
			->where('c.child = :childId')
			->setParameter('childId', $this->id);

		$choices = $qb->getQuery()->getResult();

		foreach ($choices as $choice) {
			$lineId = $choice->getLine()->getId();
			$choices = $this->userFascade->getQueryBuilder(UserFascade::CHILD_BUS_CHOICES_REPOSITORY, 'c')
				->select('c')
				->where('c.line = :lineId')
				->setParameter('lineId', $lineId)
				->getQuery()
				->setHint(\Doctrine\ORM\Query::HINT_INCLUDE_META_COLUMNS, true)
				->getArrayResult();

			$choicesb = [];
			foreach ($choices as $choice) {
				$choicesb[] = $choice['day_id'];
			}

			$this->values['days' . $lineId] = $choicesb;
		}

		$form->setDefaults($this->values);

Akorát nevím, jestli nepokládám zbytečně moc SQL dotazů