コード例 #1
0
 /**
  * Make sure the menu objects exist in the database for each locale.
  */
 public function makeSureMenusExist()
 {
     $locales = array_unique($this->getLocales());
     $required = array();
     foreach ($this->menuNames as $name) {
         $required[$name] = $locales;
     }
     $menuObjects = $this->em->getRepository('KunstmaanMenuBundle:Menu')->findAll();
     foreach ($menuObjects as $menu) {
         if (array_key_exists($menu->getName(), $required)) {
             $index = array_search($menu->getLocale(), $required[$menu->getName()]);
             if ($index !== false) {
                 unset($required[$menu->getName()][$index]);
             }
         }
     }
     foreach ($required as $name => $locales) {
         foreach ($locales as $locale) {
             $menu = new Menu();
             $menu->setName($name);
             $menu->setLocale($locale);
             $this->em->persist($menu);
         }
     }
     $this->em->flush();
 }
コード例 #2
0
 /**
  * Make sure the menu objects exist in the database for each locale.
  */
 private function makeSureMenusExist()
 {
     $menuNames = $this->container->getParameter('kunstmaan_menu.menus');
     $locales = explode('|', $this->container->getParameter('requiredlocales'));
     $required = array();
     foreach ($menuNames as $name) {
         $required[$name] = $locales;
     }
     $em = $this->getDoctrine()->getManager();
     $menuObjects = $em->getRepository('KunstmaanMenuBundle:Menu')->findAll();
     foreach ($menuObjects as $menu) {
         if (array_key_exists($menu->getName(), $required)) {
             $index = array_search($menu->getLocale(), $required[$menu->getName()]);
             if ($index !== false) {
                 unset($required[$menu->getName()][$index]);
             }
         }
     }
     foreach ($required as $name => $locales) {
         foreach ($locales as $locale) {
             $menu = new Menu();
             $menu->setName($name);
             $menu->setLocale($locale);
             $em->persist($menu);
         }
     }
     $em->flush();
 }