/** * Return all urls of a page * * @param Page $page Page entity * @param string $type ['sql'] * * @return array * @access public * @author Etienne de Longeaux <*****@*****.**> * @since 2012-06-21 */ public function getUrlByPage(Page $page, $type = '') { $urls = array(); // we register all urls of the page foreach ($page->getTranslations() as $key => $translationPage) { if ($translationPage instanceof TranslationPage) { $locale = $translationPage->getLangCode()->getId(); $url = $page->getUrl(); $slug = $translationPage->getSlug(); if (!empty($url) && !empty($slug)) { $urls[$locale] = $url . "/" . $slug; } elseif (!empty($url) && empty($slug)) { $urls[$locale] = $url; } elseif (empty($url) && !empty($slug)) { $urls[$locale] = $slug; } elseif (empty($url) && empty($slug)) { $urls[$locale] = ""; } $is_prefix_locale = $this->container->getParameter("pi_app_admin.page.route.with_prefix_locale"); if ($is_prefix_locale) { $locale_tmp = explode('_', $locale); $urls[$locale] = $locale_tmp[0] . '/' . $urls[$locale]; } $urls[$locale] = str_replace("//", "/", $urls[$locale]); if ($type == 'sql') { $urls[$locale] = str_replace("/", "\\\\\\\\\\/", $urls[$locale]); } } } return $urls; }
/** * Edits an existing Page entity. * * @param Request $request The request instance * @param Page $entity A page entity * * @Secure(roles="ROLE_EDITOR") * @return Response * @access public * @author Etienne de Longeaux <*****@*****.**> */ public function updateAction(Request $request, Page $entity) { $locale = $this->container->get('request')->getLocale(); $User = $this->get('security.context')->getToken()->getUser(); $NoLayout = $this->container->get('request')->query->get('NoLayout'); if ($this->container->get('security.context')->isGranted("ROLE_SUPER_ADMIN")) { $originalTranslations = array(); // Create an array of the current Widget objects in the database foreach ($entity->getTranslations() as $Translation) { $originalTranslations[] = $Translation; } } $editForm = $this->createForm(new PageType($this->container, $locale, $User->getRoles()), $entity, array('show_legend' => false)); $deleteForm = $this->createDeleteForm($entity->getId()); $editForm->bind($this->getRequest()); if ($editForm->isValid()) { $em = $this->getDoctrine()->getManager(); if ($this->container->get('security.context')->isGranted("ROLE_SUPER_ADMIN")) { // filter $originalWidgets to contain tags no longer present foreach ($entity->getTranslations() as $Translation) { foreach ($originalTranslations as $key => $toDel) { if ($toDel->getId() === $Translation->getId()) { unset($originalTranslations[$key]); } } } // remove the relationship between the Translation and the page foreach ($originalTranslations as $Translation) { $Translation->setPage(null); $em->remove($Translation); } } // We persist all page translations foreach ($entity->getTranslations() as $translationPage) { $entity->addTranslation($translationPage); } $em->persist($entity); $em->flush(); return $this->redirect($this->generateUrl('admin_pagebytrans_edit', array('id' => $entity->getId(), 'NoLayout' => $NoLayout))); } return $this->render("SfynxCmfBundle:PageByTrans:edit.html.twig", array('entity' => $entity, 'edit_form' => $editForm->createView(), 'delete_form' => $deleteForm->createView(), 'NoLayout' => $NoLayout)); }