@@ 58-99 (lines=42) @@ | ||
55 | } |
|
56 | } |
|
57 | ||
58 | class CustomTreeWalkerJoin extends Query\TreeWalkerAdapter |
|
59 | { |
|
60 | public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) |
|
61 | { |
|
62 | foreach ($selectStatement->fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) { |
|
63 | $rangeVariableDecl = $identificationVariableDeclaration->rangeVariableDeclaration; |
|
64 | ||
65 | if ($rangeVariableDecl->abstractSchemaName !== CmsUser::class) { |
|
66 | continue; |
|
67 | } |
|
68 | ||
69 | $this->modifySelectStatement($selectStatement, $identificationVariableDeclaration); |
|
70 | } |
|
71 | } |
|
72 | ||
73 | private function modifySelectStatement(Query\AST\SelectStatement $selectStatement, $identificationVariableDecl) |
|
74 | { |
|
75 | $rangeVariableDecl = $identificationVariableDecl->rangeVariableDeclaration; |
|
76 | $joinAssocPathExpression = new Query\AST\JoinAssociationPathExpression($rangeVariableDecl->aliasIdentificationVariable, 'address'); |
|
77 | $joinAssocDeclaration = new Query\AST\JoinAssociationDeclaration($joinAssocPathExpression, $rangeVariableDecl->aliasIdentificationVariable . 'a', null); |
|
78 | $join = new Query\AST\Join(Query\AST\Join::JOIN_TYPE_LEFT, $joinAssocDeclaration); |
|
79 | $selectExpression = new Query\AST\SelectExpression($rangeVariableDecl->aliasIdentificationVariable . 'a', null, false); |
|
80 | ||
81 | $identificationVariableDecl->joins[] = $join; |
|
82 | $selectStatement->selectClause->selectExpressions[] = $selectExpression; |
|
83 | ||
84 | $entityManager = $this->_getQuery()->getEntityManager(); |
|
85 | $userMetadata = $entityManager->getClassMetadata(CmsUser::class); |
|
86 | $addressMetadata = $entityManager->getClassMetadata(CmsAddress::class); |
|
87 | ||
88 | $this->setQueryComponent($rangeVariableDecl->aliasIdentificationVariable . 'a', |
|
89 | [ |
|
90 | 'metadata' => $addressMetadata, |
|
91 | 'parent' => $rangeVariableDecl->aliasIdentificationVariable, |
|
92 | 'relation' => $userMetadata->getAssociationMapping('address'), |
|
93 | 'map' => null, |
|
94 | 'nestingLevel' => 0, |
|
95 | 'token' => null, |
|
96 | ] |
|
97 | ); |
|
98 | } |
|
99 | } |
|
100 |
@@ 185-226 (lines=42) @@ | ||
182 | } |
|
183 | } |
|
184 | ||
185 | class CustomTreeWalkerJoin extends Query\TreeWalkerAdapter |
|
186 | { |
|
187 | public function walkSelectStatement(Query\AST\SelectStatement $selectStatement) |
|
188 | { |
|
189 | foreach ($selectStatement->fromClause->identificationVariableDeclarations as $identificationVariableDeclaration) { |
|
190 | $rangeVariableDecl = $identificationVariableDeclaration->rangeVariableDeclaration; |
|
191 | ||
192 | if ($rangeVariableDecl->abstractSchemaName !== CmsUser::class) { |
|
193 | continue; |
|
194 | } |
|
195 | ||
196 | $this->modifySelectStatement($selectStatement, $identificationVariableDeclaration); |
|
197 | } |
|
198 | } |
|
199 | ||
200 | private function modifySelectStatement(Query\AST\SelectStatement $selectStatement, $identificationVariableDecl) |
|
201 | { |
|
202 | $rangeVariableDecl = $identificationVariableDecl->rangeVariableDeclaration; |
|
203 | $joinAssocPathExpression = new Query\AST\JoinAssociationPathExpression($rangeVariableDecl->aliasIdentificationVariable, 'address'); |
|
204 | $joinAssocDeclaration = new Query\AST\JoinAssociationDeclaration($joinAssocPathExpression, $rangeVariableDecl->aliasIdentificationVariable . 'a', null); |
|
205 | $join = new Query\AST\Join(Query\AST\Join::JOIN_TYPE_LEFT, $joinAssocDeclaration); |
|
206 | $selectExpression = new Query\AST\SelectExpression($rangeVariableDecl->aliasIdentificationVariable . 'a', null, false); |
|
207 | ||
208 | $identificationVariableDecl->joins[] = $join; |
|
209 | $selectStatement->selectClause->selectExpressions[] = $selectExpression; |
|
210 | ||
211 | $entityManager = $this->_getQuery()->getEntityManager(); |
|
212 | $userMetadata = $entityManager->getClassMetadata(CmsUser::class); |
|
213 | $addressMetadata = $entityManager->getClassMetadata(CmsAddress::class); |
|
214 | ||
215 | $this->setQueryComponent($rangeVariableDecl->aliasIdentificationVariable . 'a', |
|
216 | [ |
|
217 | 'metadata' => $addressMetadata, |
|
218 | 'parent' => $rangeVariableDecl->aliasIdentificationVariable, |
|
219 | 'relation' => $userMetadata->getAssociationMapping('address'), |
|
220 | 'map' => null, |
|
221 | 'nestingLevel' => 0, |
|
222 | 'token' => null, |
|
223 | ] |
|
224 | ); |
|
225 | } |
|
226 | } |
|
227 |