示例#1
0
 /**
  * @param View  $view
  * @param mixed $entity
  *
  * @return string
  */
 public static function generateViewReferenceId(View $view, $entity = null)
 {
     $id = $view->getId();
     if ($view instanceof BusinessPage) {
         $id = $view->getTemplate()->getId();
         $entity = $view->getBusinessEntity();
     } elseif (!$view instanceof WebViewInterface) {
         return $view->getId();
     }
     $refId = sprintf('ref_%s', $id);
     if ($entity) {
         $refId .= '_' . $entity->getId();
     }
     return $refId;
 }
示例#2
0
 /**
  * Transforms an object (View) to a string (id).
  *
  * @param View|null $view
  *
  * @return string
  */
 public function transform($view)
 {
     if (null === $view) {
         return '';
     }
     return $view->getId();
 }
示例#3
0
 /**
  * Delete the widget from the view
  *
  * @param View   $view
  * @param Widget $widget
  *
  * @throws \Exception The slot does not exists
  */
 public function deleteWidgetFromView(View $view, Widget $widget)
 {
     //the widget view
     $widgetView = $widget->getView();
     //the widget slot
     $widgetSlotId = $widget->getSlot();
     //the widget id
     $widgetId = $widget->getId();
     //get the slot
     $slot = $view->getSlotById($widgetSlotId);
     //we remove the widget from the current view
     if ($widgetView === $view) {
         //test that the slot for the widget exists
         if ($slot === null) {
             throw new \Exception('The slot[' . $widgetSlotId . '] for the widget [' . $widgetId . '] of the view [' . $view->getId() . '] was not found.');
         }
         //get the widget map
         $widgetMap = $slot->getWidgetMapByWidgetId($widgetId);
         //check that the widget map exists
         if ($widgetMap === null) {
             throw new \Exception('The widgetMap for the widget [' . $widgetId . '] and the view [' . $view->getId() . '] does not exists.');
         }
         //remove the widget map from the slot
         $slot->removeWidgetMap($widgetMap);
     } else {
         //there might be no slot yet for the child view
         if ($slot === null) {
             //create a new slot
             $slot = new Slot();
             $slot->setId($widgetSlotId);
             //add the new slot to the view
             $view->addSlot($slot);
         }
         //the widget is owned by another view (a parent)
         //so we add a new widget map that indicates we delete this widget
         $widgetMap = new WidgetMap();
         $widgetMap->setAction(WidgetMap::ACTION_DELETE);
         $widgetMap->setWidgetId($widgetId);
         $slot->addWidgetMap($widgetMap);
     }
 }
示例#4
0
 /**
  * BasePage settings.
  *
  * @param BasePage $page
  *
  * @Route("/{id}", name="victoire_seo_pageSeo_settings")
  * @Template()
  *
  * @return JsonResponse
  */
 public function settingsAction(View $page)
 {
     //services
     $em = $this->getDoctrine()->getManager();
     $businessProperties = [];
     //if the page is a business entity template page
     if ($page instanceof BusinessPage || $page instanceof BusinessTemplate) {
         //we can use the business entity properties on the seo
         $businessEntity = $this->get('victoire_core.helper.business_entity_helper')->findById($page->getBusinessEntityId());
         $businessProperties = $businessEntity->getBusinessPropertiesByType('seoable');
     }
     $pageSeo = $page->getSeo() ? $page->getSeo() : new PageSeo($page);
     //url for the form
     $formUrl = $this->get('router')->generate('victoire_seo_pageSeo_settings', ['id' => $page->getId()]);
     //create the form
     $form = $this->get('form.factory')->create(PageSeoType::class, $pageSeo, ['action' => $formUrl, 'method' => 'POST']);
     $form->handleRequest($this->get('request'));
     $novalidate = $this->get('request')->query->get('novalidate', false);
     $template = 'VictoireSeoBundle:PageSeo:form.html.twig';
     if ($novalidate === false) {
         $template = 'VictoireSeoBundle:PageSeo:settings.html.twig';
     }
     if (false === $novalidate && $form->isValid()) {
         $em->persist($pageSeo);
         $page->setSeo($pageSeo);
         $em->persist($page);
         $em->flush();
         //redirect to the page url
         if (!method_exists($page, 'getUrl')) {
             $url = $this->generateUrl('victoire_business_template_show', ['id' => $page->getId()]);
         } else {
             /** @var ViewReference $viewReference */
             $viewReference = $this->container->get('victoire_view_reference.repository')->getOneReferenceByParameters(['viewId' => $page->getId()]);
             $page->setReference($viewReference);
             $url = $this->generateUrl('victoire_core_page_show', ['url' => $viewReference->getUrl()]);
         }
         $this->get('victoire_core.current_view')->setCurrentView($page);
         $this->congrat('victoire_seo.save.success');
         return new JsonResponse(['success' => true, 'url' => $url]);
     }
     return new JsonResponse(['success' => !$form->isSubmitted(), 'html' => $this->container->get('templating')->render($template, ['page' => $page, 'form' => $form->createView(), 'businessProperties' => $businessProperties])]);
 }
示例#5
0
 /**
  * @param View $view
  * @param $entity
  * @return string
  */
 public static function getViewReferenceId(View $view, $entity = null)
 {
     if ($view instanceof BusinessEntityPage) {
         $entity = $view->getBusinessEntity();
     }
     $id = sprintf('ref_%s', $view->getId());
     if ($entity) {
         $id .= '_' . $entity->getId();
     }
     return $id;
 }