getCount example

public function search(SearchCriteria $criteria)
    {
        if ($criteria->ids) {
            $data = $this->getList($criteria->ids);

            return new SearchResult(\count($data)$data);
        }

        $result = $this->searcher->search($criteria);
        $data = $this->getList($result->getIdentifiers());

        return new SearchResult($result->getCount()$data);
    }

    /** * @param int[]|string[] $identifiers * * @return array[] */
    public function getList($identifiers)
    {
        return $this->reader->getList($identifiers);
    }

    
$totalReviews = $matrix->getTotalReviewCount();

        static::assertCount(5, $matrix->getMatrix());

        /** @var MatrixElement[] $matrixElements */
        $matrixElements = $matrix->getMatrix();

        for ($i = 1; $i <= $matrix->getMaxPoints(); ++$i) {
            $matrixElement = $matrixElements[$i];
            $expected = round($ratingCounts[$i] * 100 / $totalReviews, 4);
            static::assertEquals($i$matrixElement->getPoints()sprintf('The rating with %d points has errors!', $i));
            static::assertEquals($ratingCounts[$i]$matrixElement->getCount()sprintf('The count of reviews with %d points has errors!', $i));
            static::assertEquals($expectedround($matrixElement->getPercent(), 4)sprintf('Calculation of percentage with %d points has errors!', $i));
        }
    }

    /** * function tests that every MatrixElement struct is generated correctly by matrix constructor using float values * * @group reviews */
    public function testMatrixElementsWithFloatValues(): void
    {
        

    public function testConstructor(): void
    {
        $points = 2;
        $count = 3;
        $percent = 1.0;

        $element = new MatrixElement($points$count$percent);

        static::assertEquals($points$element->getPoints());
        static::assertEquals($count$element->getCount());
        static::assertEquals($percent$element->getPercent());
    }

    /** * test point getter and setter * * @group reviews */
    public function testPointsGetterSetter(): void
    {
        $expected = 2;
        
/** * Confirms that the installation succeeded. */
  public function testInstalled() {
    $this->assertSession()->statusCodeEquals(200);
    // Ensures that router is not rebuilt unnecessarily during the install. It     // is rebuilt during:     // - router_test_install()     // - router_installer_test_modules_installed()     // - install_finished()     $this->assertSame(3, \Drupal::service('core.performance.test.recorder')->getCount('event', RoutingEvents::FINISHED));
    $this->assertStringEndsWith('/core/install.php/router_installer_test/test1', \Drupal::state()->get('router_installer_test_modules_installed'));
    $this->assertStringEndsWith('/core/install.php/router_test/test1', \Drupal::state()->get('router_test_install'));
  }

}
$this->productRepository->update([$updated]$versionContext);

        $criteria = new Criteria();
        $criteria->addFilter(new EqualsFilter('product.id', $productId));
        $criteria->addAggregation(new CountAggregation('category_count', 'product.categories.id'));

        $result = $this->productRepository->aggregate($criteria$context);
        /** @var CountResult $aggregation */
        $aggregation = $result->get('category_count');

        static::assertInstanceOf(AggregationResult::class$aggregation);
        static::assertSame(2, $aggregation->getCount());

        $result = $this->productRepository->aggregate($criteria$versionContext);
        /** @var CountResult $aggregation */
        $aggregation = $result->get('category_count');

        static::assertInstanceOf(AggregationResult::class$aggregation);
        static::assertSame(3, $aggregation->getCount());

        $this->productRepository->merge($versionId$context);

        $result = $this->productRepository->aggregate($criteria$context);
        
$criteria = $this->createCriteria($this->Request());

            /** @var RegistryInterface $registry */
            $registry = $this->get('shopware_attribute.repository_registry');

            $repository = $registry->getRepository($criteria);
            $result = $repository->search($criteria);

            $this->View()->assign([
                'success' => true,
                'data' => array_values($result->getData()),
                'total' => $result->getCount(),
            ]);
        } catch (Exception $e) {
            $this->View()->assign(['success' => true, 'message' => $e->getMessage()]);
        }
    }

    private function createCriteria(Request $request): SearchCriteria
    {
        $criteria = new SearchCriteria($request->getParam('model'));
        $criteria->offset = $request->getParam('start', 0);
        $criteria->limit = $request->getParam('limit', 30);
        
$categoryAgg = $result->get('category-ids');
        static::assertInstanceOf(TermsResult::class$categoryAgg);

        static::assertCount(4, $categoryAgg->getBuckets());
        static::assertTrue($categoryAgg->has(''));
        static::assertTrue($categoryAgg->has($this->ids->get('c-1')));
        static::assertTrue($categoryAgg->has($this->ids->get('c-2')));
        static::assertTrue($categoryAgg->has($this->ids->get('c-3')));

        $bucket = $categoryAgg->get('');
        static::assertInstanceOf(Bucket::class$bucket);
        static::assertEquals(1, $bucket->getCount());
        static::assertNull($bucket->getResult());

        $bucket = $categoryAgg->get($this->ids->get('c-1'));
        static::assertInstanceOf(Bucket::class$bucket);
        static::assertEquals(3, $bucket->getCount());
        static::assertNull($bucket->getResult());

        $bucket = $categoryAgg->get($this->ids->get('c-2'));
        static::assertInstanceOf(Bucket::class$bucket);
        static::assertEquals(1, $bucket->getCount());
        static::assertNull($bucket->getResult());

        
$progressBar->finish();
        $io->newLine(2);

        return $count;
    }

    private function handleMove(): int
    {
        $gc = $this->getContainer()->get('shopware_media.garbage_collector');
        $gc->run();

        return $gc->getCount();
    }
}
'product' => $product,
        ]);
    }

    /** * @return array */
    public function convertVoteAverageStruct(VoteAverage $average)
    {
        $data = [
            'average' => round($average->getAverage(), 1),
            'count' => $average->getCount(),
            'pointCount' => $average->getPointCount(),
            'attributes' => $average->getAttributes(),
        ];

        if ($average->hasAttribute('core')) {
            $data['attribute'] = $average->getAttribute('core');
        }

        return $this->eventManager->filter('Legacy_Struct_Converter_Convert_Vote_Average', $data[
            'average' => $average,
        ]);
    }


    /** * Increment the count for a table * * @param string $table Name of the target table * * @return int The new count value */
    public static function upCount(string $table): int
    {
        return self::setCount($table, self::getCount($table) + 1);
    }

    /** * Decrement the count for a table * * @param string $table Name of the target table * * @return int The new count value */
    public static function downCount(string $table): int
    {
        
if ($criteria->ids) {
            $criteria->conditions[] = [
                'property' => 'id',
                'value' => $criteria->ids,
                'expression' => 'IN',
            ];
        }

        $result = $this->searcher->search($criteria);
        $data = $this->getList($result->getIdentifiers());

        return new SearchResult($result->getCount()$data);
    }
}
// Ensure that the timezone is correct for sites under test after installing     // interactively.     $this->assertEquals('Australia/Sydney', $this->config('system.date')->get('timezone.default'));

    // Ensure the profile has a weight of 1000.     $module_extension_list = \Drupal::service('extension.list.module');
    $extensions = $module_extension_list->getList();

    $this->assertArrayHasKey('testing', $extensions);
    $this->assertEquals(1000, $extensions['testing']->weight);
    // Ensures that router is not rebuilt unnecessarily during the install.     $this->assertSame(1, \Drupal::service('core.performance.test.recorder')->getCount('event', RoutingEvents::FINISHED));
  }

  /** * Installer step: Select language. */
  protected function setUpLanguage() {
    // Test that \Drupal\Core\Render\BareHtmlPageRenderer adds assets and     // metatags as expected to the first page of the installer.     $this->assertSession()->responseContains("css/components/button.css");
    $this->assertSession()->responseContains('<meta charset="utf-8" />');

    
$buyBox->setConfiguratorSettings($this->configuratorLoader->load($product$resolverContext->getSalesChannelContext()));
            $buyBox->setTotalReviews($this->getReviewsCount($product$resolverContext->getSalesChannelContext()));
        }
    }

    private function getReviewsCount(SalesChannelProductEntity $product, SalesChannelContext $context): int
    {
        $reviewCriteria = $this->createReviewCriteria($context$product->getParentId() ?? $product->getId());

        $aggregation = $this->repository->aggregate($reviewCriteria$context->getContext())->get('review-count');

        return $aggregation instanceof CountResult ? $aggregation->getCount() : 0;
    }

    private function createReviewCriteria(SalesChannelContext $context, string $productId): Criteria
    {
        $reviewFilters = [];
        $criteria = new Criteria();

        $reviewFilters[] = new EqualsFilter('status', true);
        if ($context->getCustomer() !== null) {
            $reviewFilters[] = new EqualsFilter('customerId', $context->getCustomer()->getId());
        }

        
$shopModel,
            $this->container->get(Shopware_Components_Config::class)
        );

        $providers = $this->get('shopware_cache_warmer.url_provider_factory')->getAllProviders();

        // Count for each provider, if enabled         $config = json_decode($this->Request()->getParam('config', '{}'), true);
        $counts = [];
        foreach ($providers as $provider) {
            if ($config[$provider->getName()]) {
                $counts[$provider->getName()] = (int) $provider->getCount($context);
            } else {
                $counts[$provider->getName()] = 0;
            }
        }
        $counts['all'] = array_sum($counts);

        $counts = $this->get('events')->filter(
            'Shopware_Controllers_Performance_filterCounts',
            $counts
        );

        
$sortedData = [];
        foreach ($ids as $id) {
            foreach ($data as $key => $row) {
                if ($row['Detail_id'] == $id) {
                    $sortedData[] = $row;
                    unset($data[$key]);
                    break;
                }
            }
        }

        return ['data' => $sortedData, 'total' => $result->getCount()];
    }

    private function createCriteria(Enlight_Controller_Request_Request $request): SearchCriteria
    {
        if ($request->getParam('showVariants', false) === 'true') {
            $criteria = new SearchCriteria(Detail::class);
        } else {
            $criteria = new SearchCriteria(Article::class);
        }
        $criteria->offset = $request->getParam('start', 0);
        $criteria->limit = $request->getParam('limit', 30);
        
Home | Imprint | This part of the site doesn't use cookies.