Bundle/WidgetMapBundle/Warmer/WidgetDataWarmer.php
private function setAssociatedEntities(array $repositories)
    {
        $newEntities = [];

        foreach ($repositories as $repositoryName => $findMethods) {
            foreach ($findMethods as $findMethod => $groupedBySortAssociatedEntitiesToWarm) {
                foreach ($groupedBySortAssociatedEntitiesToWarm as $orderByToken => $groupedAssociatedEntitiesToWarm) {
                    $associatedEntitiesToWarm = $groupedAssociatedEntitiesToWarm['entitiesToWarm'];

                    //Extract ids to search
                    $idsToSearch = array_map(function ($associatedEntityToWarm) {
                        return $associatedEntityToWarm->getEntityId();
                    }, $associatedEntitiesToWarm);

                    $orderBy = [];
                    if ($orderByToken !== 'unsorted') {
                        foreach ($groupedAssociatedEntitiesToWarm['orderBy'] as $orderAttribut => $order) {
                            $orderBy[$orderAttribut] = $order;
                        }
                    }

                    //Find by id for ManyToOne associations based on target entity id
                    //Find by mappedBy value for OneToMany associations based on owner entity id
                    $foundEntities = $this->em->getRepository($repositoryName)->findBy([
                        $findMethod => array_values($idsToSearch),
                    ], $orderBy);

                    /* @var AssociatedEntityToWarm[] $associatedEntitiesToWarm */
                    foreach ($associatedEntitiesToWarm as $associatedEntityToWarm) {
                        foreach ($foundEntities as $foundEntity) {
                            if ($associatedEntityToWarm->getType() === AssociatedEntityToWarm::TYPE_MANY_TO_ONE
                                && $foundEntity->getId() === $associatedEntityToWarm->getEntityId()
                            ) {
                                $inheritorEntity = $associatedEntityToWarm->getInheritorEntity();
                                $inheritorPropertyName = $associatedEntityToWarm->getInheritorPropertyName();
                                $this->accessor->setValue($inheritorEntity, $inheritorPropertyName, $foundEntity);
                                continue;
                            } elseif ($associatedEntityToWarm->getType() === AssociatedEntityToWarm::TYPE_ONE_TO_MANY
                                && $this->accessor->getValue($foundEntity, $findMethod) === $associatedEntityToWarm->getInheritorEntity()
                            ) {
                                $inheritorEntity = $associatedEntityToWarm->getInheritorEntity();
                                $inheritorPropertyName = $associatedEntityToWarm->getInheritorPropertyName();

                                //Don't use Collection getter directly and override Collection
                                //default behaviour to avoid useless query
                                $getter = 'get'.ucwords($inheritorPropertyName);
                                $inheritorEntity->$getter()->add($foundEntity);
                                $inheritorEntity->$getter()->setDirty(false);
                                $inheritorEntity->$getter()->setInitialized(true);

                                //Store new entities to warm if necessary
                                $newEntities[] = $foundEntity;
                                continue;
                            }
                        }
                    }
                }
            }
        }

        return $newEntities;
    }
private function setAssociatedEntities(array $repositories)
    {
        $newEntities = [];

        foreach ($repositories as $repositoryName => $findMethods) {
            foreach ($findMethods as $findMethod => $groupedBySortAssociatedEntitiesToWarm) {
                foreach ($groupedBySortAssociatedEntitiesToWarm as $orderByToken => $groupedAssociatedEntitiesToWarm) {
                    $associatedEntitiesToWarm = $groupedAssociatedEntitiesToWarm['entitiesToWarm'];

                    //Extract ids to search
                    $idsToSearch = array_map(function ($associatedEntityToWarm) {
                        return $associatedEntityToWarm->getEntityId();
                    }, $associatedEntitiesToWarm);

                    $orderBy = [];
                    if ($orderByToken !== 'unsorted') {
                        foreach ($groupedAssociatedEntitiesToWarm['orderBy'] as $orderAttribut => $order) {
                            $orderBy[$orderAttribut] = $order;
                        }
                    }

                    //Find by id for ManyToOne associations based on target entity id
                    //Find by mappedBy value for OneToMany associations based on owner entity id
                    $foundEntities = $this->em->getRepository($repositoryName)->findBy([
                        $findMethod => array_values($idsToSearch),
                    ], $orderBy);

                    /* @var AssociatedEntityToWarm[] $associatedEntitiesToWarm */
                    foreach ($associatedEntitiesToWarm as $associatedEntityToWarm) {
                        foreach ($foundEntities as $foundEntity) {
                            if ($associatedEntityToWarm->getType() === AssociatedEntityToWarm::TYPE_MANY_TO_ONE
                                && $foundEntity->getId() === $associatedEntityToWarm->getEntityId()
                            ) {
                                $inheritorEntity = $associatedEntityToWarm->getInheritorEntity();
                                $inheritorPropertyName = $associatedEntityToWarm->getInheritorPropertyName();
                                $this->accessor->setValue($inheritorEntity, $inheritorPropertyName, $foundEntity);
                                continue;
                            } elseif ($associatedEntityToWarm->getType() === AssociatedEntityToWarm::TYPE_ONE_TO_MANY
                                && $this->accessor->getValue($foundEntity, $findMethod) === $associatedEntityToWarm->getInheritorEntity()
                            ) {
                                $inheritorEntity = $associatedEntityToWarm->getInheritorEntity();
                                $inheritorPropertyName = $associatedEntityToWarm->getInheritorPropertyName();

                                //Don't use Collection getter directly and override Collection
                                //default behaviour to avoid useless query
                                $getter = 'get'.ucwords($inheritorPropertyName);
                                $inheritorEntity->$getter()->add($foundEntity);
                                $inheritorEntity->$getter()->setDirty(false);
                                $inheritorEntity->$getter()->setInitialized(true);

                                //Store new entities to warm if necessary
                                $newEntities[] = $foundEntity;
                                continue;
                            }
                        }
                    }
                }
            }
        }

        return $newEntities;
    }
