コード例 #1
0
 /**
  * @covers Kunstmaan\FormBundle\Entity\FormSubmission::getNode
  * @covers Kunstmaan\FormBundle\Entity\FormSubmission::setNode
  */
 public function testSetGetNode()
 {
     $object = $this->object;
     $node = new Node();
     $node->setId(123);
     $object->setNode($node);
     $retrievedNode = $object->getNode();
     $this->assertEquals($node, $retrievedNode);
     $this->assertEquals($node->getId(), $retrievedNode->getId());
 }
コード例 #2
0
 /**
  * Add parent nodes to the index document
  *
  * @param Node  $node
  * @param array $doc
  *
  * @return array
  */
 protected function addParentAndAncestors($node, &$doc)
 {
     $parent = $node->getParent();
     if ($parent) {
         $doc['parent'] = $parent->getId();
         $ancestors = array();
         do {
             $ancestors[] = $parent->getId();
             $parent = $parent->getParent();
         } while ($parent);
         $doc['ancestors'] = $ancestors;
     }
 }
コード例 #3
0
 private function createRootNode($page, $language, $internalName, $fixtureParams)
 {
     $rootNode = new Node();
     $rootNode->setRef($page);
     $rootNode->setDeleted(false);
     $rootNode->setInternalName($internalName);
     $rootNode->setHiddenFromNav(isset($fixtureParams['hidden_from_nav']) ? $fixtureParams['hidden_from_nav'] : false);
     $parent = $this->getParentNode($fixtureParams, $language);
     if ($parent instanceof Node) {
         $rootNode->setParent($parent);
     }
     return $rootNode;
 }
コード例 #4
0
 /**
  * Get the node translation for a given url
  *
  * @param string          $urlSlug        The full url
  * @param string          $locale         The locale
  * @param boolean         $includeDeleted Include deleted nodes
  * @param NodeTranslation $toExclude      Optional NodeTranslation instance
  *                                        you wish to exclude
  * @param Node            $rootNode       Optional Root node of the tree you
  *                                        wish to use
  *
  * @return NodeTranslation|null
  */
 public function getNodeTranslationForUrl($urlSlug, $locale = '', $includeDeleted = false, NodeTranslation $toExclude = null, Node $rootNode = null)
 {
     $qb = $this->createQueryBuilder('b')->select('b', 'v')->innerJoin('b.node', 'n', 'WITH', 'b.node = n.id')->leftJoin('b.publicNodeVersion', 'v', 'WITH', 'b.publicNodeVersion = v.id')->addOrderBy('b.online', 'DESC')->addOrderBy('n.sequenceNumber', 'DESC')->setFirstResult(0)->setMaxResults(1);
     if (!$includeDeleted) {
         $qb->andWhere('n.deleted = 0');
     }
     if (!empty($locale)) {
         $qb->andWhere('b.lang = :lang')->setParameter('lang', $locale);
     }
     if (empty($urlSlug)) {
         $qb->andWhere('b.url IS NULL');
     } else {
         $qb->andWhere('b.url = :url');
         $qb->setParameter('url', $urlSlug);
     }
     if (!is_null($toExclude)) {
         $qb->andWhere('NOT b.id = :exclude_id')->setParameter('exclude_id', $toExclude->getId());
     }
     if ($rootNode) {
         $qb->andWhere('n.lft >= :left')->andWhere('n.rgt <= :right')->setParameter('left', $rootNode->getLeft())->setParameter('right', $rootNode->getRight());
     }
     return $qb->getQuery()->getOneOrNullResult();
 }
コード例 #5
0
 /**
  * Add children
  *
  * @param Node $child
  *
  * @return Node
  */
 public function addNode(Node $child)
 {
     $this->children[] = $child;
     $child->setParent($this);
     return $this;
 }
コード例 #6
0
 /**
  * @param string $lang   The locale
  * @param string $title  The title
  * @param string $slug   The slug
  * @param int    $nodeId The node id
  *
  * @return Node
  */
 private function getNodeWithTranslation($lang, $title, $slug, $nodeId = null)
 {
     $node = new Node();
     if (!is_null($nodeId)) {
         $node->setId($nodeId);
     }
     $nodeTranslation = new NodeTranslation();
     $nodeTranslation->setLang($lang)->setTitle($title)->setSlug($slug);
     $node->addNodeTranslation($nodeTranslation);
     return $node;
 }
