Esempio n. 1
0
 /**
  * {@inheritDoc}
  */
 public function switchInstance(InstanceInterface $instance)
 {
     $container = $this->getContainer();
     $container->offsetSet('instance', $instance->getId());
     $url = $this->router->assemble($this->routeMatch->getParams(), ['name' => $this->routeMatch->getMatchedRouteName()]);
     $this->redirect($url);
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function switchInstance(InstanceInterface $instance)
 {
     if (!array_key_exists('HTTP_HOST', (array) $_SERVER)) {
         throw new Exception\RuntimeException(sprintf('Host not set.'));
     }
     $url = $this->router->assemble($this->routeMatch->getParams(), ['name' => $this->routeMatch->getMatchedRouteName()]);
     $hostNames = explode('.', $_SERVER['HTTP_HOST']);
     $tld = $hostNames[count($hostNames) - 2] . "." . $hostNames[count($hostNames) - 1];
     $url = 'http://' . $instance->getSubdomain() . '.' . $tld . $url;
     $this->redirect($url);
 }
Esempio n. 3
0
 public function findTermByName($name, InstanceInterface $instance)
 {
     $className = $this->getClassResolver()->resolveClassName('Term\\Entity\\TermEntityInterface');
     $criteria = ['name' => $name, 'instance' => $instance->getId()];
     $entity = $this->getObjectManager()->getRepository($className)->findOneBy($criteria);
     if (!is_object($entity)) {
         foreach ($this->terms as $term) {
             if ($term->getName() == $name && $term->getInstance() === $instance) {
                 return $term;
             }
         }
     }
     if (!is_object($entity)) {
         throw new TermNotFoundException(sprintf('Term %s with instance %s not found', $name, $instance->getId()));
     }
     // Since we can not search case sensitive in mysql (without side effects) we need to do this manually.
     if ($entity->getName() != $name && strcasecmp($entity->getName(), $name) == 0) {
         $entity->setName($name);
         $this->persist($entity);
         $this->flush($entity);
     }
     return $entity;
 }
 /**
  * @param InstanceInterface $instance
  * @return ContainerInterface[]
  */
 public function findContainersByInstance(InstanceInterface $instance)
 {
     $className = $this->classResolver->resolveClassName($this->interfaces['container']);
     $repository = $this->objectManager->getRepository($className);
     return $repository->findBy(['instance' => $instance->getId()]);
 }
Esempio n. 5
0
 public function findTaxonomyByName($name, InstanceInterface $instance)
 {
     $className = $this->getClassResolver()->resolveClassName('Taxonomy\\Entity\\TaxonomyInterface');
     $type = $this->getTypeManager()->findTypeByName($name);
     $criteria = ['type' => $type->getId(), 'instance' => $instance->getId()];
     $entity = $this->getObjectManager()->getRepository($className)->findOneBy($criteria);
     if (!is_object($entity)) {
         $this->assertGranted('taxonomy.create', $instance);
         /* @var $entity \Taxonomy\Entity\TaxonomyInterface */
         $entity = $this->getClassResolver()->resolve('Taxonomy\\Entity\\TaxonomyInterface');
         $entity->setInstance($instance);
         $entity->setType($type);
         if ($this->getObjectManager()->isOpen()) {
             $this->getObjectManager()->persist($entity);
             $this->getObjectManager()->flush($entity);
         }
     }
     $this->assertGranted('taxonomy.get', $entity);
     return $entity;
 }
Esempio n. 6
0
 public function findShuffledAds(InstanceInterface $instance, $number)
 {
     $sql = 'SELECT * FROM ad WHERE `instance_id` =' . (int) $instance->getId() . ' ORDER BY RAND( ) * frequency DESC LIMIT ' . (int) $number;
     $stmt = $this->getObjectManager()->getConnection()->prepare($sql);
     $stmt->execute();
     $adArray = $stmt->fetchAll();
     $adCollection = array();
     $className = $this->getClassResolver()->resolveClassName('Ads\\Entity\\AdInterface');
     foreach ($adArray as $ad) {
         $addCollection[] = $this->getObjectManager()->getRepository($className)->find($ad['id']);
     }
     if (!empty($addCollection)) {
         return $addCollection;
     } else {
         return null;
     }
 }
Esempio n. 7
0
 public function findCanonicalAlias($alias, InstanceInterface $instance)
 {
     /* @var $entity Entity\AliasInterface */
     $criteria = ['alias' => $alias, 'instance' => $instance->getId()];
     $order = ['timestamp' => 'DESC'];
     $results = $this->getAliasRepository()->findBy($criteria, $order);
     $entity = current($results);
     if (!is_object($entity)) {
         throw new Exception\CanonicalUrlNotFoundException(sprintf('No canonical url found'));
     }
     $canonical = $this->findAliasByObject($entity->getObject());
     if ($canonical !== $entity) {
         $router = $this->getRouter();
         $url = $router->assemble(['alias' => $canonical->getAlias()], ['name' => 'alias']);
         if ($url !== $alias) {
             return $url;
         }
     }
     throw new Exception\CanonicalUrlNotFoundException(sprintf('No canonical url found'));
 }