/**
  * @param View $view, the view to translatate
  * @param $templatename the new name of the view
  * @param $loopindex the current loop of iteration in recursion
  * @param $locale the target locale to translate view
  *
  * this methods allow you to add a translation to any view
  * recursively to its subview
  */
 public function addTranslation(View $view, $viewName = null, $locale)
 {
     $template = null;
     if ($view->getTemplate()) {
         $template = $view->getTemplate();
         if ($template->getI18n()->getTranslation($locale)) {
             $template = $template->getI18n()->getTranslation($locale);
         } else {
             $templateName = $template->getName() . '-' . $locale;
             $this->em->refresh($view);
             $template = $this->addTranslation($template, $templateName, $locale);
         }
     }
     $view->setLocale($locale);
     $view->setTemplate($template);
     $clonedView = $this->cloneView($view, $viewName, $locale);
     if ($clonedView instanceof BasePage && $view->getTemplate()) {
         $template->addPage($clonedView);
     }
     $i18n = $view->getI18n();
     $i18n->setTranslation($locale, $clonedView);
     $this->em->persist($clonedView);
     $this->em->refresh($view);
     $this->em->flush();
     return $clonedView;
 }
 /**
  * @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;
 }
Example #3
0
 /**
  * Find page's ancestors (templates and parents) and flatted all their roles.
  *
  * @param View $view
  *
  * @return array
  */
 private function getPageRoles(View $view)
 {
     $insertAncestorRole = function (View $view = null) use(&$insertAncestorRole) {
         if ($view === null) {
             return;
         }
         $roles = $view->getRoles();
         if ($templateRoles = $insertAncestorRole($view->getTemplate(), $roles)) {
             $roles .= ($roles ? ',' : '') . $templateRoles;
         }
         if ($parentRoles = $insertAncestorRole($view->getParent(), $roles)) {
             $roles .= ($roles ? ',' : '') . $parentRoles;
         }
         return $roles;
     };
     $roles = $insertAncestorRole($view);
     if ($roles) {
         return array_unique(explode(',', $roles));
     }
 }
Example #4
0
 public function isTemplateOf(View $view)
 {
     while ($_view = $view->getTemplate()) {
         if ($this === $_view) {
             return true;
         }
         $view = $_view;
     }
     return false;
 }
Example #5
0
 public function build(View $view, $updatePage = true)
 {
     $viewWidgetMaps = null;
     $widgetMap = array();
     //get the template widget map
     $template = $view->getTemplate();
     if ($template !== null) {
         $widgetMap = $this->build($template);
     }
     // build the view widgetMaps for each its slots
     foreach ($view->getSlots() as $slot) {
         if (empty($widgetMap[$slot->getId()])) {
             $widgetMap[$slot->getId()] = array();
         }
         if ($slot !== null) {
             $viewWidgetMaps = $slot->getWidgetMaps();
         }
         //if the current view have some widget maps
         if ($viewWidgetMaps !== null) {
             //we parse the widget maps
             foreach ($viewWidgetMaps as $viewWidgetMap) {
                 $viewWidgetMap = clone $viewWidgetMap;
                 //depending on the action
                 $action = $viewWidgetMap->getAction();
                 switch ($action) {
                     case WidgetMap::ACTION_CREATE:
                         $position = (int) $viewWidgetMap->getPosition();
                         $reference = (int) $viewWidgetMap->getPositionReference();
                         if ($reference != 0) {
                             if (isset($widgetMap[$slot->getId()])) {
                                 foreach ($widgetMap[$slot->getId()] as $key => $_widgetMap) {
                                     if ($_widgetMap->getWidgetId() === $reference) {
                                         $position += $_widgetMap->getPosition();
                                     }
                                 }
                             }
                         }
                         array_splice($widgetMap[$slot->getId()], $position - 1, 0, array($viewWidgetMap));
                         array_map(function ($key, $_widgetMap) {
                             $_widgetMap->setPosition($key + 1);
                         }, array_keys($widgetMap[$slot->getId()]), $widgetMap[$slot->getId()]);
                         break;
                     case WidgetMap::ACTION_OVERWRITE:
                         //parse the widget maps
                         $position = null;
                         foreach ($widgetMap[$slot->getId()] as $index => $wm) {
                             if ($wm->getWidgetId() == $viewWidgetMap->getReplacedWidgetId()) {
                                 if (null === $viewWidgetMap->isAsynchronous()) {
                                     $viewWidgetMap->setAsynchronous($wm->isAsynchronous());
                                 }
                                 //replace the widget map from the list
                                 unset($widgetMap[$slot->getId()][$index]);
                                 break;
                             }
                         }
                         array_splice($widgetMap[$slot->getId()], $viewWidgetMap->getPosition() - 1, 0, array($viewWidgetMap));
                         array_map(function ($key, $_widgetMap) {
                             $_widgetMap->setPosition($key + 1);
                         }, array_keys($widgetMap[$slot->getId()]), $widgetMap[$slot->getId()]);
                         break;
                     case WidgetMap::ACTION_DELETE:
                         //parse the widget maps
                         foreach ($widgetMap[$slot->getId()] as $index => $wm) {
                             if ($wm->getWidgetId() === $viewWidgetMap->getWidgetId()) {
                                 //remove the widget map from the list
                                 unset($widgetMap[$slot->getId()][$index]);
                             }
                         }
                         break;
                     default:
                         throw new \Exception('The action [' . $action . '] is not handled yet.');
                         break;
                 }
             }
             ksort($widgetMap[$slot->getId()]);
         }
     }
     if ($updatePage) {
         $view->setBuiltWidgetMap($widgetMap);
     }
     return $widgetMap;
 }