Exemplo n.º 1
0
 /**
  * @param array $entityIds
  * @param array $mapping
  * @param array $config
  *
  * @return array
  */
 protected function loadRelatedItems($entityIds, $mapping, $config)
 {
     $entityClass = $mapping['targetEntity'];
     $bindings = $this->getRelatedItemsBindings($entityIds, $mapping, $config);
     $qb = $this->doctrineHelper->getEntityRepository($entityClass)->createQueryBuilder('r')->where(sprintf('r.%s IN (:ids)', $this->getEntityIdFieldName($entityClass)))->setParameter('ids', $this->getRelatedItemsIds($bindings));
     $this->prepareQuery($qb, $config);
     $data = $this->getQuery($qb, $config)->getResult();
     $result = [];
     if (!empty($data)) {
         $items = $this->serializeEntities((array) $data, $entityClass, $config, true);
         foreach ($bindings as $entityId => $relatedEntityIds) {
             foreach ($relatedEntityIds as $relatedEntityId) {
                 if (isset($items[$relatedEntityId])) {
                     $result[$entityId][] = $items[$relatedEntityId];
                 }
             }
         }
     }
     return $result;
 }