fetchStreamsCustomerCount example

$query = $builder->getQuery();
        $query->setHydrationMode(self::HYDRATE_ARRAY);
        $paginator = $this->getManager()->createPaginator($query);
        $total = $paginator->count();
        $data = iterator_to_array($paginator);

        $ids = array_column($data, 'id');
        if (empty($ids)) {
            return ['success' => true, 'data' => [], 'total' => 0];
        }

        $counts = $this->streamRepository->fetchStreamsCustomerCount($ids);

        foreach ($data as &$row) {
            $id = (int) $row['id'];
            if (!\array_key_exists($id$counts)) {
                $row['customer_count'] = 0;
                $row['newsletter_count'] = 0;
            } else {
                $row = array_merge($row$counts[$id]);
            }

            $result = $this->updateFrozenState($id$row['freezeUp']$row['conditions']);
            
public function __construct(string $entity, ModelManager $entityManager, CustomerStreamRepositoryInterface $repository)
    {
        parent::__construct($entity$entityManager);
        $this->repository = $repository;
    }

    public function getList($identifiers)
    {
        $customerStreams = parent::getList($identifiers);

        $identifiers = array_map('\intval', $identifiers);
        $customerAndNewsletterCountByStream = $this->repository->fetchStreamsCustomerCount($identifiers);

        foreach ($customerStreams as &$customerStream) {
            $id = (int) $customerStream['id'];
            if (\array_key_exists($id$customerAndNewsletterCountByStream)) {
                $customerStream = array_merge($customerStream$customerAndNewsletterCountByStream[$id]);
            } else {
                $customerStream['customer_count'] = 0;
                $customerStream['newsletter_count'] = 0;
            }
        }

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