/** * @param string $alias * @param Page $entity * * @return mixed */ public function checkUniqueAlias($alias, $entity = null) { $q = $this->createQueryBuilder('e')->select('count(e.id) as alias_count')->where('e.alias = :alias'); $q->setParameter('alias', $alias); if (!empty($entity)) { $parent = $entity->getTranslationParent(); $children = $entity->getTranslationChildren(); if ($parent || count($children)) { //allow same alias among language group $ids = array(); if (!empty($parent)) { $children = $parent->getTranslationChildren(); $ids[] = $parent->getId(); } foreach ($children as $child) { if ($child->getId() != $entity->getId()) { $ids[] = $child->getId(); } } $q->andWhere($q->expr()->notIn('e.id', $ids)); } $parent = $entity->getVariantParent(); $children = $entity->getVariantChildren(); if ($parent || count($children)) { //allow same alias among language group $ids = array(); if (!empty($parent)) { $children = $parent->getVariantChildren(); $ids[] = $parent->getId(); } foreach ($children as $child) { if ($child->getId() != $entity->getId()) { $ids[] = $child->getId(); } } $q->andWhere($q->expr()->notIn('e.id', $ids)); } if ($entity->getId()) { $q->andWhere('e.id != :id'); $q->setParameter('id', $entity->getId()); } } $results = $q->getQuery()->getSingleResult(); return $results['alias_count']; }
/** * PreProcess page slots for public view. * * @deprecated - to be removed in 3.0 * * @param array $slots * @param Page $entity */ private function processSlots($slots, $entity) { /** @var \Mautic\CoreBundle\Templating\Helper\AssetsHelper $assetsHelper */ $assetsHelper = $this->factory->getHelper('template.assets'); /** @var \Mautic\CoreBundle\Templating\Helper\SlotsHelper $slotsHelper */ $slotsHelper = $this->factory->getHelper('template.slots'); $content = $entity->getContent(); foreach ($slots as $slot => $slotConfig) { // backward compatibility - if slotConfig array does not exist if (is_numeric($slot)) { $slot = $slotConfig; $slotConfig = []; } if (isset($slotConfig['type']) && $slotConfig['type'] == 'slideshow') { if (isset($content[$slot])) { $options = json_decode($content[$slot], true); } else { $options = ['width' => '100%', 'height' => '250px', 'background_color' => 'transparent', 'arrow_navigation' => false, 'dot_navigation' => true, 'interval' => 5000, 'pause' => 'hover', 'wrap' => true, 'keyboard' => true]; } // Create sample slides for first time or if all slides were deleted if (empty($options['slides'])) { $options['slides'] = [['order' => 0, 'background-image' => $assetsHelper->getUrl('media/images/mautic_logo_lb200.png'), 'captionheader' => 'Caption 1'], ['order' => 1, 'background-image' => $assetsHelper->getUrl('media/images/mautic_logo_db200.png'), 'captionheader' => 'Caption 2']]; } // Order slides usort($options['slides'], function ($a, $b) { return strcmp($a['order'], $b['order']); }); $options['slot'] = $slot; $options['public'] = true; $renderingEngine = $this->container->get('templating')->getEngine('MauticPageBundle:Page:Slots/slideshow.html.php'); $slotsHelper->set($slot, $renderingEngine->render('MauticPageBundle:Page:Slots/slideshow.html.php', $options)); } elseif (isset($slotConfig['type']) && $slotConfig['type'] == 'textarea') { $value = isset($content[$slot]) ? nl2br($content[$slot]) : ""; $slotsHelper->set($slot, $value); } else { // Fallback for other types like html, text, textarea and all unknown $value = isset($content[$slot]) ? $content[$slot] : ""; $slotsHelper->set($slot, $value); } } $parentVariant = $entity->getVariantParent(); $title = !empty($parentVariant) ? $parentVariant->getTitle() : $entity->getTitle(); $slotsHelper->set('pageTitle', $title); }
/** * Get the variant parent/children * * @param Page $page * * @return array */ public function getVariants(Page $page) { $parent = $page->getVariantParent(); if (!empty($parent)) { $children = $parent->getVariantChildren(); } else { $parent = $page; $children = $page->getVariantChildren(); } if (empty($children)) { $children = array(); } return array($parent, $children); }
/** * Generate URL for a page. * * @param Page $entity * @param bool $absolute * @param array $clickthrough * * @return string */ public function generateUrl($entity, $absolute = true, $clickthrough = []) { // If this is a variant, then get the parent's URL $parent = $entity->getVariantParent(); if ($parent != null) { $entity = $parent; } $slug = $this->generateSlug($entity); return $this->buildUrl('mautic_page_public', ['slug' => $slug], $absolute, $clickthrough); }
/** * {@inheritDoc} */ public function getVariantParent() { $this->__initializer__ && $this->__initializer__->__invoke($this, 'getVariantParent', array()); return parent::getVariantParent(); }