Exemplo n.º 1
0
 private function menuArrayToEntities($menuArray, \Doctrine\ORM\EntityManager $em, MenuElement $parent = null, $locale)
 {
     $collection = new \Doctrine\Common\Collections\ArrayCollection();
     $repo = $em->getRepository('SKCMSCoreBundle:MenuElement');
     $repo->setDefaultLocale($locale);
     foreach ($menuArray as $menuElement) {
         //            //dump($menuElement);
         //            die();
         $element = null;
         if (isset($menuElement->elementId)) {
             $element = $repo->find($menuElement->elementId);
             $element->setTranslatableLocale($locale);
             $em->refresh($element);
         }
         if (null === $element) {
             $element = new MenuElement();
         }
         $element->setName($menuElement->name);
         $element->setEntityId($menuElement->targetId);
         $element->setEntityClass($menuElement->entityClass);
         $element->setPosition($menuElement->position);
         if (isset($menuElement->children) && count($menuElement->children)) {
             $element->setChildren($this->menuArrayToEntities($menuElement->children, $em, $element, $locale));
         }
         $collection->add($element);
         if (null !== $parent) {
             $element->setParent($parent);
         }
         $em->persist($element);
     }
     return $collection;
 }