/** * {@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); }
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()]); }
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; }
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; } }
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')); }