Example #1
0
 /**
  * @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'];
 }
Example #2
0
 /**
  * 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);
 }
 /**
  * {@inheritDoc}
  */
 public function getVariantChildren()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getVariantChildren', array());
     return parent::getVariantChildren();
 }