function let(DocumentManager $manager, ChannelInterface $ecommerce, ChannelInterface $mobile, LocaleInterface $enUs, LocaleInterface $frFr, CategoryInterface $category, ChannelRepositoryInterface $channelRepository, CategoryRepositoryInterface $categoryRepository, ProductRepository $productRepository, QueryBuilder $ormQb, Builder $odmQb, Query $odmQuery, OrmQuery $ormQuery, Cursor $cursor)
 {
     $enUs->getCode()->willReturn('en_US');
     $frFr->getCode()->willReturn('fr_FR');
     $ecommerce->getCode()->willReturn('ecommerce');
     $ecommerce->getLabel()->willReturn('ECommerce');
     $ecommerce->getLocales()->willReturn([$enUs, $frFr]);
     $ecommerce->getCategory()->willReturn($category);
     $mobile->getCode()->willReturn('mobile');
     $mobile->getLabel()->willReturn('Mobile');
     $mobile->getLocales()->willReturn([$enUs]);
     $mobile->getCategory()->willReturn($category);
     $odmQuery->execute()->willReturn($cursor);
     $productRepository->createQueryBuilder()->willReturn($odmQb);
     $odmQb->hydrate(Argument::any())->willReturn($odmQb);
     $odmQb->field(Argument::any())->willReturn($odmQb);
     $odmQb->in(Argument::any())->willReturn($odmQb);
     $odmQb->equals(Argument::any())->willReturn($odmQb);
     $odmQb->select('_id')->willReturn($odmQb);
     $odmQb->getQuery()->willReturn($odmQuery);
     $categoryRepository->getAllChildrenIds($category, true)->willReturn([1, 2, 3]);
     $channelRepository->findAll()->willReturn([$ecommerce, $mobile]);
     $manager->getRepository('pim_product_class')->willReturn($productRepository);
     $this->beConstructedWith($manager, $channelRepository, $categoryRepository, 'pim_product_class');
 }
 /**
  * {@inheritdoc}
  */
 public function buildByChannelAndCompleteness(ChannelInterface $channel)
 {
     $qb = $this->createQueryBuilder('p');
     foreach ($channel->getLocales() as $locale) {
         $qb->addOr($qb->expr()->field(sprintf('normalizedData.completenesses.%s-%s', $channel->getCode(), $locale->getCode()))->equals(100));
     }
     $categoryIds = $this->categoryRepository->getAllChildrenIds($channel->getCategory());
     $qb->addAnd($qb->expr()->field('categoryIds')->in($categoryIds));
     return $qb;
 }
 /**
  * Get children category ids
  *
  * @param integer[] $categoryIds
  *
  * @return integer[]
  */
 protected function getAllChildrenIds(array $categoryIds)
 {
     $allChildrenIds = [];
     foreach ($categoryIds as $categoryId) {
         $category = $this->categoryRepository->find($categoryId);
         $childrenIds = $this->categoryRepository->getAllChildrenIds($category);
         $childrenIds[] = $category->getId();
         $allChildrenIds = array_merge($allChildrenIds, $childrenIds);
     }
     return $allChildrenIds;
 }
 /**
  * {@inheritdoc}
  */
 public function getCompleteProductsCountPerChannels()
 {
     $channels = $this->channelRepository->findAll();
     $productRepo = $this->documentManager->getRepository($this->productClass);
     $productsCount = [];
     foreach ($channels as $channel) {
         $category = $channel->getCategory();
         $categoryIds = $this->categoryRepository->getAllChildrenIds($category, true);
         foreach ($channel->getLocales() as $locale) {
             $data = [];
             $compSuffix = $channel->getCode() . '-' . $locale->getCode();
             $localeCount = $productRepo->createQueryBuilder()->hydrate(false)->field('categoryIds')->in($categoryIds)->field('enabled')->equals(true)->field('normalizedData.completenesses.' . $compSuffix)->equals(100)->select('_id')->getQuery()->execute()->count();
             $data['locale'] = $locale->getCode();
             $data['label'] = $channel->getLabel();
             $data['total'] = $localeCount;
             $productsCount[] = $data;
         }
     }
     return $productsCount;
 }
 /**
  * {@inheritdoc}
  */
 public function getItemsCountInCategory(CategoryInterface $category, $inChildren = false, $inProvided = true)
 {
     $categoryIds = $inChildren ? $this->categoryRepository->getAllChildrenIds($category, $inProvided) : [$category->getId()];
     return $this->itemRepository->getItemsCountInCategory($categoryIds);
 }
 /**
  * Get children category ids
  *
  * @param CategoryInterface $category
  *
  * @return integer[]
  */
 protected function getAllChildrenIds(CategoryInterface $category)
 {
     $categoryIds = $this->categoryRepo->getAllChildrenIds($category);
     return $categoryIds;
 }