コード例 #7
0
 /**
  * @param HasNodeInterface $hasNode      The object to link to
  * @param string           $lang         The locale
  * @param BaseUser         $owner        The user
  * @param string           $internalName The internal name (may be null)
  *
  * @throws \InvalidArgumentException
  *
  * @return Node
  */
 public function createNodeFor(HasNodeInterface $hasNode, $lang, BaseUser $owner, $internalName = null)
 {
     $em = $this->getEntityManager();
     $node = new Node();
     $node->setRef($hasNode);
     if (!$hasNode->getId() > 0) {
         throw new \InvalidArgumentException("the entity of class " . $node->getRefEntityName() . " has no id, maybe you forgot to flush first");
     }
     $node->setDeleted(false);
     $node->setInternalName($internalName);
     $parent = $hasNode->getParent();
     if ($parent) {
         /* @var NodeVersion $parentNodeVersion */
         $parentNodeVersion = $em->getRepository('KunstmaanNodeBundle:NodeVersion')->findOneBy(array('refId' => $parent->getId(), 'refEntityName' => ClassLookup::getClass($parent)));
         if ($parentNodeVersion) {
             $node->setParent($parentNodeVersion->getNodeTranslation()->getNode());
         }
     }
     if ($hasNode instanceof HiddenFromNavInterface) {
         $node->setHiddenFromNav($hasNode->isHiddenFromNav());
     }
     $em->persist($node);
     $em->flush();
     $em->refresh($node);
     $em->getRepository('KunstmaanNodeBundle:NodeTranslation')->createNodeTranslationFor($hasNode, $lang, $node, $owner);
     return $node;
 }
コード例 #8
0
 private function createRootNode($page, $language, $internalName, $fixtureParams)
 {
     $rootNode = new Node();
     $rootNode->setRef($page);
     $rootNode->setDeleted(false);
     $rootNode->setInternalName($internalName);
     $rootNode->setHiddenFromNav(isset($fixtureParams['hidden_from_nav']) ? $fixtureParams['hidden_from_nav'] : false);
     $parent = $this->getParentNode($fixtureParams, $language);
     if ($parent instanceof Node) {
         $rootNode->setParent($parent);
         if (!$this->canHaveChild($parent->getRefEntityName(), get_class($page))) {
             throw new \Exception(sprintf('A %s can\'t have a %s as child. Forgot to add in allowed_children or getPossibleChildTypes?', $parent->getRefEntityName(), get_class($page)));
         }
     }
     return $rootNode;
 }
コード例 #9
0
 /**
  * @param Node $node
  *
  * @return NodeMenuItem
  */
 public function getParent(Node $node)
 {
     if ($node->getParent() && array_key_exists($node->getParent()->getId(), $this->allNodes)) {
         return $this->allNodes[$node->getParent()->getId()];
     }
     return false;
 }
コード例 #10
0
 /**
  * @covers Kunstmaan\NodeBundle\Entity\Node::__toString
  */
 public function testToString()
 {
     $this->object->setId(1);
     $this->object->setRef(new TestEntity());
     $this->assertEquals('node 1, refEntityName: Kunstmaan\\NodeBundle\\Tests\\Entity\\TestEntity', $this->object->__toString());
 }
コード例 #11
0
 /**
  * @covers Kunstmaan\NodeBundle\Helper\Menu\ActionsMenuBuilder::createActionsMenu
  */
 public function testShouldShowDeleteButtonWhenTheNodeHasAParent()
 {
     $nodeTranslation = new NodeTranslation();
     $node = new Node();
     $node->setParent(new Node());
     $nodeTranslation->setNode($node);
     $nodeVersion = new NodeVersion();
     $nodeVersion->setType('public');
     $nodeVersion->setNodeTranslation($nodeTranslation);
     $this->builder->setActiveNodeVersion($nodeVersion);
     $menu = $this->builder->createActionsMenu();
     $this->assertNotNull($menu->getChild('action.delete'));
     $this->assertEquals('page-main-actions js-auto-collapse-buttons', $menu->getChildrenAttribute('class'));
 }
コード例 #12
0
 /**
  * Get all childs of a given node
  *
  * @param Node $node
  *
  * @return array
  */
 public function getChildren(Node $node)
 {
     return $this->findBy(array('parent' => $node->getId()), array('weight' => 'ASC'));
 }
コード例 #13
0
 /**
  * @covers Kunstmaan\NodeBundle\Helper\Menu\ActionsMenuBuilder::createActionsMenu
  */
 public function testShouldShowRecopyButtonWhenTheNodeHasTranslations()
 {
     $node = new Node();
     $nodeTranslation = new NodeTranslation();
     $nodeTranslation->setLang('en');
     $node->addNodeTranslation($nodeTranslation);
     $nodeVersion = new NodeVersion();
     $nodeVersion->setType("public");
     $nodeVersion->setNodeTranslation($nodeTranslation);
     $this->builder->setActiveNodeVersion($nodeVersion);
     $nodeTranslation = new NodeTranslation();
     $nodeTranslation->setLang('nl');
     $node->addNodeTranslation($nodeTranslation);
     $nodeVersion = new NodeVersion();
     $nodeVersion->setType("public");
     $nodeVersion->setNodeTranslation($nodeTranslation);
     $this->builder->setActiveNodeVersion($nodeVersion);
     $menu = $this->builder->createActionsMenu();
     $this->assertNotNull($menu->getChild('action.recopyfromlanguage'));
     $this->assertEquals('page-main-actions js-auto-collapse-buttons', $menu->getChildrenAttribute('class'));
 }
コード例 #14
0
 /**
  * @return int
  */
 public function getId()
 {
     return $this->node->getId();
 }