Example #1
0
 public function editPostAction($id)
 {
     $urlFrom = $this->getReferer();
     if (null == $urlFrom || trim($urlFrom) == '') {
         return $this->redirect($this->generateUrl('_admin_productdoc_list'));
     }
     $em = $this->getEntityManager();
     try {
         $productdoc = $em->getRepository('AllucoDataBundle:Productdoc')->find($id);
         if (null == $productdoc) {
             $this->flashMsgSession('warning', 'Productdoc.edit.notfound');
         } else {
             $productdocUpdateContentForm = $this->createForm(new ProductdocUpdateContentTForm(), $productdoc);
             $productdocUpdateRankForm = $this->createForm(new ProductdocUpdateRankTForm(), $productdoc);
             $productdocUpdateInfoForm = $this->createForm(new ProductdocUpdateInfoTForm(), $productdoc);
             $productdocUpdateOriginalNameForm = $this->createForm(new ProductdocUpdateOriginalNameTForm(), $productdoc);
             $langs = $em->getRepository('AllucoDataBundle:Lang')->getAll();
             $this->gvars['langs'] = $langs;
             foreach ($langs as $lang) {
                 $productdocTrans = $em->getRepository('AllucoDataBundle:ProductdocTrans')->findOneBy(array('lang' => $lang, 'productdoc' => $productdoc));
                 if (null == $productdocTrans) {
                     $productdocTrans = new ProductdocTrans();
                     $productdocTrans->setProductdoc($productdoc);
                     $productdocTrans->setLang($lang);
                     $productdocTrans->setAlt($productdoc->getAlt());
                     $productdocTrans->setTitle($productdoc->getTitle());
                     try {
                         $em->persist($productdocTrans);
                         $em->flush();
                     } catch (\Exception $e) {
                         // ne rien faire
                     }
                 }
             }
             $em->refresh($productdoc);
             $this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2);
             $this->getSession()->remove('tabActive');
             $request = $this->getRequest();
             $reqData = $request->request->all();
             if (isset($reqData['ProductdocUpdateContentForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $productdocUpdateContentForm->handleRequest($request);
                 if ($productdocUpdateContentForm->isValid()) {
                     $productdocUrl = $productdocUpdateContentForm['filename']->getData();
                     $productdocDir = $this->getParameter('kernel.root_dir') . '/../web/res/docs';
                     $originalName = $productdocUrl->getClientOriginalName();
                     $fileName = sha1(uniqid(mt_rand(), true)) . '.' . strtolower($productdocUrl->getClientOriginalExtension());
                     $mimeType = $productdocUrl->getMimeType();
                     $productdocUrl->move($productdocDir, $fileName);
                     $size = filesize($productdocDir . '/' . $fileName);
                     $md5 = md5_file($productdocDir . '/' . $fileName);
                     $productdoc->setFilename($fileName);
                     $productdoc->setOriginalName($originalName);
                     $productdoc->setSize($size);
                     $productdoc->setMimeType($mimeType);
                     $productdoc->setMd5($md5);
                     $em->persist($productdoc);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Productdoc.edit.success', array('%productdoc%' => $productdoc->getFilename())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($productdoc);
                     $this->flashMsgSession('error', $this->translate('Productdoc.edit.failure', array('%productdoc%' => $productdoc->getFilename())));
                 }
             } elseif (isset($reqData['ProductdocUpdateRankForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $productdocUpdateRankForm->handleRequest($request);
                 if ($productdocUpdateRankForm->isValid()) {
                     $em->persist($productdoc);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Productdoc.edit.success', array('%productdoc%' => $productdoc->getFilename())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($productdoc);
                     $this->flashMsgSession('error', $this->translate('Productdoc.edit.failure', array('%productdoc%' => $productdoc->getFilename())));
                 }
             } elseif (isset($reqData['ProductdocUpdateInfoForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $productdocUpdateInfoForm->handleRequest($request);
                 if ($productdocUpdateInfoForm->isValid()) {
                     $em->persist($productdoc);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Productdoc.edit.success', array('%productdoc%' => $productdoc->getFilename())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($productdoc);
                     $this->flashMsgSession('error', $this->translate('Productdoc.edit.failure', array('%productdoc%' => $productdoc->getFilename())));
                 }
             } elseif (isset($reqData['ProductdocUpdateOriginalNameForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $productdocUpdateOriginalNameForm->handleRequest($request);
                 if ($productdocUpdateOriginalNameForm->isValid()) {
                     $em->persist($productdoc);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Productdoc.edit.success', array('%productdoc%' => $productdoc->getFilename())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($productdoc);
                     $this->flashMsgSession('error', $this->translate('Productdoc.edit.failure', array('%productdoc%' => $productdoc->getFilename())));
                 }
             }
             foreach ($productdoc->getI18ns() as $productdocTrans) {
                 $em->refresh($productdocTrans);
                 $productdocTransUpdateInfoForm = $this->createForm(new ProductdocTransUpdateInfoTForm($productdocTrans->getLang()->getLocale()), $productdocTrans);
                 if (isset($reqData['ProductdocTransUpdateInfoForm_' . $productdocTrans->getLang()->getLocale()])) {
                     $this->gvars['tabActive'] = $productdocTrans->getLang()->getLocale();
                     $this->getSession()->set('tabActive', $productdocTrans->getLang()->getLocale());
                     $productdocTransUpdateInfoForm->handleRequest($request);
                     if ($productdocTransUpdateInfoForm->isValid()) {
                         $em->persist($productdocTrans);
                         $em->flush();
                         $this->flashMsgSession('success', $this->translate('ProductdocTrans.edit.success', array('%productdoc%' => $productdoc->getFilename())));
                         return $this->redirect($urlFrom);
                     } else {
                         $em->refresh($productdoc);
                         $this->flashMsgSession('error', $this->translate('ProductdocTrans.edit.failure', array('%productdoc%' => $productdoc->getFilename())));
                     }
                 }
                 $this->gvars['ProductdocTransUpdateInfoForm'][$productdocTrans->getLang()->getLocale()] = $productdocTransUpdateInfoForm->createView();
             }
             $this->gvars['productdoc'] = $productdoc;
             $this->gvars['ProductdocUpdateContentForm'] = $productdocUpdateContentForm->createView();
             $this->gvars['ProductdocUpdateRankForm'] = $productdocUpdateRankForm->createView();
             $this->gvars['ProductdocUpdateInfoForm'] = $productdocUpdateInfoForm->createView();
             $this->gvars['ProductdocUpdateOriginalNameForm'] = $productdocUpdateOriginalNameForm->createView();
             $this->gvars['pagetitle'] = $this->translate('Pagetitle.productdoc.edit', array('%productdoc%' => $productdoc->getFilename()));
             $this->gvars['pagetitle_txt'] = $this->translate('Pagetitle.productdoc.edit.txt', array('%productdoc%' => $productdoc->getFilename()));
             return $this->renderResponse('AllucoAdminBundle:Productdoc:edit.html.twig', $this->gvars);
         }
     } catch (\Exception $e) {
         $logger = $this->getLogger();
         $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
     }
     return $this->redirect($urlFrom);
 }
Example #2
0
 public function editPostAction($id)
 {
     $urlFrom = $this->getReferer();
     if (null == $urlFrom || trim($urlFrom) == '') {
         return $this->redirect($this->generateUrl('_admin_product_list'));
     }
     $em = $this->getEntityManager();
     try {
         $product = $em->getRepository('AllucoDataBundle:Product')->find($id);
         if (null == $product) {
             $this->flashMsgSession('warning', 'Product.edit.notfound');
         } else {
             $productUpdateForm = $this->createForm(new ProductUpdateTForm(), $product);
             $productUpdatePageUrlForm = $this->createForm(new ProductUpdatePageUrlTForm(), $product);
             $productUpdateThumbForm = $this->createForm(new ProductUpdateThumbTForm(), $product);
             $productUpdateThumbInfoForm = $this->createForm(new ProductUpdateThumbInfoTForm(), $product);
             $productUpdateRankForm = $this->createForm(new ProductUpdateRankTForm(), $product);
             $productUpdateNameForm = $this->createForm(new ProductUpdateNameTForm(), $product);
             $productUpdateParentForm = $this->createForm(new ProductUpdateParentTForm($product->getPageUrlFull()), $product);
             $productpic = new Productpic();
             $productpic->setProduct($product);
             $productpicNewForm = $this->createForm(new ProductpicNewTForm($product), $productpic);
             $productdoc = new Productdoc();
             $productdoc->setProduct($product);
             $productdocNewForm = $this->createForm(new ProductdocNewTForm($product), $productdoc);
             $langs = $em->getRepository('AllucoDataBundle:Lang')->getAll();
             $this->gvars['langs'] = $langs;
             foreach ($langs as $lang) {
                 $productTrans = $em->getRepository('AllucoDataBundle:ProductTrans')->findOneBy(array('lang' => $lang, 'product' => $product));
                 if (null == $productTrans) {
                     $productTrans = new ProductTrans();
                     $productTrans->setLang($lang);
                     $productTrans->setProduct($product);
                     $productTrans->setName($product->getName());
                     $productTrans->setMetaTitle($product->getMetaTitle());
                     $productTrans->setMetaKeywords($product->getMetaKeywords());
                     $productTrans->setMetaDescription($product->getMetaDescription());
                     $productTrans->setPageTitle($product->getPageTitle());
                     $productTrans->setBreadcrumb($product->getBreadcrumb());
                     $productTrans->setPageContent($product->getPageContent());
                     $productTrans->setThumbAlt($product->getThumbAlt());
                     $productTrans->setThumbTitle($product->getThumbTitle());
                     try {
                         $em->persist($productTrans);
                         $em->flush();
                     } catch (\Exception $e) {
                         // ne rien faire
                     }
                 }
             }
             $em->refresh($product);
             $this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2);
             $this->getSession()->remove('tabActive');
             $request = $this->getRequest();
             $reqData = $request->request->all();
             if (isset($reqData['ProductUpdateNameForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $productUpdateNameForm->handleRequest($request);
                 if ($productUpdateNameForm->isValid()) {
                     $em->persist($product);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Product.edit.success', array('%product%' => $product->getName())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($product);
                     $this->flashMsgSession('error', $this->translate('Product.edit.failure', array('%product%' => $product->getName())));
                 }
             } elseif (isset($reqData['ProductUpdatePageUrlForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $productUpdatePageUrlForm->handleRequest($request);
                 if ($productUpdatePageUrlForm->isValid()) {
                     $slug = $this->get('cocur_slugify')->slugify($productUpdatePageUrlForm['pageUrl']->getData(), '_');
                     $foundSlug = false;
                     do {
                         $productTest = $em->getRepository('AllucoDataBundle:Product')->findOneBy(array('pageUrl' => $slug));
                         if (null != $productTest && $productTest->getId() != $product->getId()) {
                             $foundSlug = true;
                             $slug = $slug . '_1';
                         } else {
                             $foundSlug = false;
                         }
                     } while ($foundSlug == true);
                     $product->setPageUrl($slug);
                     $em->persist($product);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Product.edit.success', array('%product%' => $product->getName())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($product);
                     $this->flashMsgSession('error', $this->translate('Product.edit.failure', array('%product%' => $product->getName())));
                 }
             } elseif (isset($reqData['ProductUpdateForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $productUpdateForm->handleRequest($request);
                 if ($productUpdateForm->isValid()) {
                     $em->persist($product);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Product.edit.success', array('%product%' => $product->getName())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($product);
                     $this->flashMsgSession('error', $this->translate('Product.edit.failure', array('%product%' => $product->getName())));
                 }
             } elseif (isset($reqData['ProductUpdateThumbForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $productUpdateThumbForm->handleRequest($request);
                 if ($productUpdateThumbForm->isValid()) {
                     $productUrl = $productUpdateThumbForm['thumb']->getData();
                     $productDir = $this->getParameter('kernel.root_dir') . '/../web/res/prods';
                     $fileName = sha1(uniqid(mt_rand(), true)) . '.' . strtolower($productUrl->getClientOriginalExtension());
                     $productUrl->move($productDir, $fileName);
                     $product->setThumb($fileName);
                     $em->persist($product);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Product.edit.success', array('%product%' => $product->getName())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($product);
                     $this->flashMsgSession('error', $this->translate('Product.edit.failure', array('%product%' => $product->getName())));
                 }
             } elseif (isset($reqData['ProductUpdateThumbInfoForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $productUpdateThumbInfoForm->handleRequest($request);
                 if ($productUpdateThumbInfoForm->isValid()) {
                     $em->persist($product);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Product.edit.success', array('%product%' => $product->getName())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($product);
                     $this->flashMsgSession('error', $this->translate('Product.edit.failure', array('%product%' => $product->getName())));
                 }
             } elseif (isset($reqData['ProductUpdateRankForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $productUpdateRankForm->handleRequest($request);
                 if ($productUpdateRankForm->isValid()) {
                     $em->persist($product);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Product.edit.success', array('%product%' => $product->getName())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($product);
                     $this->flashMsgSession('error', $this->translate('Product.edit.failure', array('%product%' => $product->getName())));
                 }
             } elseif (isset($reqData['ProductpicNewForm'])) {
                 $this->gvars['tabActive'] = 3;
                 $this->getSession()->set('tabActive', 3);
                 $productpicNewForm->handleRequest($request);
                 if ($productpicNewForm->isValid()) {
                     $productpicUrl = $productpicNewForm['filename']->getData();
                     $productpicDir = $this->getParameter('kernel.root_dir') . '/../web/res/pics';
                     $fileName = sha1(uniqid(mt_rand(), true)) . '.' . strtolower($productpicUrl->getClientOriginalExtension());
                     $productpicUrl->move($productpicDir, $fileName);
                     $productpic->setFilename($fileName);
                     $em->persist($productpic);
                     $em->flush();
                     foreach ($langs as $lang) {
                         $productpicTrans = new ProductpicTrans();
                         $productpicTrans->setLang($lang);
                         $productpicTrans->setProductpic($productpic);
                         $productpicTrans->setAlt($productpic->getAlt());
                         $productpicTrans->setTitle($productpic->getTitle());
                         try {
                             $em->persist($productpicTrans);
                             $em->flush();
                         } catch (\Exception $e) {
                             // ne rien faire
                         }
                     }
                     $this->flashMsgSession('success', $this->translate('Productpic.add.success', array('%productpic%' => $productpic->getFilename())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($product);
                     $this->flashMsgSession('error', $this->translate('Product.edit.failure', array('%product%' => $product->getName())));
                 }
             } elseif (isset($reqData['ProductdocNewForm'])) {
                 $this->gvars['tabActive'] = 4;
                 $this->getSession()->set('tabActive', 4);
                 $productdocNewForm->handleRequest($request);
                 if ($productdocNewForm->isValid()) {
                     $productdocUrl = $productdocNewForm['filename']->getData();
                     $productdocDir = $this->getParameter('kernel.root_dir') . '/../web/res/docs';
                     $originalName = $productdocUrl->getClientOriginalName();
                     $fileName = sha1(uniqid(mt_rand(), true)) . '.' . strtolower($productdocUrl->getClientOriginalExtension());
                     $mimeType = $productdocUrl->getMimeType();
                     $productdocUrl->move($productdocDir, $fileName);
                     $size = filesize($productdocDir . '/' . $fileName);
                     $md5 = md5_file($productdocDir . '/' . $fileName);
                     $productdoc->setFilename($fileName);
                     $productdoc->setOriginalName($originalName);
                     $productdoc->setSize($size);
                     $productdoc->setMimeType($mimeType);
                     $productdoc->setMd5($md5);
                     $em->persist($productdoc);
                     $em->flush();
                     foreach ($langs as $lang) {
                         $productdocTrans = new ProductdocTrans();
                         $productdocTrans->setLang($lang);
                         $productdocTrans->setProductdoc($productdoc);
                         $productdocTrans->setTitle($productdoc->getTitle());
                         try {
                             $em->persist($productdocTrans);
                             $em->flush();
                         } catch (\Exception $ex) {
                             // ne rien faire
                         }
                     }
                     $this->flashMsgSession('success', $this->translate('Productdoc.add.success', array('%productdoc%' => $productdoc->getFilename())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($product);
                     $this->flashMsgSession('error', $this->translate('Product.edit.failure', array('%product%' => $product->getName())));
                 }
             } elseif (isset($reqData['ProductUpdateParentForm'])) {
                 $this->gvars['tabActive'] = 2;
                 $this->getSession()->set('tabActive', 2);
                 $productUpdateParentForm->handleRequest($request);
                 if ($productUpdateParentForm->isValid()) {
                     $em->persist($product);
                     $em->flush();
                     $this->flashMsgSession('success', $this->translate('Product.edit.success', array('%product%' => $product->getName())));
                     return $this->redirect($urlFrom);
                 } else {
                     $em->refresh($product);
                     $this->flashMsgSession('error', $this->translate('Product.edit.failure', array('%product%' => $product->getName())));
                 }
             }
             //*/
             foreach ($product->getI18ns() as $productTrans) {
                 $em->refresh($productTrans);
                 $productTransUpdateNameForm = $this->createForm(new ProductTransUpdateNameTForm($productTrans->getLang()->getLocale()), $productTrans);
                 $productTransUpdateForm = $this->createForm(new ProductTransUpdateTForm($productTrans->getLang()->getLocale()), $productTrans);
                 $productTransUpdateThumbInfoForm = $this->createForm(new ProductTransUpdateThumbInfoTForm($productTrans->getLang()->getLocale()), $productTrans);
                 if (isset($reqData['ProductTransUpdateForm_' . $productTrans->getLang()->getLocale()])) {
                     $this->gvars['tabActive'] = $productTrans->getLang()->getLocale();
                     $this->getSession()->set('tabActive', $productTrans->getLang()->getLocale());
                     $productTransUpdateForm->handleRequest($request);
                     if ($productTransUpdateForm->isValid()) {
                         $em->persist($productTrans);
                         $em->flush();
                         $this->flashMsgSession('success', $this->translate('ProductTrans.edit.success', array('%product%' => $product->getName())));
                         return $this->redirect($urlFrom);
                     } else {
                         $em->refresh($product);
                         $this->flashMsgSession('error', $this->translate('ProductTrans.edit.failure', array('%product%' => $product->getName())));
                     }
                 } elseif (isset($reqData['ProductTransUpdateThumbInfoForm_' . $productTrans->getLang()->getLocale()])) {
                     $this->gvars['tabActive'] = $productTrans->getLang()->getLocale();
                     $this->getSession()->set('tabActive', $productTrans->getLang()->getLocale());
                     $productTransUpdateThumbInfoForm->handleRequest($request);
                     if ($productTransUpdateThumbInfoForm->isValid()) {
                         $em->persist($productTrans);
                         $em->flush();
                         $this->flashMsgSession('success', $this->translate('ProductTrans.edit.success', array('%product%' => $product->getName())));
                         return $this->redirect($urlFrom);
                     } else {
                         $em->refresh($product);
                         $this->flashMsgSession('error', $this->translate('ProductTrans.edit.failure', array('%product%' => $product->getName())));
                     }
                 } elseif (isset($reqData['ProductTransUpdateNameForm_' . $productTrans->getLang()->getLocale()])) {
                     $this->gvars['tabActive'] = $productTrans->getLang()->getLocale();
                     $this->getSession()->set('tabActive', $productTrans->getLang()->getLocale());
                     $productTransUpdateNameForm->handleRequest($request);
                     if ($productTransUpdateNameForm->isValid()) {
                         $em->persist($productTrans);
                         $em->flush();
                         $this->flashMsgSession('success', $this->translate('ProductTrans.edit.success', array('%product%' => $product->getName())));
                         return $this->redirect($urlFrom);
                     } else {
                         $em->refresh($product);
                         $this->flashMsgSession('error', $this->translate('ProductTrans.edit.failure', array('%product%' => $product->getName())));
                     }
                 }
                 $this->gvars['ProductTransUpdateNameForm'][$productTrans->getLang()->getLocale()] = $productTransUpdateNameForm->createView();
                 $this->gvars['ProductTransUpdateForm'][$productTrans->getLang()->getLocale()] = $productTransUpdateForm->createView();
                 $this->gvars['ProductTransUpdateThumbInfoForm'][$productTrans->getLang()->getLocale()] = $productTransUpdateThumbInfoForm->createView();
             }
             $this->gvars['product'] = $product;
             $this->gvars['ProductUpdateForm'] = $productUpdateForm->createView();
             $this->gvars['ProductUpdatePageUrlForm'] = $productUpdatePageUrlForm->createView();
             $this->gvars['ProductUpdateThumbForm'] = $productUpdateThumbForm->createView();
             $this->gvars['ProductUpdateThumbInfoForm'] = $productUpdateThumbInfoForm->createView();
             $this->gvars['ProductUpdateRankForm'] = $productUpdateRankForm->createView();
             $this->gvars['ProductUpdateNameForm'] = $productUpdateNameForm->createView();
             $this->gvars['ProductpicNewForm'] = $productpicNewForm->createView();
             $this->gvars['ProductdocNewForm'] = $productdocNewForm->createView();
             $this->gvars['ProductUpdateParentForm'] = $productUpdateParentForm->createView();
             $this->gvars['pagetitle'] = $this->translate('Pagetitle.product.edit', array('%product%' => $product->getName()));
             $this->gvars['pagetitle_txt'] = $this->translate('Pagetitle.product.edit.txt', array('%product%' => $product->getName()));
             return $this->renderResponse('AllucoAdminBundle:Product:edit.html.twig', $this->gvars);
         }
     } catch (\Exception $e) {
         $logger = $this->getLogger();
         $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString());
     }
     return $this->redirect($urlFrom);
 }
Example #3
0
 public function addPostAction()
 {
     $urlFrom = $this->getReferer();
     if (null == $urlFrom || trim($urlFrom) == '') {
         return $this->redirect($this->generateUrl('_admin_lang_addGet'));
     }
     $lang = new Lang();
     $langNewForm = $this->createForm(new LangNewTForm(), $lang);
     $request = $this->getRequest();
     $reqData = $request->request->all();
     if (isset($reqData['LangNewForm'])) {
         $langNewForm->handleRequest($request);
         if ($langNewForm->isValid()) {
             $em = $this->getEntityManager();
             $em->persist($lang);
             $em->flush();
             $jobs = $em->getRepository('AllucoDataBundle:Job')->getAll();
             foreach ($jobs as $job) {
                 $jobTrans = new JobTrans();
                 $jobTrans->setLang($lang);
                 $jobTrans->setJob($job);
                 $jobTrans->setName($job->getName());
                 $em->persist($jobTrans);
             }
             $banners = $em->getRepository('AllucoDataBundle:Banner')->getAll();
             foreach ($banners as $banner) {
                 $bannerTrans = new BannerTrans();
                 $bannerTrans->setLang($lang);
                 $bannerTrans->setBanner($banner);
                 $bannerTrans->setAlt($banner->getAlt());
                 $bannerTrans->setTitle($banner->getTitle());
                 $em->persist($bannerTrans);
             }
             $certifs = $em->getRepository('AllucoDataBundle:Certif')->getAll();
             foreach ($certifs as $certif) {
                 $certifTrans = new CertifTrans();
                 $certifTrans->setLang($lang);
                 $certifTrans->setCertif($certif);
                 $certifTrans->setTitle($certif->getTitle());
                 $em->persist($certifTrans);
             }
             $staticpages = $em->getRepository('AllucoDataBundle:Staticpage')->getAll();
             foreach ($staticpages as $staticpage) {
                 $staticpageTrans = new StaticpageTrans();
                 $staticpageTrans->setLang($lang);
                 $staticpageTrans->setStaticpage($staticpage);
                 $staticpageTrans->setMetaTitle($staticpage->getMetaTitle());
                 $staticpageTrans->setMetaKeywords($staticpage->getMetaKeywords());
                 $staticpageTrans->setMetaDescription($staticpage->getMetaDescription());
                 $staticpageTrans->setPageTitle($staticpage->getPageTitle());
                 $staticpageTrans->setBreadcrumb($staticpage->getBreadcrumb());
                 $staticpageTrans->setPageContent($staticpage->getPageContent());
                 $em->persist($staticpageTrans);
             }
             $sitenews = $em->getRepository('AllucoDataBundle:Sitenew')->getAll();
             foreach ($sitenews as $sitenew) {
                 $sitenewTrans = new SitenewTrans();
                 $sitenewTrans->setLang($lang);
                 $sitenewTrans->setSitenew($sitenew);
                 $sitenewTrans->setMetaTitle($sitenew->getMetaTitle());
                 $sitenewTrans->setMetaKeywords($sitenew->getMetaKeywords());
                 $sitenewTrans->setMetaDescription($sitenew->getMetaDescription());
                 $sitenewTrans->setPageTitle($sitenew->getPageTitle());
                 $sitenewTrans->setBreadcrumb($sitenew->getBreadcrumb());
                 $sitenewTrans->setPageContent($sitenew->getPageContent());
                 $sitenewTrans->setThumbAlt($sitenew->getThumbAlt());
                 $sitenewTrans->setThumbTitle($sitenew->getThumbTitle());
                 $em->persist($sitenewTrans);
             }
             $products = $em->getRepository('AllucoDataBundle:Product')->getAll();
             foreach ($products as $product) {
                 $productTrans = new ProductTrans();
                 $productTrans->setLang($lang);
                 $productTrans->setProduct($product);
                 $productTrans->setName($product->getName());
                 $productTrans->setMetaTitle($product->getMetaTitle());
                 $productTrans->setMetaKeywords($product->getMetaKeywords());
                 $productTrans->setMetaDescription($product->getMetaDescription());
                 $productTrans->setPageTitle($product->getPageTitle());
                 $productTrans->setBreadcrumb($product->getBreadcrumb());
                 $productTrans->setPageContent($product->getPageContent());
                 $productTrans->setThumbAlt($product->getThumbAlt());
                 $productTrans->setThumbTitle($product->getThumbTitle());
                 $em->persist($productTrans);
             }
             $productpics = $em->getRepository('AllucoDataBundle:Productpic')->getAll();
             foreach ($productpics as $productpic) {
                 $productpicTrans = new ProductpicTrans();
                 $productpicTrans->setLang($lang);
                 $productpicTrans->setProductpic($productpic);
                 $productpicTrans->setAlt($productpic->getAlt());
                 $productpicTrans->setTitle($productpic->getTitle());
                 $em->persist($productpicTrans);
             }
             $productdocs = $em->getRepository('AllucoDataBundle:Productdoc')->getAll();
             foreach ($productdocs as $productdoc) {
                 $productdocTrans = new ProductdocTrans();
                 $productdocTrans->setLang($lang);
                 $productdocTrans->setProductdoc($productdoc);
                 $productdocTrans->setTitle($productdoc->getTitle());
                 $em->persist($productdocTrans);
             }
             $em->flush();
             $this->flashMsgSession('success', $this->translate('Lang.add.success', array('%lang%' => $lang->getName())));
             return $this->redirect($this->generateUrl('_admin_lang_editGet', array('id' => $lang->getId())));
         } else {
             $this->flashMsgSession('error', $this->translate('Lang.add.failure', array('%lang%' => $langNewForm['locale']->getData())));
         }
     }
     $this->gvars['lang'] = $lang;
     $this->gvars['LangNewForm'] = $langNewForm->createView();
     $this->gvars['pagetitle'] = $this->translate('Pagetitle.lang.add');
     $this->gvars['pagetitle_txt'] = $this->translate('Pagetitle.lang.add.txt');
     $this->gvars['smenu_active'] = 'add';
     return $this->renderResponse('AllucoAdminBundle:Lang:add.html.twig', $this->gvars);
 }