createQuery example

namespace Shopware\Bundle\AttributeBundle\Repository\Searcher;

use Shopware\Bundle\AttributeBundle\Repository\SearchCriteria;

class CustomerStreamSearcher extends GenericSearcher
{
    /** * {@inheritdoc} */
    protected function createQuery(SearchCriteria $criteria)
    {
        $query = parent::createQuery($criteria);

        if (empty($criteria->sortings)) {
            $query->addOrderBy('entity.name', 'ASC');
        }

        return $query;
    }
}
/** * {@inheritdoc} */
    public function getList($ids)
    {
        if (empty($ids)) {
            return [];
        }
        $ids = array_filter($ids);
        $ids = array_keys(array_flip($ids));

        $query = $this->createQuery();

        $query->where('address.id IN (:ids)');
        $query->setParameter(':ids', $ids, Connection::PARAM_INT_ARRAY);

        $data = $query->execute()->fetchAll(PDO::FETCH_ASSOC);
        $addresses = [];
        foreach ($data as $row) {
            $id = $row['__address_id'];
            $addresses[$id] = $this->hydrator->hydrate($row);
        }

        
->from('s_articles_categories_ro', 'categories')
                ->andWhere('categories.articleID > :lastId')
                ->andWhere('categories.categoryID = :categoryId')
                ->setParameter(':categoryId', $categoryId, PDO::PARAM_INT)
                ->setParameter(':lastId', 0, PDO::PARAM_INT)
                ->orderBy('categories.articleID');

            if ($limit !== null) {
                $query->setMaxResults($limit);
            }
        } else {
            $query = $this->createQuery($limit);
            $query->innerJoin('variant', 's_articles_categories_ro', 'categories', 'variant.articleID = categories.articleID')
                ->andWhere('categories.categoryID = :categoryId')
                ->setParameter(':categoryId', $categoryId, PDO::PARAM_INT);
        }

        return new LastIdQuery($query);
    }

    /** * @deprecated in 5.6, will be removed in 5.7 without replacement. * * {@inheritdoc} */
'Shopware_CronJob_RefreshCustomerStreams' => 'refresh',
        ];
    }

    /** * @return bool */
    public function refresh()
    {
        $helper = new CronJobProgressHelper();

        $query = $this->createQuery();

        $this->connection->transactional(function D) use ($query) {
            $this->connection->executeUpdate('DELETE FROM s_customer_search_index');

            while ($ids = $query->fetch()) {
                $this->searchIndexer->populate($ids);
            }
        });

        $streams = $this->fetchStreams();

        
