/** * @param PageInterface $page * @param PageInterface $currentPage * @param array $choices * @param int $level */ private function childWalker(PageInterface $page, PageInterface $currentPage = null, &$choices, $level = 1) { if (!($currentPage && $currentPage->getId() == $page->getId())) { $choices[$page->getId()] = $page->getLongName(); foreach ($page->getChildren() as $child) { $this->childWalker($child, $currentPage, $choices, $level + 1); } } }
/** * @param PageInterface $page * @param PageInterface $currentPage * @param array $choices * @param int $level */ private function childWalker(PageInterface $page, PageInterface $currentPage = null, &$choices, $level = 1) { foreach ($page->getChildren() as $child) { if ($currentPage && $currentPage->getId() == $child->getId()) { continue; } if ($child->isDynamic()) { continue; } $choices[$child->getId()] = $child; $this->childWalker($child, $currentPage, $choices, $level + 1); } }
/** * {@inheritdoc} */ public function loadPageBlocks(PageInterface $page) { if (isset($this->pageBlocksLoaded[$page->getId()])) { return array(); } $blocks = $this->getBlocksById($page); $page->disableBlockLazyLoading(); foreach ($blocks as $block) { $parent = $block->getParent(); $block->disableChildrenLazyLoading(); if (!$parent) { $page->addBlocks($block); continue; } $blocks[$block->getParent()->getId()]->disableChildrenLazyLoading(); $blocks[$block->getParent()->getId()]->addChildren($block); } $this->pageBlocksLoaded[$page->getId()] = true; return $blocks; }
/** * Get children * * @param \Sonata\PageBundle\Model\PageInterface $parent * @return Collection */ public function getChildren(PageInterface $parent) { if (!isset($this->children[$parent->getId()])) { $date = new \Datetime(); $parameters = array('publicationDateStart' => $date, 'publicationDateEnd' => $date, 'parentId' => $parent->getId()); $snapshots = $this->entityManager->createQueryBuilder()->select('s')->from('Application\\Sonata\\PageBundle\\Entity\\Snapshot', 's')->where('s.parentId = :parentId and s.enabled = 1')->andWhere('s.publicationDateStart <= :publicationDateStart AND ( s.publicationDateEnd IS NULL OR s.publicationDateEnd >= :publicationDateEnd )')->orderBy('s.position')->setParameters($parameters)->getQuery()->execute(); $pages = array(); foreach ($snapshots as $snapshot) { $page = new SnapshotPageProxy($this, $snapshot); $pages[$page->getId()] = $page; } $this->children[$parent->getId()] = new \Doctrine\Common\Collections\ArrayCollection($pages); } return $this->children[$parent->getId()]; }
/** * {@inheritdoc} */ public function getBlocksById(PageInterface $page) { $blocks = $this->getEntityManager()->createQuery(sprintf('SELECT b FROM %s b INDEX BY b.id WHERE b.page = :page ORDER BY b.position ASC', $this->blockManager->getClass()))->setParameters(array('page' => $page->getId()))->useResultCache(true, 300)->execute(); return $blocks; }
/** * {@inheritDoc} */ public function cleanup(PageInterface $page, $keep) { if (!is_numeric($keep)) { throw new \RuntimeException(sprintf('Please provide an integer value, %s given', gettype($keep))); } $tableName = $this->getTableName(); $platform = $this->getConnection()->getDatabasePlatform()->getName(); if ('mysql' === $platform) { return $this->getConnection()->exec(sprintf('DELETE FROM %s WHERE page_id = %d AND id NOT IN ( SELECT id FROM ( SELECT id, publication_date_end FROM %s WHERE page_id = %d ORDER BY publication_date_end IS NULL DESC, publication_date_end DESC LIMIT %d ) AS table_alias )', $tableName, $page->getId(), $tableName, $page->getId(), $keep)); } if ('oracle' === $platform) { return $this->getConnection()->exec(sprintf('DELETE FROM %s WHERE page_id = %d AND id NOT IN ( SELECT id FROM ( SELECT id, publication_date_end FROM %s WHERE page_id = %d AND rownum <= %d ORDER BY publication_date_end DESC ) AS table_alias )', $tableName, $page->getId(), $tableName, $page->getId(), $keep)); } throw new \RuntimeException(sprintf('The %s database platform has not been tested yet. Please report us if it works and feel free to create a pull request to handle it ;-)', $platform)); }
/** * {@inheritdoc} */ public function getChildren(PageInterface $parent) { if (!isset($this->children[$parent->getId()])) { $date = new \Datetime(); $parameters = array('publicationDateStart' => $date, 'publicationDateEnd' => $date, 'parentId' => $parent->getId()); $manager = $this->registry->getManagerForClass($this->snapshotManager->getClass()); if (!$manager instanceof EntityManagerInterface) { throw new \RuntimeException('Invalid entity manager type'); } $snapshots = $manager->createQueryBuilder()->select('s')->from($this->snapshotManager->getClass(), 's')->where('s.parentId = :parentId and s.enabled = 1')->andWhere('s.publicationDateStart <= :publicationDateStart AND ( s.publicationDateEnd IS NULL OR s.publicationDateEnd >= :publicationDateEnd )')->orderBy('s.position')->setParameters($parameters)->getQuery()->execute(); $pages = array(); foreach ($snapshots as $snapshot) { $page = new SnapshotPageProxy($this->snapshotManager, $this, $snapshot); $pages[$page->getId()] = $page; } $this->children[$parent->getId()] = new \Doctrine\Common\Collections\ArrayCollection($pages); } return $this->children[$parent->getId()]; }
/** * @param PageInterface $page * @param PageInterface $currentPage * @param array $choices * @param int $level */ private function childWalker(PageInterface $page, PageInterface $currentPage = null, &$choices, $level = 1, $addNotGrantedPage = false) { if (!($currentPage && $currentPage->getId() == $page->getId())) { if ($level > 1 || $this->isEditor || $this->securityContext->isGranted('EDIT', $page) || $addNotGrantedPage) { $choices[$page->getId()] = $page->getLongName(); } foreach ($page->getChildren() as $child) { if ($this->isEditor || $this->securityContext->isGranted('EDIT', $child)) { $this->childWalker($child, $currentPage, $choices, $level + 1); } } } }
/** * {@inheritdoc} */ public function getChildren(PageInterface $parent) { if (!isset($this->children[$parent->getId()])) { $date = new \Datetime(); $parameters = array('publicationDateStart' => $date, 'publicationDateEnd' => $date, 'parentId' => $parent->getId()); $manager = $this->registry->getManagerForClass($this->snapshotManager->getClass()); if (!$manager instanceof EntityManagerInterface) { throw new \RuntimeException('Invalid entity manager type'); } $snapshots_query = $manager->createQueryBuilder()->select('s')->from($this->snapshotManager->getClass(), 's')->where('s.parentId = :parentId and s.enabled = 1')->andWhere('s.publicationDateStart <= :publicationDateStart AND ( s.publicationDateEnd IS NULL OR s.publicationDateEnd >= :publicationDateEnd )')->orderBy('s.position')->setParameters($parameters)->getQuery(); $snapshots_query->setHint(\Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER, 'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'); $snapshots_query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, $parent->getSite()->getLocale()); $snapshots = $snapshots_query->execute(); $pages = array(); foreach ($snapshots as $snapshot) { $page = new SnapshotPageProxy($this->snapshotManager, $this, $snapshot); $pages[$page->getId()] = $page; } $this->children[$parent->getId()] = new \Doctrine\Common\Collections\ArrayCollection($pages); } return $this->children[$parent->getId()]; }