createQueryBuilder example

protected function configureQuery(QueryBuilder $builder, ?int $shopId, string $pluginName): QueryBuilder
    {
        return $builder
            ->andWhere($builder->expr()->eq('corePlugins.name', $builder->createNamedParameter($pluginName)))
            ->andWhere($builder->expr()->eq('coreConfigValues.shop_id', $builder->createNamedParameter($shopId)))
        ;
    }

    protected function isLayerResponsible(?int $shopId): bool
    {
        $queryBuilder = $this->connection->createQueryBuilder();

        return $queryBuilder->from('s_core_shops')
            ->select('1')
            ->andWhere($queryBuilder->expr()->eq('id', ':id'))
            ->andWhere($queryBuilder->expr()->isNotNull('main_id'))
            ->setParameter('id', $shopId)
            ->execute()->fetchColumn() !== false
        ;
    }
}
/** * Helper function to create the query builder for the "getListQuery" function. * This function can be hooked to modify the query builder of the query object. * * @param array<array{property: string, direction: string}>|null $orderBy * * @return QueryBuilder */
    public function getListQueryBuilder(?array $orderBy = null)
    {
        /** @var QueryBuilder $builder */
        $builder = $this->getEntityManager()->createQueryBuilder();
        $builder->select(
            [
                'productFeed.id as id',
                'productFeed.name as name',
                'productFeed.active as active',
                'productFeed.fileName as fileName',
                'productFeed.countArticles as countArticles',
                'productFeed.hash as hash',
                'productFeed.lastExport as lastExport',
            ]
        );
        

    public function send(string $body, array $headers, int $delay = 0): string
    {
        $now = new \DateTimeImmutable('UTC');
        $availableAt = $now->modify(sprintf('+%d seconds', $delay / 1000));

        $queryBuilder = $this->driverConnection->createQueryBuilder()
            ->insert($this->configuration['table_name'])
            ->values([
                'body' => '?',
                'headers' => '?',
                'queue_name' => '?',
                'created_at' => '?',
                'available_at' => '?',
            ]);

        $this->executeStatement($queryBuilder->getSQL()[
            $body,
            
 {
        $this->connection = $connection;
        $this->taxHydrator = $taxHydrator;
        $this->fieldHelper = $fieldHelper;
    }

    /** * {@inheritdoc} */
    public function getRules(Group $customerGroup, ?Area $area = null, ?Country $country = null, ?State $state = null)
    {
        $query = $this->connection->createQueryBuilder();
        $query->select($this->fieldHelper->getTaxFields())
            ->from('s_core_tax', 'tax');

        $statement = $query->execute();
        $data = $statement->fetchAll(PDO::FETCH_ASSOC);

        $rules = [];

        $query = $this->getAreaQuery(
            $customerGroup,
            $area,
            
'D - german',
                'H - german',
            ]$names);
        }
    }

    /** * @param string[] $salesChannelIds */
    private function fetchSalesChannelNames(array $salesChannelIds, string $languageId): array
    {
        return $this->connection->createQueryBuilder()
            ->select('name')
            ->from(SalesChannelTranslationDefinition::ENTITY_NAME)
            ->where('sales_channel_id IN (:salesChannelIds)')
            ->andWhere('language_id = :languageId')
            ->setParameter('salesChannelIds', $salesChannelIds, ArrayParameterType::STRING)
            ->setParameter('languageId', $languageId)
            ->addOrderBy('name', 'ASC')
            ->executeQuery()
            ->fetchFirstColumn();
    }

    
protected function queryProperty($modelClass$property$conditionCallback = null)
    {
        $alias = uniqid('modelAlias');

        try {
            $em = $this->getContainer()->get(ModelManager::class);
        } catch (Exception $e) {
            return [];
        }

        $repository = $em->getRepository($modelClass);
        $queryBuilder = $repository->createQueryBuilder($alias);

        if (\is_callable($conditionCallback)) {
            $queryBuilder = \call_user_func($conditionCallback$queryBuilder$alias);
        }

        $result = $queryBuilder->select(["$alias.$property"])
            ->addOrderBy($queryBuilder->expr()->asc("$alias.$property"))
            ->getQuery()
            ->getArrayResult();

        return array_column($result$property);
    }
/** * {@inheritdoc} */
    public function getList($products, ShopContextInterface $context)
    {
        $ids = [];
        foreach ($products as $product) {
            $ids[] = $product->getId();
        }
        $ids = array_unique($ids);

        $query = $this->connection->createQueryBuilder();

        $query->select($this->fieldHelper->getDownloadFields());

        $query->from('s_articles_downloads', 'download')
            ->leftJoin('download', 's_articles_downloads_attributes', 'downloadAttribute', 'downloadAttribute.downloadID = download.id')
            ->innerJoin('download', 's_media', 'media', 'media.path = download.filename')
            ->where('download.articleID IN (:ids)')
            ->setParameter(':ids', $ids, Connection::PARAM_INT_ARRAY);

        $this->fieldHelper->addDownloadTranslation($query$context);

        

    public function getOne($id, array $options = [])
    {
        $this->checkPrivilege('read');

        if (empty($id)) {
            throw new ParameterMissingException('id');
        }

        $builder = $this->getManager()->createQueryBuilder();
        $builder->select([
            'article',
            'mainDetail',
            'mainDetailPrices',
            'tax',
            'propertyValues',
            'configuratorOptions',
            'supplier',
            'priceCustomGroup',
            'mainDetailAttribute',
            'propertyGroup',
            

    private function createDownloadZip(string $content): string
    {
        $file = tempnam(sys_get_temp_dir(), 'plugin_') . '.zip';
        file_put_contents($file$content);

        return $file;
    }

    private function getPluginSource(string $name): string
    {
        $query = $this->connection->createQueryBuilder();
        $query->select(['plugin.source'])
            ->from('s_core_plugins', 'plugin')
            ->where('plugin.name = :name')
            ->setParameter(':name', $name)
            ->setMaxResults(1);

        return (string) $query->execute()->fetchOne();
    }
}

        return [];
    }

    /** * {@inheritdoc} */
    public function completeArgumentValues($argumentName, CompletionContext $context)
    {
        if ($argumentName === 'shopId') {
            $shopRepository = $this->getContainer()->get(ModelManager::class)->getRepository(ShopModel::class);
            $queryBuilder = $shopRepository->createQueryBuilder('shop');

            if (is_numeric($context->getCurrentWord())) {
                $queryBuilder->andWhere($queryBuilder->expr()->like('shop.id', ':id'))
                    ->setParameter('id', addcslashes($context->getCurrentWord(), '%_') . '%');
            }

            $result = $queryBuilder->select(['shop.id'])
                ->addOrderBy($queryBuilder->expr()->asc('shop.id'))
                ->getQuery()
                ->getArrayResult();

            
$this->View()->assign(['success' => true, 'data' => $voucher, 'total' => 1]);
    }

    /** * get the Tax configuration * Used for the backend tax-combobox * * @return void */
    public function getTaxConfigurationAction()
    {
        $builder = $this->getManager()->getRepository(Tax::class)->createQueryBuilder('t');
        $builder->orderBy('t.id', 'ASC');
        $tax = $builder->getQuery()->getArrayResult();

        $this->View()->assign(['success' => true, 'data' => $tax]);
    }

    /** * Creates a new voucher with the passed values * * @return void */
    


        if (!\is_string($templateContentMapping[$locale][$html ? 'html' : 'plain'])) {
            throw new \RuntimeException(\sprintf('Could not MailTemplate data with locale %s', $locale));
        }

        return $templateContentMapping[$locale][$html ? 'html' : 'plain'];
    }

    private function getExistingMailTemplateTypeId(string $technicalName, Connection $connection): ?string
    {
        $result = $connection->createQueryBuilder()
            ->select('id')
            ->from('mail_template_type')
            ->where('technical_name = :technicalName')
            ->setParameter('technicalName', $technicalName)
            ->executeQuery()
            ->fetchOne();

        return $result ?: null;
    }
}
public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }

    /** * {@inheritdoc} */
    public function getLastBacklogId()
    {
        $value = $this->connection->createQueryBuilder()
            ->select('value')
            ->from('s_core_config_elements', 'elements')
            ->where('elements.name = :name')
            ->setParameter(':name', 'lastBacklogId')
            ->setMaxResults(1)
            ->execute()
            ->fetch(PDO::FETCH_COLUMN);

        return (int) unserialize($value['allowed_classes' => false]);
    }

    

        return new LastIdQuery($this->createOptionQuery($limit));
    }

    /** * @param int|null $limit * * @return \Doctrine\DBAL\Query\QueryBuilder */
    private function createOptionQuery($limit = null)
    {
        $query = $this->connection->createQueryBuilder();
        $query->select(['propertyGroups.id', 'propertyGroups.id'])
            ->from('s_filter_options', 'propertyGroups')
            ->where('propertyGroups.id > :lastId')
            ->orderBy('propertyGroups.id', 'ASC')
            ->setParameter(':lastId', 0);

        if ($limit !== null) {
            $query->setMaxResults($limit);
        }

        return $query;
    }
$builder->addOrderBy($criteria->sortings);
        }

        return $this->createResult($builder);
    }

    /** * @return QueryBuilder */
    protected function createQuery(SearchCriteria $criteria)
    {
        $builder = $this->entityManager->createQueryBuilder();
        $builder->select($this->getIdentifierField());
        $builder->from($criteria->entity, 'entity');
        $builder->setAlias('entity');

        return $builder;
    }

    protected function addSearchTermCondition(SearchCriteria $criteria, QueryBuilder $builder)
    {
        $this->searchBuilder->addSearchTerm($builder$criteria->term, $this->getSearchFields($criteria));
    }

    
Home | Imprint | This part of the site doesn't use cookies.