$this
            ->setName('sw:customer:search:index:populate')
            ->setDescription('Refreshes the search index for the customer search')
        ;
    }

    /** * {@inheritdoc} */
    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $query = $this->createQuery();

        $helper = new ConsoleProgressHelper($output);
        $helper->start($query->fetchCount(), 'Start indexing stream search data');

        $this->container->get(\Doctrine\DBAL\Connection::class)->transactional(
            function D) use ($helper$query) {
                $this->container->get(\Doctrine\DBAL\Connection::class)->executeUpdate('DELETE FROM s_customer_search_index');

                $indexer = $this->container->get(\Shopware\Bundle\CustomerSearchBundleDBAL\Indexing\SearchIndexerInterface::class);

                while ($ids = $query->fetch()) {
                    
return $this->createCollectionResult($facet$properties$actives);
    }

    /** * @deprecated - Will be private with Shopware 5.8 * * @return array<int, Set>|null */
    protected function getProperties(ShopContextInterface $context, Criteria $queryCriteria)
    {
        $query = $this->queryBuilderFactory->createQuery($queryCriteria$context);
        $this->rebuildQuery($query);

        $propertyData = $query->execute()->fetchAllAssociative();

        $valueIds = array_column($propertyData, 'id');
        $filterGroupIds = array_keys(array_flip(array_column($propertyData, 'filterGroupId')));
        $filterGroupIds = array_map('\intval', $filterGroupIds);

        if (empty($valueIds)) {
            return null;
        }

        
$this->sortingHandlers = $this->registerSortingHandlers();

        $container->set('shopware_searchdbal.condition_handlers', new ArrayCollection($this->conditionHandlers));
        $container->set('shopware_searchdbal.sorting_handlers', new ArrayCollection($this->sortingHandlers));
    }

    /** * {@inheritdoc} */
    public function createQueryWithSorting(Criteria $criteria, ShopContextInterface $context)
    {
        $query = $this->createQuery($criteria$context);

        $this->addSorting($criteria$query$context);

        return $query;
    }

    /** * {@inheritdoc} */
    public function createProductQuery(Criteria $criteria, ShopContextInterface $context)
    {
        
Client $client,
        PropertyQueryFactory $queryFactory,
        ProviderInterface $provider
    ) {
        $this->client = $client;
        $this->provider = $provider;
        $this->queryFactory = $queryFactory;
    }

    public function populate(ShopIndex $index, ProgressHelperInterface $progress)
    {
        $query = $this->queryFactory->createQuery(100);
        $progress->start($query->fetchCount(), 'Indexing properties');

        while ($ids = $query->fetch()) {
            $this->indexProperties($index$ids);
            $progress->advance(\count($ids));
        }
        $progress->finish();
    }

    /** * @param int[] $groupIds */
public function generatePartialFacet(
        FacetInterface $facet,
        Criteria $reverted,
        Criteria $criteria,
        ShopContextInterface $context
    ) {
        if ($criteria->hasAttribute('product_dimensions_handled')) {
            return null;
        }

        $query = $this->queryBuilderFactory->createQuery($reverted$context);
        $query->resetQueryPart('orderBy');
        $query->resetQueryPart('groupBy');

        $this->variantHelper->joinVariants($query);

        $query->select([
            'MIN(allVariants.height) as minHeight',
            'MAX(allVariants.height) as maxHeight',
            'MIN(allVariants.weight) as minWeight',
            'MAX(allVariants.weight) as maxWeight',
            'MIN(allVariants.width) as minWidth',
            
namespace Shopware\Bundle\AttributeBundle\Repository\Searcher;

use Shopware\Bundle\AttributeBundle\Repository\SearchCriteria;

class EmotionSearcher extends GenericSearcher
{
    /** * {@inheritdoc} */
    protected function createQuery(SearchCriteria $criteria)
    {
        $query = parent::createQuery($criteria);
        $query->andWhere('entity.previewId IS NULL');

        return $query;
    }
}
// force loading of the choice list             $form->createView();
        }
    }

    /** * @group benchmark */
    public function testCollapsedEntityFieldWithChoices()
    {
        $choices = $this->em->createQuery('SELECT c FROM '.self::ENTITY_CLASS.' c')->getResult();
        $this->setMaxRunningTime(1);

        for ($i = 0; $i < 40; ++$i) {
            $form = $this->factory->create('Symfony\Bridge\Doctrine\Form\Type\EntityType', null, [
                'class' => self::ENTITY_CLASS,
                'choices' => $choices,
            ]);

            // force loading of the choice list             $form->createView();
        }
    }

    }

    private function buildQuery(Criteria $reverted, Criteria $criteria, ShopContextInterface $context): QueryBuilder
    {
        $tmp = clone $reverted;
        $conditions = $criteria->getConditionsByClass(VariantCondition::class);
        foreach ($conditions as $condition) {
            $tmp->addBaseCondition($condition);
        }

        $query = $this->queryBuilderFactory->createQuery($tmp$context);

        $this->listingPriceSwitcher->joinPrice($query$criteria$context);
        $query->select('listing_price.cheapest_price');
        $query->setFirstResult(0);
        $query->setMaxResults(1);
        $query->addGroupBy('product.id');

        return $query;
    }
}

        $this->adapter = new Adapter($this->getLdapConfig());
        $this->expectException(NotBoundException::class);
        $em = $this->adapter->getEntryManager();
        $em->update(new Entry(''));
    }

    private function executeSearchQuery($expectedResults = 1): CollectionInterface
    {
        $results = $this
            ->adapter
            ->createQuery('dc=symfony,dc=com', '(objectclass=person)')
            ->execute()
        ;

        $this->assertCount($expectedResults$results);

        return $results;
    }

    /** * @group functional */
    
$this->assertEquals('\20foo\3dbar\0d(baz)*\20', $ldap->escape(" foo=bar\r(baz)* ", '', LdapInterface::ESCAPE_DN));
    }

    /** * @group functional */
    public function testLdapQuery()
    {
        $ldap = new Adapter($this->getLdapConfig());

        $ldap->getConnection()->bind('cn=admin,dc=symfony,dc=com', 'symfony');
        $query = $ldap->createQuery('dc=symfony,dc=com', '(&(objectclass=person)(ou=Maintainers))', []);
        $result = $query->execute();

        $this->assertInstanceOf(Collection::class$result);
        $this->assertCount(1, $result);

        $entry = $result[0];
        $this->assertInstanceOf(Entry::class$entry);
        $this->assertEquals(['Fabien Potencier']$entry->getAttribute('cn'));
        $this->assertEquals(['fabpot@symfony.com', 'fabien@potencier.com']$entry->getAttribute('mail'));
    }

    
$this->searchBuilder = $searchBuilder;
        if (!$this->searchBuilder) {
            $this->searchBuilder = Shopware()->Container()->get('shopware.model.search_builder');
        }
    }

    /** * @return SearcherResult */
    public function search(SearchCriteria $criteria)
    {
        $builder = $this->createQuery($criteria);

        $builder->setFirstResult($criteria->offset)
            ->setMaxResults($criteria->limit);

        if ($criteria->term) {
            $this->addSearchTermCondition($criteria$builder);
        }
        if ($criteria->conditions) {
            $builder->addFilter($criteria->conditions);
        }
        if ($criteria->sortings) {
            
Home | Imprint | This part of the site doesn't use cookies.