createPaginator example

->addSelect(['attribute'])
            ->leftJoin('user.attribute', 'attribute')
            ->addFilter($criteria)
            ->addOrderBy($orderBy)
            ->setFirstResult($offset)
            ->setMaxResults($limit);

        /** @var Query<UserModel|array<string, mixed>> $query */
        $query = $builder->getQuery();
        $query->setHydrationMode($this->getResultMode());

        $paginator = $this->getManager()->createPaginator($query);

        $users = iterator_to_array($paginator);

        if (!$this->hasPrivilege('create', 'usermanager')
            && !$this->hasPrivilege('update', 'usermanager')) {
            foreach ($users as &$user) {
                unset($user['apiKey']$user['sessionId']$user['password']$user['encoder']);
            }
        }

        return [
            
$builder->where("{$column} LIKE ?1")
                ->setParameter(1, '%' . $queryConfig['filter'] . '%');
        }
        // Ignore empty results; add pagination         $builder->andWhere("{$column} != ''")
            ->setFirstResult($queryConfig['offset'])
            ->setMaxResults($queryConfig['limit']);

        /** @var Query<array<string, mixed>> $query */
        $query = $builder->getQuery();

        $paginator = Shopware()->Models()->createPaginator($query);
        $totalCount = $paginator->count();
        $results = [];

        // Iterate results, do some formatting if needed         foreach ($paginator as $item) {
            $item = array_pop($item);
            if ($item instanceof DateTime) {
                if ($columnType === 'date') {
                    $item = $item->format('Y-m-d');
                } elseif ($columnType === 'datetime') {
                    $item = $item->format('Y-m-d H:i:s');
                }
if (\is_array($filter) && isset($filter[0]['value'])) {
            $filter = $filter[0]['value'];
        }

        if ($dispatchID === null) {
            $dispatchID = $this->Request()->getParam('id');
        }

        $query = $this->getRepository()->getShippingCostsQuery($dispatchID$filter$sort$limit$offset);
        $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);

        $paginator = $this->getModelManager()->createPaginator($query);
        // Returns the total count of the query         $totalResult = $paginator->count();
        $shippingCosts = iterator_to_array($paginator);
        $shippingCosts = $this->convertShippingCostsDates($shippingCosts);

        if ($totalResult > 0) {
            $shippingCosts = $this->translateDispatchMethods($shippingCosts);
        }

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

    
$builder = $this->getRepository()->createQueryBuilder('shop');

        $builder->addFilter($criteria)
                ->addOrderBy($orderBy)
                ->setFirstResult($offset)
                ->setMaxResults($limit);
        /** @var Query<ShopModel|array<string, mixed>> $query */
        $query = $builder->getQuery();
        $query->setHydrationMode($this->resultMode);

        $paginator = $this->getManager()->createPaginator($query);

        // returns the total count of the query         $totalResult = $paginator->count();

        // returns the category data         $shops = iterator_to_array($paginator);

        return ['data' => $shops, 'total' => $totalResult];
    }

    /** * @throws Exception * @throws ValidationException * * @return ShopModel */
->innerJoin('detail.article', 'article')
                ->addFilter($criteria)
                ->addOrderBy($orderBy)
                ->setFirstResult($offset)
                ->setMaxResults($limit);

        /** @var Query<Detail|array<string, mixed>> $query */
        $query = $builder->getQuery();

        $query->setHydrationMode($this->getResultMode());

        $paginator = $this->getManager()->createPaginator($query);

        // Returns the total count of the query         $totalResult = $paginator->count();

        // Returns the product data         $variants = iterator_to_array($paginator);

        if ($this->getResultMode() === self::HYDRATE_ARRAY && !empty($options['considerTaxInput'])) {
            foreach ($variants as &$variant) {
                if (\is_array($variant)) {
                    $variant = $this->considerTaxInput($variant);
                }
->leftJoin('mainDetail.attribute', 'attribute')
            ->addFilter($criteria)
            ->addOrderBy($orderBy)
            ->setFirstResult($offset)
            ->setMaxResults($limit);

        /** @var Query<ProductModel|array<string, mixed>> $query */
        $query = $builder->getQuery();

        $query->setHydrationMode($this->getResultMode());

        $paginator = $this->getManager()->createPaginator($query);

        // Returns the total count of the query         $totalResult = $paginator->count();

        $products = iterator_to_array($paginator);

        if ($this->getResultMode() === self::HYDRATE_ARRAY && !empty($options['language'])) {
            $shop = $this->findEntityByConditions(Shop::class[['id' => $options['language']]]);
            if (!$shop instanceof Shop) {
                throw new ModelNotFoundException(Shop::class$options['language']);
            }

            
'articleDetail.number',
            ]);
            $builder->from(ProductVariant::class, 'articleDetail')
                ->leftJoin('articleDetail.esd', 'esd')
                ->leftJoin('articleDetail.article', 'article')
                ->where('articleDetail.articleId = :articleId')
                ->andWhere('esd.id IS NULL')
                ->setParameter('articleId', $productId);

            $query = $builder->getQuery();
            $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);
            $paginator = $this->getModelManager()->createPaginator($query);

            // returns the total count of the query             $totalResult = $paginator->count();

            // returns the customer data             $result = iterator_to_array($paginator);

            $products = $this->buildListProducts($result);
            $products = $this->getAdditionalTexts($products);
            $result = $this->assignAdditionalText($result$products);

            
