/**
  * Guess the position of the widget relatively to the positionReference.
  *
  * @param Widget $widget            The widget to position
  * @param int    $positionReference Id of the parent widget
  *
  * @return WidgetMap The position of the widget
  */
 public function generateWidgetPosition(EntityManager $entityManager, WidgetMap $widgetMapEntry, $widget, $widgetMap, $positionReference)
 {
     $position = 1;
     $slotId = $widget->getSlot();
     if (empty($widgetMap[$slotId])) {
         $widgetMapEntry->setPosition($position);
         return $widgetMapEntry;
     }
     $slot = $widgetMap[$slotId];
     $referenceWidget = $entityManager->getRepository('Victoire\\Bundle\\WidgetBundle\\Entity\\Widget')->findOneById($positionReference);
     //If we added a widget just after a parent widget
     //The position of the new widget is the one just after the parent widget
     if ($referenceWidget && $widget->getView() !== $referenceWidget->getView()) {
         $position = 1;
         $widgetMapEntry->setPosition($position);
         $widgetMapEntry->setPositionReference($positionReference);
     } else {
         foreach ($slot as $key => $_widgetMap) {
             if ($_widgetMap->getWidgetId() === (int) $positionReference) {
                 $widgetMapEntry->setPosition($_widgetMap->getPosition() + 1);
                 break;
             } elseif (0 === (int) $positionReference) {
                 $widgetMapEntry->setPosition(1);
             }
         }
     }
     return $widgetMapEntry;
 }
Exemplo n.º 2
0
 /**
  * Stylize a widget.
  *
  * @param Widget $widget        The widget to stylize
  * @param int    $viewReference The current view
  *
  * @return JsonResponse
  *
  * @Route("/victoire-dcms/widget/stylize/{id}/{viewReference}", name="victoire_core_widget_stylize", options={"expose"=true})
  * @Template()
  */
 public function stylizeAction(Request $request, Widget $widget, $viewReference)
 {
     $view = $this->getViewByReferenceId($viewReference);
     $widgetView = $widget->getView();
     $widgetViewReference = $this->container->get('victoire_view_reference.cache.repository')->getOneReferenceByParameters(['viewId' => $view->getId()]);
     $widgetView->setReference($widgetViewReference);
     $this->get('victoire_core.current_view')->setCurrentView($view);
     try {
         $form = $this->container->get('form.factory')->create('victoire_widget_style_type', $widget, ['method' => 'POST', 'action' => $this->generateUrl('victoire_core_widget_stylize', ['id' => $widget->getId(), 'viewReference' => $viewReference])]);
         $form->handleRequest($this->get('request'));
         if ($request->query->get('novalidate', false) === false && $form->isValid()) {
             if ($form->has('deleteBackground') && $form->get('deleteBackground')->getData()) {
                 // @todo: dynamic responsive key
                 foreach (['', 'XS', 'SM', 'MD', 'LG'] as $key) {
                     $widget->{'deleteBackground' . $key}();
                 }
             }
             $this->get('doctrine.orm.entity_manager')->flush();
             $params = ['view' => $view, 'success' => true, 'html' => $this->get('victoire_widget.widget_renderer')->render($widget, $view), 'widgetId' => $widget->getId(), 'viewCssHash' => $view->getCssHash()];
         } else {
             $template = $request->query->get('novalidate', false) !== false ? 'VictoireCoreBundle:Widget/Form/stylize:form.html.twig' : 'VictoireCoreBundle:Widget/Form:stylize.html.twig';
             $params = ['success' => false, 'html' => $this->get('victoire_core.template_mapper')->render($template, ['view' => $view, 'form' => $form->createView(), 'widget' => $widget])];
         }
         $response = new JsonResponse($params);
     } catch (Exception $ex) {
         $response = $this->getJsonReponseFromException($ex);
     }
     return $response;
 }
Exemplo n.º 3
0
 /**
  * Stylize a widget
  * @param Widget  $widget        The widget to stylize
  * @param integer $viewReference The current view
  * @param string  $entityName    The entity name (could be null is the submitted form is in static mode)
  *
  * @return JsonResponse
  *
  * @Route("/victoire-dcms/widget/stylize/{id}/{viewReference}/{entityName}", name="victoire_core_widget_stylize", options={"expose"=true})
  * @Template()
  */
 public function stylizeAction(Widget $widget, $viewReference, $entityName = null)
 {
     $view = $this->getViewByReferenceId($viewReference);
     $widgetView = $widget->getView();
     $widgetViewReferenceId = $this->get('victoire_core.view_cache_helper')->getViewReferenceId($widgetView);
     $widgetViewReference = $this->get('victoire_core.view_cache_helper')->getReferenceByParameters(array('id' => $widgetViewReferenceId));
     $widgetView->setReference($widgetViewReference);
     $this->get('victoire_core.current_view')->setCurrentView($view);
     try {
         $form = $this->container->get('form.factory')->create('victoire_widget_style_type', $widget, array('method' => 'POST', 'action' => $this->generateUrl('victoire_core_widget_stylize', array('id' => $widget->getId(), 'viewReference' => $viewReference))));
         $form->handleRequest($this->get('request'));
         if ($form->isValid()) {
             $this->get('doctrine.orm.entity_manager')->flush();
             $params = array('view' => $view, 'success' => true, 'html' => $this->get('victoire_widget.widget_renderer')->render($widget, $view), 'widgetId' => $widget->getId());
         } else {
             $params = array("success" => false, "html" => $this->get('victoire_core.template_mapper')->render("VictoireCoreBundle:Widget:Form/stylize.html.twig", array('view' => $view, 'form' => $form->createView(), 'widget' => $widget)));
         }
         $response = new JsonResponse($params);
     } catch (Exception $ex) {
         $response = $this->getJsonReponseFromException($ex);
     }
     return $response;
 }