private function setAssociatedEntities ( array $ repositories ) { $ newEntities = [ ] ; foreach ( $ repositories as $ repositoryName => $ findMethods ) { foreach ( $ findMethods as $ findMethod => $ groupedBySortAssociatedEntitiesToWarm ) { foreach ( $ groupedBySortAssociatedEntitiesToWarm as $ orderByToken => $ groupedAssociatedEntitiesToWarm ) { $ associatedEntitiesToWarm = $ groupedAssociatedEntitiesToWarm [ 'entitiesToWarm' ] ; //Extract ids to search $ idsToSearch = array_map ( function ( $ associatedEntityToWarm ) { return $ associatedEntityToWarm -> getEntityId ( ) ; } , $ associatedEntitiesToWarm ) ; $ orderBy = [ ] ; if ( $ orderByToken !== 'unsorted' ) { foreach ( $ groupedAssociatedEntitiesToWarm [ 'orderBy' ] as $ orderAttribut => $ order ) { $ orderBy [ $ orderAttribut ] = $ order ; } } //Find by id for ManyToOne associations based on target entity id //Find by mappedBy value for OneToMany associations based on owner entity id $ foundEntities = $ this -> em -> getRepository ( $ repositoryName ) -> findBy ( [ $ findMethod => array_values ( $ idsToSearch ) , ] , $ orderBy ) ; /* @var AssociatedEntityToWarm[] $associatedEntitiesToWarm */ foreach ( $ associatedEntitiesToWarm as $ associatedEntityToWarm ) { foreach ( $ foundEntities as $ foundEntity ) { if ( $ associatedEntityToWarm -> getType ( ) === AssociatedEntityToWarm :: TYPE_MANY_TO_ONE && $ foundEntity -> getId ( ) === $ associatedEntityToWarm -> getEntityId ( ) ) { $ inheritorEntity = $ associatedEntityToWarm -> getInheritorEntity ( ) ; $ inheritorPropertyName = $ associatedEntityToWarm -> getInheritorPropertyName ( ) ; $ this -> accessor -> setValue ( $ inheritorEntity , $ inheritorPropertyName , $ foundEntity ) ; continue ; } elseif ( $ associatedEntityToWarm -> getType ( ) === AssociatedEntityToWarm :: TYPE_ONE_TO_MANY && $ this -> accessor -> getValue ( $ foundEntity , $ findMethod ) === $ associatedEntityToWarm -> getInheritorEntity ( ) ) { $ inheritorEntity = $ associatedEntityToWarm -> getInheritorEntity ( ) ; $ inheritorPropertyName = $ associatedEntityToWarm -> getInheritorPropertyName ( ) ; //Don't use Collection getter directly and override Collection //default behaviour to avoid useless query $ getter = 'get' . ucwords ( $ inheritorPropertyName ) ; $ inheritorEntity -> $ getter ( ) -> add ( $ foundEntity ) ; $ inheritorEntity -> $ getter ( ) -> setDirty ( false ) ; $ inheritorEntity -> $ getter ( ) -> setInitialized ( true ) ; //Store new entities to warm if necessary $ newEntities [ ] = $ foundEntity ; continue ; } } } } } } return $ newEntities ; }
Set all missing associated entities.

@param array $repositories

@throws \Throwable
@throws \TypeError

@return array
Set all missing associated entities .