/** * @param QueryBuilder $builder * * @return Paginator */
    protected function getPaginator($builder)
    {
        $query = $builder->getQuery();
        $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);

        return $this->get(ModelManager::class)->createPaginator($query);
    }

    /** * @param array[] $data * * @return array[] */
    private function hydrateSearchResult(string $entity, array $data): array
    {
        $data = array_map(static function D$row) {
            if (\array_key_exists('_score', $row) && \array_key_exists(0, $row)) {
                
public function getList(
        $offset = 0,
        $limit = 25,
        array $criteria = [],
        array $orderBy = []
    ) {
        $this->checkPrivilege('read');

        /** @var Query<array<string, mixed>> $query */
        $query = $this->getListQuery($offset$limit$criteria$orderBy)->getQuery();
        $query->setHydrationMode(self::HYDRATE_ARRAY);
        $paginator = $this->getManager()->createPaginator($query);

        $translations = iterator_to_array($paginator);

        foreach ($translations as &$translation) {
            unset($translation['id']);
            $translation['data'] = $this->getTranslationComponent()->unFilterData(
                'article',
                $translation['data']
            );
        }

        
$builder = $this->sortListQuery($builder$sortings);

        if ($offset !== null) {
            $builder->setFirstResult($offset);
        }
        if ($limit !== null) {
            $builder->setMaxResults($limit);
        }
        /** @var Query<array{id: int}> $query */
        $query = $builder->getQuery();
        $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);
        $paginator = $em->createPaginator($query);

        return [
            'total' => $paginator->count(),
            'orders' => iterator_to_array($paginator),
        ];
    }

    /** * @param QueryBuilder $builder * @param array<array{property: string, direction: string}> $sortings * * @return QueryBuilder */
->addFilter($criteria)
            ->addOrderBy($orderBy)
            ->setFirstResult($offset)
                ->setMaxResults($limit)
            ->addSelect(['partial customer.{id,email}'])
            ->leftJoin('orders.customer', 'customer');
        /** @var Query<OrderModel|array<string, mixed>> $query */
        $query = $builder->getQuery();

        $query->setHydrationMode($this->getResultMode());

        $paginator = $this->getManager()->createPaginator($query);

        // Returns the total count of the query         $totalResult = $paginator->count();

        // Returns the order data         $orders = iterator_to_array($paginator);

        foreach ($orders as &$order) {
            if (\is_array($order)) {
                $order['paymentStatusId'] = $order['cleared'];
                $order['orderStatusId'] = $order['status'];
                
 $classMetaData->fieldNames);
    }

    /** * @return SearcherResult */
    protected function createResult(QueryBuilder $builder)
    {
        /** @var Query<array<string, mixed>> $query */
        $query = $builder->getQuery();
        $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);
        $paginator = $this->entityManager->createPaginator($query);
        $result = iterator_to_array($paginator);

        $field = $this->getIdentifierField();
        $field = explode('.', $field);

        return new SearcherResult(
            array_column($result$field[1]),
            $paginator->count()
        );
    }

    

    public function getList($offset = 0, $limit = 25, array $criteria = [], array $orderBy = [])
    {
        $this->checkPrivilege('read');

        $query = $this->getRepository()->getListQuery($criteria$orderBy$limit$offset);
        $query->setHydrationMode(self::HYDRATE_ARRAY);

        $paginator = $this->getManager()->createPaginator($query);

        // Returns the total count of the query         $totalResult = $paginator->count();

        // Returns the address data         $addresses = iterator_to_array($paginator);

        return ['data' => $addresses, 'total' => $totalResult];
    }

    /** * @throws NotFoundException * @throws CustomValidationException * * @return AddressModel */
        $limitStart = ($page - 1) * $perPage;
        $limitEnd = $perPage;

        // Get all blog articles         $query = $this->getCategoryRepository()->getBlogCategoriesByParentQuery($categoryId);
        $blogCategoryIds = array_column($query->getArrayResult(), 'id');
        $blogCategoryIds[] = $categoryId;
        $shopId = (int) $this->get('shop')->getId();
        $blogArticlesQuery = $this->getRepository()->getListQuery($blogCategoryIds$limitStart$limitEnd$filter$shopId);
        $blogArticlesQuery->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);

        $paginator = $this->get('models')->createPaginator($blogArticlesQuery);

        // Returns the total count of the query         $totalResult = $paginator->count();

        // Returns the blog article data         $blogArticles = iterator_to_array($paginator);

        $blogArticles = $this->translateBlogArticles($blogArticles);

        $mediaIds = array_map(function D$blogArticle) {
            if (isset($blogArticle['media']) && $blogArticle['media'][0]['mediaId']) {
                

    protected function getQueryPaginator(QueryBuilder $builder$hydrationMode = AbstractQuery::HYDRATE_ARRAY)
    {
        /** @var Query<TEntityClass|array<string, mixed>> $query */
        $query = $builder->getQuery();
        $query->setHydrationMode($hydrationMode);

        return $this->getManager()->createPaginator($query);
    }

    /** * Helper function which formats the Ext JS search value * to a valid doctrine field value for the passed field. * This function is used to supports different date search strings * like the german and english date format. * Additionally this function adds the sql wildcards at the right points of * the search value. * * @param string $value * @param array{alias?: string, type: string|null} $field * @param string|null $expression * * @return string */
Home | Imprint | This part of the site doesn't use cookies.