protected function prepareData(ClassMetadata $metadata, array $data) { foreach ($data as $name => &$entityData) { switch ($metadata->name) { case Localization::CN(): case PageLocalization::CN(): case TemplateLocalization::CN(): case ApplicationLocalization::CN(): $entityData['publishedRevision'] = null; $args = array($entityData['locale']); break; case PageLocalizationPath::CN(): $args = array(str_ireplace('pageLocalizationPath', '', $name), $entityData['locale']); break; case TemplateLayout::CN(): $args = array($entityData['media']); break; case BlockPropertyMetadata::CN(): $args = array($entityData['name'], $entityData['blockProperty']); break; case BlockProperty::CN(): $args = array($entityData['name']); break; case PagePlaceHolder::CN(): case TemplatePlaceHolder::CN(): $args = array($entityData['name']); break; default: $constructor = new \ReflectionMethod($metadata->name, '__construct'); if ($constructor->getNumberOfRequiredParameters() === 0) { return parent::prepareData($metadata, $data); } throw new \RuntimeException(sprintf('Don\'t know how to build constructor required for [%s].', $metadata->name)); } $entityData = array_merge(array('__construct' => $args), $entityData); } return parent::prepareData($metadata, $data); }
/** * @return \Doctrine\ORM\QueryBuilder */ protected function doGetQueryBuilder() { // Clones the query builder for local usage $qb = clone $this->pageFinder->getQueryBuilder(); if ($this->pageFinder instanceof TemplateFinder) { $qb->from(TemplateLocalization::CN(), 'l'); $qb->select('l'); } else { $qb->from(PageLocalization::CN(), 'l'); $qb->select('l, e2, p'); $qb->join('l.path', 'p'); $qb->join('l.master', 'e2'); // if ($this->active) { // $qb->andWhere('l.active = true AND p.path IS NOT NULL'); // } if ($this->public) { $qb->andWhere('l.publishedRevision IS NOT NULL'); } if ($this->visibleInSitemap) { $qb->andWhere('l.visibleInSitemap = true'); } if ($this->visibleInMenu) { $qb->andWhere('l.visibleInMenu = true'); } if (!is_null($this->redirect)) { $qb->andWhere('l.redirect IS ' . ($this->redirect ? 'NOT ' : '') . 'NULL'); } } $qb->andWhere('l.master = e'); // Join only to fetch the master // It's important to include all or else extra queries will be executed //$qb->select('l, e2, p'); if (!empty($this->locale)) { $qb->andWhere('l.locale = :locale')->setParameter('locale', $this->locale); } return $qb; }
protected function createEntityTemplate($data) { $template = new Template(); $this->em->persist($template); $layout = new TemplateLayout($data['media']); $layout->setLayoutName($data['layoutName']); $layout->setTemplate($template); $this->em->persist($layout); foreach ($data['localizations'] as $locale => $title) { $localization = new TemplateLocalization($locale); $localization->setTitle($title); $localization->setTemplate($template); $this->em->persist($localization); } return $template; }
/** * Get list of pages converted to array * @param string $entity * @return array */ private function loadSitemapTree($entity) { $em = $this->getEntityManager(); $input = $this->getRequestInput(); $localeId = $this->getCurrentLocale()->getId(); // Parent ID and level $levels = null; $parentId = null; if ($input->has('parent_id')) { $parentId = $input->get('parent_id'); // Special case for root page, need to fetch 2 levels if (empty($parentId)) { $levels = 2; } else { $levels = 1; } } else { $levels = 2; } $parentLocalization = null; $filter = null; if (!empty($parentId)) { if (strpos($parentId, '_') !== false) { list($parentId, $filter) = explode('_', $parentId); } // Find localization, special case for group pages if ($entity == Page::CN()) { $parentLocalization = $em->find(PageLocalization::CN(), $parentId); if (is_null($parentLocalization)) { $rootNode = $em->find($entity, $parentId); if ($rootNode instanceof GroupPage) { $parentLocalization = $rootNode->getLocalization($localeId); } } } else { $parentLocalization = $em->find(TemplateLocalization::CN(), $parentId); } if (is_null($parentLocalization)) { throw new CmsException(null, 'The page the children has been requested for was not found'); } } $response = $this->gatherChildrenData($entity, $parentLocalization, $filter, $levels); return $response; }
/** * @return PageSet */ public function getPageSet() { if ($this->pageSet === null) { $auditReader = $this->getAuditReader(); $localization = $this->getLocalization(); // $auditReader->getCache()->setSuffix($localization->getPublishedRevision()); $entityManager = $this->getEntityManager(); $pages = array(); foreach (parent::getPageSet() as $page) { $revisionId = $localization->getPublishedRevision(); if ($page instanceof Template) { $templateLocalization = $page->getLocalization($localization->getLocaleId()); if ($templateLocalization === null) { throw new \RuntimeException(sprintf('Template [%s] from page structure set has no localization for [%s] locale.', $page->getId(), $localization->getLocaleId())); } $revisions = $auditReader->findRevisions(TemplateLocalization::CN(), $templateLocalization->getId()); $lastRevision = array_shift($revisions); $revisionId = $lastRevision->getRev(); } $classMetadata = $entityManager->getClassMetadata($page::CN()); $pages[] = $auditReader->find($classMetadata->name, $page->getId(), $revisionId); } $this->pageSet = new PageSet($pages); } return $this->pageSet; }
/** * Handles template list request. * * @return SupraJsonResponse */ public function templatesListAction() { $localeId = $this->getCurrentLocale()->getId(); $templateLocalizations = $this->getEntityManager()->getRepository(TemplateLocalization::CN())->findBy(array('locale' => $localeId), array('title' => 'asc')); /* @var $templateLocalizations TemplateLocalization[] */ $responseData = array(); foreach ($templateLocalizations as $templateLocalization) { $responseData[] = array('id' => $templateLocalization->getMaster()->getId(), 'title' => $templateLocalization->getTitle()); } return new SupraJsonResponse($responseData); }