public function editPostAction($id) { $urlFrom = $this->getReferer(); if (null == $urlFrom || trim($urlFrom) == '') { return $this->redirect($this->generateUrl('_admin_staticpage_list')); } $em = $this->getEntityManager(); try { $staticpage = $em->getRepository('AllucoDataBundle:Staticpage')->find($id); if (null == $staticpage) { $this->flashMsgSession('warning', 'Staticpage.edit.notfound'); } else { $staticpageUpdateForm = $this->createForm(new StaticpageUpdateTForm(), $staticpage); $langs = $em->getRepository('AllucoDataBundle:Lang')->getAll(); $this->gvars['langs'] = $langs; foreach ($langs as $lang) { $staticpageTrans = $em->getRepository('AllucoDataBundle:StaticpageTrans')->findOneBy(array('lang' => $lang, 'staticpage' => $staticpage)); if (null == $staticpageTrans) { $staticpageTrans = new StaticpageTrans(); $staticpageTrans->setLang($lang); $staticpageTrans->setStaticpage($staticpage); $staticpageTrans->setMetaKeywords($staticpage->getMetaKeywords()); $staticpageTrans->setMetaDescription($staticpage->getMetaDescription()); $staticpageTrans->setPageTitle($staticpage->getPageTitle()); $staticpageTrans->setBreadcrumb($staticpage->getBreadcrumb()); $staticpageTrans->setPageContent($staticpage->getPageContent()); try { $em->persist($staticpageTrans); $em->flush(); } catch (\Exception $e) { // ne rien faire } } } $em->refresh($staticpage); $this->gvars['tabActive'] = $this->getSession()->get('tabActive', 2); $this->getSession()->remove('tabActive'); $request = $this->getRequest(); $reqData = $request->request->all(); if (isset($reqData['StaticpageUpdateForm'])) { $this->gvars['tabActive'] = 2; $this->getSession()->set('tabActive', 2); $staticpageUpdateForm->handleRequest($request); if ($staticpageUpdateForm->isValid()) { $em->persist($staticpage); $em->flush(); $this->flashMsgSession('success', $this->translate('Staticpage.edit.success', array('%staticpage%' => $staticpage->getPagetitle()))); return $this->redirect($urlFrom); } else { $em->refresh($staticpage); $this->flashMsgSession('error', $this->translate('Staticpage.edit.failure', array('%staticpage%' => $staticpage->getPagetitle()))); } } foreach ($staticpage->getI18ns() as $staticpageTrans) { $em->refresh($staticpageTrans); $staticpageTransUpdateForm = $this->createForm(new StaticpageTransUpdateTForm($staticpageTrans->getLang()->getLocale()), $staticpageTrans); if (isset($reqData['StaticpageTransUpdateForm_' . $staticpageTrans->getLang()->getLocale()])) { $this->gvars['tabActive'] = $staticpageTrans->getLang()->getLocale(); $this->getSession()->set('tabActive', $staticpageTrans->getLang()->getLocale()); $staticpageTransUpdateForm->handleRequest($request); if ($staticpageTransUpdateForm->isValid()) { $em->persist($staticpageTrans); $em->flush(); $this->flashMsgSession('success', $this->translate('StaticpageTrans.edit.success', array('%staticpage%' => $staticpage->getPagetitle()))); return $this->redirect($urlFrom); } else { $em->refresh($staticpage); $this->flashMsgSession('error', $this->translate('StaticpageTrans.edit.failure', array('%staticpage%' => $staticpage->getPagetitle()))); } } $this->gvars['StaticpageTransUpdateForm'][$staticpageTrans->getLang()->getLocale()] = $staticpageTransUpdateForm->createView(); } $this->gvars['staticpage'] = $staticpage; $this->gvars['StaticpageUpdateForm'] = $staticpageUpdateForm->createView(); $this->gvars['pagetitle'] = $this->translate('Pagetitle.staticpage.edit', array('%staticpage%' => $staticpage->getPagetitle())); $this->gvars['pagetitle_txt'] = $this->translate('Pagetitle.staticpage.edit.txt', array('%staticpage%' => $staticpage->getPagetitle())); return $this->renderResponse('AllucoAdminBundle:Staticpage:edit.html.twig', $this->gvars); } } catch (\Exception $e) { $logger = $this->getLogger(); $logger->addCritical($e->getLine() . ' ' . $e->getMessage() . ' ' . $e->getTraceAsString()); } return $this->redirect($urlFrom); }
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); }