コード例 #1
0
 /**
  * @param \DateTime $date
  * @param string $format
  * @return string
  */
 public function prettyDate(\DateTime $date, $format = "default")
 {
     $locale = $this->currentLocale->getCurrentLocale();
     if (isset($this->formats[$format][$locale])) {
         $format = $this->formats[$format][$locale];
     } elseif (isset($this->formats[$format]['default'])) {
         $format = $this->formats[$format]['default'];
     }
     $intlDateFormatter = new IntlDateFormatter($locale, IntlDateFormatter::FULL, IntlDateFormatter::FULL, $date->getTimezone()->getName(), null, $format);
     return $intlDateFormatter->format($date);
 }
コード例 #2
0
 /**
  * @param array $options
  *
  * @return mixed
  */
 private function getNodeChildren(array $options)
 {
     /** @noinspection PhpUnusedParameterInspection */
     $options = (new OptionsResolver())->setDefaults(['depth' => 1, 'refName' => null, 'parent' => null, 'lang' => $this->currentLocale->getCurrentLocale(), 'include_root' => false, 'include_hidden' => false, 'include_offline' => false, 'flatten' => false, 'limit' => 0])->setNormalizer('refName', function ($options, $value) {
         return $value ? (array) $value : [];
     })->setAllowedTypes('parent', ['null', Node::class])->setAllowedTypes('depth', 'integer')->setAllowedTypes('limit', 'integer')->setAllowedTypes('include_root', 'bool')->setAllowedTypes('include_hidden', 'bool')->setAllowedTypes('flatten', 'bool')->resolve($options);
     $qb = $this->nodeRepository->createQueryBuilder('node')->leftJoin('node.nodeTranslations', 'nt', Join::WITH, 'nt.node = node and nt.lang = :lang')->leftJoin('nt.publicNodeVersion', 'nv')->leftJoin('node.parent', 'parent')->select('parent.id as parentId', 'node.id', 'nt.title', 'nt.url', 'nt.lang', 'nv.refId', 'nv.refEntityName', 'node.internalName')->where('nt.lang = :lang')->andWhere('node.deleted = 0')->orderBy('node.lvl, nt.weight')->setParameter('lang', $options['lang']);
     if ($options['limit']) {
         $qb->setMaxResults($options['limit']);
     }
     if (false === $options['include_hidden']) {
         $qb->andWhere('node.hiddenFromNav = 0');
     }
     if (false === $options['include_offline']) {
         $qb->andWhere('nt.online = 1');
     }
     if ($options['refName']) {
         $qb->andWhere('node.refEntityName in (:refName)')->setParameter('refName', $options['refName']);
     }
     $level = 0;
     $nodeId = null;
     if ($options['parent']) {
         /** @var Node $parent */
         $parent = $options['parent'];
         $nodeId = $parent->getId();
         $level = $parent->getLevel();
         $qb->andWhere('node.lft >= :minLeft')->andWhere('node.rgt <= :maxRight')->setParameter('minLeft', $parent->getLeft())->setParameter('maxRight', $parent->getRight());
         if (false === $options['include_root']) {
             $qb->andWhere('node.id != :nodeId')->setParameter('nodeId', $nodeId);
         }
     }
     if ($options['depth']) {
         $qb->andWhere('node.lvl <= :maxLevel')->setParameter('maxLevel', $level + $options['depth']);
     }
     $children = $qb->getQuery()->getResult();
     $flatten = $options['flatten'];
     /** @noinspection PhpInternalEntityUsedInspection */
     return array_reduce($children, function (TreeBuilder $treeBuilder, $item) use($nodeId, $flatten) {
         $branch = new Branch($item['title'], $item['id'], $item['url'], $item['lang'], $item['refId'], $item['refEntityName'], $item['internalName']);
         if ($branch->getNodeId() === $nodeId) {
             $item['parentId'] = null;
         } elseif ($flatten) {
             $item['parentId'] = $nodeId;
         }
         return $treeBuilder->add($item['parentId'], $branch);
     }, new TreeBuilder())->getRoot();
 }
コード例 #3
0
 private function getValueId($value)
 {
     if ($value instanceof HasNodeInterface) {
         return $value->getId();
     } elseif ($value instanceof HasRefInterface) {
         return $value->getRefId();
     } elseif ($value instanceof NodeVersion) {
         return $value->getRefId();
     } elseif ($value instanceof NodeTranslation) {
         $nodeVersion = $value->getPublicNodeVersion();
         return $nodeVersion ? $nodeVersion->getRefId() : null;
     } elseif ($value instanceof Node) {
         $nodeTranslation = $value->getNodeTranslation($this->currentLocale->getCurrentLocale(), true);
         return $nodeTranslation ? $nodeTranslation->getPublicNodeVersion()->getRefId() : null;
     }
     return null;
 }
コード例 #4
0
 /**
  * @param Category $category
  * @param string   $lang
  *
  * @return Branch|null
  */
 public function getBranchByCategory(Category $category, $lang = null)
 {
     $this->initNodeVersions();
     $lang = $lang ?: $this->currentLocale->getCurrentLocale();
     $matches = function (Branch $branch) use($category, $lang) {
         return $category->getNodeId() === $branch->getNodeId() && $lang === $branch->getLang();
     };
     return array_reduce($this->branches, function (Branch $result = null, Branch $branch) use($matches) {
         return $matches($branch) ? $branch : $result;
     });
 }
コード例 #5
0
 public function configureOptions(OptionsResolver $resolver)
 {
     parent::configureOptions($resolver);
     $resolver->setDefaults(['advanced_select' => true, 'root_node' => function (Options $options) {
         return $this->domainConfiguration->getRootNode();
     }, 'lang' => function (Options $options) {
         return $this->currentLocale->getCurrentLocale();
     }, 'class' => function (Options $options) {
         return $this->contentTypeService->getContentTypeClass($options['page_name']);
     }, 'query_builder' => function (Options $options) {
         /** @var QueryBuilder $qb */
         $qb = $options['em']->getRepository($options['class'])->createQueryBuilder('e');
         $node = $options['root_node'];
         if ($node instanceof Node) {
             $qb->setParameters(['left' => $node->getLeft(), 'right' => $node->getRight()]);
         }
         $qb->setParameter('lang', $options['lang']);
         return $qb;
     }, 'empty_value' => ' ', 'required' => false]);
     $resolver->setAllowedTypes('root_node', ['null', Node::class]);
     $resolver->setRequired('page_name');
 }
コード例 #6
0
 /**
  * @param int|null $offset
  * @param int|null $size
  * @return \Elastica\ResultSet
  */
 public function search($offset = null, $size = null)
 {
     $this->language = $this->currentLocale->getCurrentLocale();
     return parent::search($offset, $size);
 }