setHydrationMode example

$builder = $this->filterListQuery($builder$filters);
        $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 */
$documentType = (int) $this->Request()->getParam('documentType');

        // Needs to be called this early since $this->createDocument boots the         // shop, the order was made in, and thereby destroys the backend session         $translationComponent = $this->get(Shopware_Components_Translation::class);

        if ($orderId !== 0 && $documentType !== 0) {
            $this->createDocument($orderId$documentType);
        }

        $query = $this->getRepository()->getOrdersQuery([['property' => 'orders.id', 'value' => $orderId]], null, 0, 1);
        $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);
        $order = iterator_to_array($this->getModelManager()->createPaginator($query));

        $order = $translationComponent->translateOrders($order);

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

    /** * Fires when the user want to open a generated order document from the backend order module. * Returns the created pdf file. * * @return void */
return 0;
    }

    /** * Handles cleaning process and returns the number of deleted media objects */
    private function handleCleanup(SymfonyStyle $io): int
    {
        $em = $this->getContainer()->get(ModelManager::class);

        $query = $em->getRepository(Media::class)->getAlbumMediaQuery(Album::ALBUM_GARBAGE);
        $query->setHydrationMode(AbstractQuery::HYDRATE_OBJECT);

        $count = (int) $em->getQueryCount($query);
        $iterableResult = $query->toIterable();

        $progressBar = $io->createProgressBar($count);

        try {
            foreach ($iterableResult as $key => $media) {
                $em->remove($media);
                if ($key % 100 === 0) {
                    $em->flush();
                    
$builder = $this->getListQuery();

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

        /** @var Query<CustomerModel|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 customer data         $customers = iterator_to_array($paginator);

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

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

        $query = $this->getRepository()->getListGroupsQuery($criteria$orderBy$limit$offset);
        $query->setHydrationMode($this->resultMode);

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

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

        // Returns the property groups data         $propertyGroups = iterator_to_array($paginator);

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

    
return $query;
    }

    /** * {@inheritdoc} */
    protected function getQueryPaginator(QueryBuilder $builder$hydrationMode = AbstractQuery::HYDRATE_ARRAY)
    {
        /** @var Query<AddressModel> $query */
        $query = $builder->getQuery();
        $query->setHydrationMode($hydrationMode);
        $query->setHint(Query::HINT_INCLUDE_META_COLUMNS, true);

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

    /** * {@inheritdoc} */
    protected function getDetailQuery($id)
    {
        $query = parent::getDetailQuery($id);

        
/** * @throws ORMException * @throws OptimisticLockException * @throws ORMInvalidArgumentException * * @return void */
    public function emptyTrashAction()
    {
        $em = $this->get(ModelManager::class);
        $query = $em->getRepository(Media::class)->getAlbumMediaQuery(Album::ALBUM_GARBAGE);
        $query->setHydrationMode(AbstractQuery::HYDRATE_OBJECT);

        foreach ($query->toIterable() as $key => $media) {
            $em->remove($media);
            if ($key % 100 === 0) {
                $em->flush();
                $em->clear();
            }
        }
        $em->flush();
        $em->clear();

        
'article.id as articleId',
                '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);

            
$filter = $this->Request()->getParam('filter');
        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);
        }

        

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

        /** @var Query<MediaModel|array<string, mixed>> $query */
        $query = $this->getRepository()->getMediaListQuery($criteria$orderBy$limit$offset);
        $query->setHydrationMode($this->resultMode);

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

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

        // Returns the category data         $media = iterator_to_array($paginator);

        $mediaService = Shopware()->Container()->get(MediaServiceInterface::class);
        array_walk($mediafunction D&$item) use ($mediaService) {
            
$builder = $this->getRepository()->createQueryBuilder('user')
            ->join('user.role', 'role')
            ->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']);
            }
        }

        


        if ($sort !== null) {
            $builder->addOrderBy($sort);
        }

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

        /** @var Query<array<string, mixed>> $query */
        $query = $builder->getQuery();
        $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);
        $paginator = $this->getModelManager()->createPaginator($query);
        $total = $paginator->count();
        $orders = iterator_to_array($paginator);

        // Translate payment and dispatch method names.         $translationComponent = $this->get(Shopware_Components_Translation::class);
        $orders = $translationComponent->translateOrders($orders);

        $this->View()->assign([
            'success' => true,
            'data' => $orders,
            

    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']
            );
        }

        

    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 */

        }
    }

    /** * @param Query<Template> $query * * @return Paginator<Template> */
    private function getQueryPaginator(Query $query): Paginator
    {
        $query->setHydrationMode(AbstractQuery::HYDRATE_ARRAY);

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

    /** * Collects all media related x_types which needs to be normalized * * @return array<string> */
    private function getMediaXTypes(): array
    {
        
Home | Imprint | This part of the site doesn't use cookies.