/**
  * Set visible route.
  *
  * @param string $locale
  * @param NodeInterface $node
  */
 public function setVisible($locale, NodeInterface $node)
 {
     $translation = $node->getTranslation($locale);
     if (null !== $translation && null !== ($route = $translation->getRoute())) {
         $route->setVisible(true);
     }
 }
 /**
  * Get max priority.
  *
  * @param NodeInterface $parent
  *
  * @return int
  */
 private function getMaxPriority(NodeInterface $parent)
 {
     $priority = 0;
     foreach ($parent->getChildren() as $child) {
         $priority = max($priority, $child->getPriority());
     }
     return $priority;
 }
 /**
  * Generate unique route pattern.
  *
  * @param NodeInterface $node
  * @param RouteInterface $route
  *
  * @return string
  *
  * @throws RouteException
  */
 private function generateUniqueRoutePattern(NodeInterface $node, RouteInterface $route)
 {
     if (false === $this->routerHelper->hasController($node->getType())) {
         throw new RouteException('Cannot generate route pattern!');
     }
     if (!trim($route->getRoutePattern())) {
         throw new RouteException('Route pattern cannot be empty!');
     }
     return $this->getUniqueRoutePattern($route);
 }
Beispiel #4
0
 /**
  * {@inheritdoc}
  */
 public function getActiveNodeTypes(NodeInterface $node)
 {
     $nodeTypes = array();
     foreach ($this->nodeTypeRegistry->getConfigs() as $config) {
         if ($node->getType() === $config->getType() || $this->nodeValidator->validateByOnlyOne($config->getType(), $node->getTree()) && (!$config->getParentTypes() || $this->nodeValidator->validateByParent($config->getType(), $node->getParent()))) {
             $nodeTypes[$config->getType()] = $config->getType();
         }
     }
     return array_values($nodeTypes);
 }
 /**
  * Checks if the passed node type is valid.
  *
  * @param NodeInterface $node
  * @param Constraint $constraint
  */
 public function validate($node, Constraint $constraint)
 {
     if (!in_array($node->getType(), $this->nodeProvider->getActiveNodeTypes($node))) {
         $nodeTypeName = $node->getType();
         if (null !== ($config = $this->nodeProvider->getNodeTypeConfig($node->getType()))) {
             $nodeTypeName = $config->getName();
         }
         $this->context->addViolation($constraint->message, array('%node_type%' => $nodeTypeName));
     }
 }
 /**
  * Get route name.
  *
  * @param NodeInterface $node
  * @param null|string $locale
  *
  * @return string
  *
  * @throws RouteException
  */
 public function getRouteName(NodeInterface $node, $locale = null)
 {
     if (!$node->getId()) {
         throw new RouteException('Node id cannot be empty!');
     }
     $name = NodeTranslationInterface::OBJECT_TYPE . '_' . $node->getId();
     if (null !== $locale) {
         $name .= '_' . $locale;
     }
     return $name;
 }
 /**
  * {@inheritdoc}
  */
 public function findNodeAllChildrenTranslationsByLang(NodeInterface $node, $lang)
 {
     $qb = $this->repository->createQueryBuilder('t');
     $qb->innerJoin('t.node', 'n');
     $qb->andWhere($qb->expr()->eq('t.lang', ':locale'));
     $qb->setParameter('locale', $lang);
     $qb->andWhere($qb->expr()->eq('n.root', ':root'))->setParameter('root', $node->getRoot());
     $qb->andWhere($qb->expr()->gte('n.left', ':left'))->setParameter('left', $node->getLeft());
     $qb->andWhere($qb->expr()->lte('n.right', ':right'))->setParameter('right', $node->getRight());
     $qb->select('t');
     return $qb->getQuery()->getResult();
 }
Beispiel #8
0
 /**
  * Validate by parent.
  *
  * @param string $nodeType
  * @param NodeInterface $parent
  *
  * @return bool
  */
 public function validateByParent($nodeType, NodeInterface $parent = null)
 {
     if (!$nodeType) {
         return true;
     }
     $config = $this->getNodeTypeConfig($nodeType);
     if (null === $config) {
         return false;
     }
     if (null !== $parent && $parent->getType()) {
         return in_array($parent->getType(), $config->getParentTypes());
     }
     return false;
 }
 /**
  * Check if node parent is online.
  *
  * @param NodeInterface $node
  * @param string $locale
  *
  * @return bool
  */
 private function parentIsOnline(NodeInterface $node, $locale)
 {
     $parent = $node->getParent();
     if (null !== $parent && $this->routeHelper->hasController($parent->getType())) {
         if (false === $this->routeHelper->hasRoute($locale, $node)) {
             return false;
         }
         if (null === ($translation = $parent->getTranslation($locale))) {
             return false;
         }
         if (null === ($route = $translation->getRoute())) {
             return false;
         }
         return $route->isVisible();
     }
     return true;
 }
 /**
  * Process node online.
  *
  * @param string $locale
  * @param Messages $messages
  * @param NodeInterface $node
  *
  * @return bool
  */
 public function process($locale, Messages $messages, NodeInterface $node)
 {
     if (null === ($nodeTranslation = $node->getTranslation($locale))) {
         $messages->addError($this->translator->trans('node_translation_not_found', array('%locale%' => $locale), 'TadckaSitemapBundle'));
         return false;
     }
     $constraints = array(new NodeRouteNotEmpty(), new NodeParentIsOnline());
     $violation = $this->validator->validateValue($nodeTranslation, $constraints);
     if (0 < $violation->count()) {
         foreach ($violation as $value) {
             $messages->addError($value->getMessage());
         }
         return false;
     }
     if (null !== ($route = $nodeTranslation->getRoute())) {
         if ($route->isVisible()) {
             $this->visibilityManager->setInvisible($locale, $node);
         } else {
             $this->visibilityManager->setVisible($locale, $node);
         }
     }
     return true;
 }
 /**
  * Render node delete confirm.
  *
  * @param NodeInterface $node
  *
  * @return string
  */
 private function renderNodeDeleteConfirm(NodeInterface $node)
 {
     return $this->responseHelper->render('TadckaSitemapBundle:Node:delete.html.twig', array('node_id' => $node->getId()));
 }
