コード例 #1
0
 public static function setSectionHasChildren($em, Section $section = null, $pageCountModifier = 0)
 {
     if ($section !== null) {
         $repo = $em->getRepository('BackBee\\NestedNode\\Page');
         $notDeletedDescendants = $repo->getNotDeletedDescendants($section->getPage(), 1, false, [], true, 0, 2);
         $section->setHasChildren($notDeletedDescendants->getIterator()->count() + $pageCountModifier > 0);
         $em->getUnitOfWork()->recomputeSingleEntityChangeSet($em->getClassMetadata('BackBee\\NestedNode\\Section'), $section);
     }
 }
コード例 #2
0
 public function deleteSection(Section $section)
 {
     $page_repo = $this->getEntityManager()->getRepository('BackBee\\NestedNode\\Page');
     $pages = $page_repo->createQueryBuilder('p')->andParentIs($section->getPage())->andIsNotSection()->getQuery()->execute();
     foreach ($pages as $page) {
         $page_repo->deletePage($page);
     }
     $sections = $page_repo->createQueryBuilder('p')->andParentIs($section->getPage())->andIsSection()->getQuery()->execute();
     foreach ($sections as $section) {
         $this->deleteSection($section->getSection());
     }
     $this->getEntityManager()->remove($section);
 }
コード例 #3
0
ファイル: Page.php プロジェクト: Bensid/BackBee
 /**
  * Sets the section for this page.
  *
  * @param  Section              $section
  *
  * @return Page
  */
 public function setSection(Section $section)
 {
     if ($section !== $this->_mainsection) {
         $this->_mainsection = null;
         $this->_level = $section->getLevel() + 1;
         if (0 === $this->_position) {
             $this->_position = 1;
         }
     }
     $this->_section = $section;
     return $this;
 }
コード例 #4
0
ファイル: PageTest.php プロジェクト: gobjila/BackBee
 /**
  * @covers BackBee\NestedNode\Page::getParent()
  */
 public function testGetParent()
 {
     $this->assertNull($this->page->getParent());
     $subsection = new Section('sub-section');
     $subsection->setRoot($this->page->getSection())->setParent($this->page->getSection());
     $child = new Page('child', array('main_section' => $subsection));
     $this->assertEquals($this->page, $child->getParent());
     $subchild = new Page('child');
     $subchild->setSection($child->getSection());
     $this->assertEquals($child, $subchild->getParent());
 }
コード例 #5
0
 /**
  * @covers \BackBee\NestedNode\Repository\SectionRepository::getNativelyNodeChildren
  */
 public function testGetNativelyNodeChildren()
 {
     $this->assertEquals(array(), $this->repository->getNativelyNodeChildren('test'));
     $this->assertEquals(array('child2', 'child1'), $this->repository->getNativelyNodeChildren($this->root->getUid()));
 }
コード例 #6
0
ファイル: SectionRepository.php プロジェクト: gobjila/BackBee
 public function deleteSection(Section $section)
 {
     $page_repo = $this->getEntityManager()->getRepository('BackBee\\NestedNode\\Page');
     $pages = $page_repo->createQueryBuilder('p')->andParentIs($section->getPage())->andIsNotSection()->getQuery()->execute();
     foreach ($pages as $page) {
         $page_repo->deletePage($page);
     }
     $sections = $page_repo->createQueryBuilder('p')->andParentIs($section->getPage())->andIsSection()->getQuery()->execute();
     $this->getEntityManager()->createQueryBuilder()->update('BackBee\\NestedNode\\Page', 'p')->set('p._section', ':null')->where('p._section = :uid')->setParameter('uid', $section->getUid())->setParameter('null', null)->getQuery()->execute();
     foreach ($sections as $subsection) {
         $page_repo->deletePage($subsection);
     }
     $this->getEntityManager()->remove($section);
 }
コード例 #7
0
 /**
  * Test cascade Doctrine annotations for entity
  */
 public function testDoctrineCascade()
 {
     self::$kernel->resetDatabase();
     $site = new Site('site-test', ['label' => 'site-test']);
     $layout = self::$kernel->createLayout('layout-test', 'layout-test');
     self::$em->persist($site);
     self::$em->persist($layout);
     self::$em->flush();
     $root = new Section('root');
     $root->setSite($site)->getPage()->setLayout($layout);
     // Persist cascade on Section::_page
     self::$em->persist($root);
     $this->assertTrue(self::$em->getUnitOfWork()->isScheduledForInsert($root));
     $this->assertTrue(self::$em->getUnitOfWork()->isScheduledForInsert($root->getPage()));
     self::$em->flush($root);
     // Remove cascade on Section::_page
     self::$em->remove($root);
     $this->assertTrue(self::$em->getUnitOfWork()->isScheduledForDelete($root));
     $this->assertTrue(self::$em->getUnitOfWork()->isScheduledForDelete($root->getPage()));
     self::$em->flush();
 }