Beispiel #12
0
 /**
  * Create seo tab.
  *
  * @param NodeInterface $node
  *
  * @return Tab
  */
 public function createSeoTab(NodeInterface $node)
 {
     return new Tab($this->translator->trans('node.seo', array(), 'TadckaSitemapBundle'), 'node_seo', $this->router->generate('tadcka_sitemap_seo', array('_format' => 'json', 'nodeId' => $node->getId())), 150);
 }
 /**
  * Render toolbar template.
  *
  * @param NodeInterface $node
  *
  * @return string
  */
 private function renderToolbar(NodeInterface $node)
 {
     return $this->responseHelper->render('TadckaSitemapBundle:Sitemap:toolbar.html.twig', array('node' => $node, 'multi_language_enabled' => $this->routerHelper->multiLanguageIsEnabled(), 'multi_language_locales' => $this->routerHelper->getMultiLanguageLocales(), 'has_controller' => $this->routerHelper->hasController($node->getType())));
 }
Beispiel #14
0
 /**
  * Recursive delete node children.
  *
  * @param TreeNodeInterface $node
  */
 private function recursiveDelete(TreeNodeInterface $node)
 {
     foreach ($node->getChildren() as $child) {
         $this->recursiveDelete($child);
     }
     $this->repository->removeFromTree($node);
 }
Beispiel #15
0
 /**
  * Get route full path.
  *
  * @param NodeInterface $node
  * @param string $locale
  *
  * @return string
  */
 private function getRouteFullPath(NodeInterface $node, $locale)
 {
     $path = '';
     if ($this->hasController($node->getType())) {
         $parent = $node->getParent();
         if (null !== $parent && $this->hasController($parent->getType())) {
             $path = $this->getRouteFullPath($parent, $locale);
         }
         if (null !== ($translation = $node->getTranslation($locale))) {
             $path .= $this->normalizeRoutePattern($translation->getTitle());
         }
     }
     return $path;
 }
Beispiel #16
0
 /**
  * Get node icon.
  *
  * @param NodeInterface $node
  *
  * @return null|string
  */
 private function getIcon(NodeInterface $node)
 {
     if (null === $node->getParent()) {
         return $this->getRootNodeIcon();
     }
     if ($node->getType() && null !== ($config = $this->nodeProvider->getNodeTypeConfig($node->getType()))) {
         return $config->getIconPath();
     }
     return null;
 }
 /**
  * Render node content template.
  *
  * @param NodeInterface $node
  * @param array $tabs
  *
  * @return string
  */
 public function renderNodeContent(NodeInterface $node, array $tabs)
 {
     return $this->responseHelper->render('TadckaSitemapBundle:Sitemap:content.html.twig', array('node' => $node, 'tabs' => $tabs, 'has_controller' => $this->routerHelper->hasController($node->getType()), 'multi_language_enabled' => $this->routerHelper->multiLanguageIsEnabled(), 'multi_language_locales' => $this->routerHelper->getMultiLanguageLocales()));
 }
 /**
  * Get node types.
  *
  * @param NodeInterface $node
  *
  * @return array
  */
 private function getNodeTypes(NodeInterface $node)
 {
     $nodeTypes = array();
     if (null !== $node->getParent()) {
         foreach ($this->nodeProvider->getActiveNodeTypes($node) as $nodeType) {
             $nodeTypes[$nodeType] = $this->getNodeTypeName($this->nodeProvider->getNodeTypeConfig($nodeType));
         }
     }
     return $nodeTypes;
 }
 /**
  * Create json response content.
  *
  * @param NodeInterface $node
  *
  * @return JsonResponseContent
  */
 public function createJsonContent(NodeInterface $node)
 {
     return new JsonResponseContent($node->getId());
 }
 /**
  * Delete node route.
  *
  * @param NodeInterface $node
  * @param RouteInterface $route
  */
 private function deleteNodeRoute(NodeInterface $node, RouteInterface $route)
 {
     $this->routeManager->remove($route);
     $redirectRouteName = $route->getDefault('redirectRouteName');
     if (RedirectRoute::NODE_TYPE === $node->getType() && null !== $redirectRouteName) {
         $redirectRoute = $this->redirectRouteManager->findByName($redirectRouteName);
         if (null !== $redirectRoute) {
             $this->redirectRouteManager->remove($redirectRoute);
         }
     }
 }
 /**
  * Get node title.
  *
  * @param string $locale
  * @param NodeInterface $node
  *
  * @return string
  */
 private function getNodeTitle($locale, NodeInterface $node)
 {
     if (null !== ($translation = $node->getTranslation($locale))) {
         return $translation->getTitle();
     }
     return $this->translator->trans('not_found_title', array(), 'TadckaSitemapBundle');
 }