function let(DocumentManager $manager, Channel $ecommerce, Channel $mobile, Locale $enUs, Locale $frFr, CategoryInterface $category, ChannelManager $channelManager, CategoryRepository $categoryRepository, ProductRepository $productRepository, QueryBuilder $ormQb, Builder $odmQb, Query $odmQuery, Cursor $cursor)
 {
     $enUs->getCode()->willReturn('en_US');
     $frFr->getCode()->willReturn('fr_FR');
     $ecommerce->getCode()->willReturn('ecommerce');
     $ecommerce->getLabel()->willReturn('ECommerce');
     $ecommerce->getLocales()->willReturn(array($enUs, $frFr));
     $ecommerce->getCategory()->willReturn($category);
     $mobile->getCode()->willReturn('mobile');
     $mobile->getLabel()->willReturn('Mobile');
     $mobile->getLocales()->willReturn(array($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->getAllChildrenQueryBuilder($category, true)->willReturn($ormQb);
     $categoryRepository->getCategoryIds($category, $ormQb)->willReturn(array(1, 2, 3));
     $channelManager->getFullChannels()->willReturn(array($ecommerce, $mobile));
     $manager->getRepository('pim_product_class')->willReturn($productRepository);
     $this->beConstructedWith($manager, $channelManager, $categoryRepository, 'pim_product_class');
 }
 /**
  * Returns an array containing the locale values
  *
  * @param Channel $channel
  *
  * @return array
  */
 protected function normalizeLocales(Channel $channel)
 {
     $locales = array();
     foreach ($channel->getLocales() as $locale) {
         $locales[] = $locale->getCode();
     }
     return $locales;
 }
    /**
     * Get the deleted locales of a channel (the channel is updated but not flushed yet).
     *
     * @param Channel $channel
     *
     * @return array the list of deleted locales
     */
    public function getDeletedLocalesForChannel(Channel $channel)
    {
        $currentLocaleIds = array_map(function ($locale) {
            return $locale->getId();
        }, $channel->getLocales()->toArray());
        $dql = <<<DQL
            SELECT l
            JOIN l.channels c
            WHERE c.id = :channel_id
              AND l.id NOT IN (:current_locale_ids)
DQL;
        $query = $this->getEntityManager()->createQuery($dql)->setParameter(':channel_id', $channel->getId())->setParameter(':current_locale_ids', implode(',', $currentLocaleIds));
        return $query->getResult();
    }
    /**
     * Get the deleted locales of a channel (the channel is updated but not flushed yet).
     *
     * @param Channel $channel
     *
     * @return array the list of deleted locales
     */
    public function getDeletedLocaleIdsForChannel(Channel $channel)
    {
        $currentLocaleIds = array_map(function ($locale) {
            return $locale->getId();
        }, $channel->getLocales()->toArray());
        $sql = <<<SQL
    SELECT cl.locale_id
    FROM pim_catalog_channel_locale cl
    WHERE cl.channel_id = :channel_id
      AND cl.locale_id NOT IN (:current_locale_ids)
SQL;
        $stmt = $this->getEntityManager()->getConnection()->executeQuery($sql, array(':channel_id' => $channel->getId(), ':current_locale_ids' => $currentLocaleIds), array(':current_locale_ids' => Connection::PARAM_INT_ARRAY));
        $rows = $stmt->fetchAll();
        $locales = array_map(function ($row) {
            return (int) $row['locale_id'];
        }, $rows);
        return $locales;
    }
 /**
  * Test getter/add/remove/has for locale property
  */
 public function testGetAddRemoveHasLocale()
 {
     $this->assertCount(0, $this->channel->getLocales());
     // assert adding the right entity
     $expectedLocaleFR = $this->createLocale('fr_FR');
     $this->assertEntity($this->channel->addLocale($expectedLocaleFR));
     $this->assertCount(1, $this->channel->getLocales());
     $locale = $this->channel->getLocales()->first();
     $this->assertEquals($expectedLocaleFR, $locale);
     // assert removing the right entity
     $expectedLocaleEN = $this->createLocale('en_US');
     $this->channel->addLocale($expectedLocaleEN);
     $this->assertCount(2, $this->channel->getLocales());
     $this->assertEntity($this->channel->removeLocale($expectedLocaleFR));
     $this->assertCount(1, $this->channel->getLocales());
     $locale = $this->channel->getLocales()->first();
     $this->assertEquals($expectedLocaleEN, $locale);
     // assert add an already defined locale
     $this->channel->addLocale($expectedLocaleEN);
     $this->assertCount(1, $this->channel->getLocales());
     // assert if a channel has a locale
     $this->assertTrue($this->channel->hasLocale($expectedLocaleEN));
     $this->assertFalse($this->channel->hasLocale($expectedLocaleFR));
 }
 function it_generates_localizable_indexes_when_saving_enabled_locale($collection, $namingUtility, AbstractAttribute $description, Locale $en_US, Locale $de_DE, Channel $ecommerce)
 {
     $description->getCode()->willReturn('description');
     $description->getBackendType()->willReturn('varchar');
     $description->isLocalizable()->willReturn(true);
     $description->isScopable()->willReturn(false);
     $description->isUseableAsGridFilter()->willReturn(true);
     $description->getAttributeType()->willReturn('pim_catalog_text');
     $en_US->getCode()->willReturn('en_US');
     $en_US->isActivated()->willReturn(true);
     $de_DE->getCode()->willReturn('de_DE');
     $de_DE->isActivated()->willReturn(true);
     $ecommerce->getCode()->willReturn('ecommerce');
     $ecommerce->getLocales()->willReturn([$en_US, $de_DE]);
     $namingUtility->getChannels()->willReturn([$ecommerce]);
     $namingUtility->getLocalizableAttributes()->willReturn([$description]);
     $namingUtility->getAttributeNormFields($description)->willReturn(['normalizedData.description-en_US', 'normalizedData.description-de_DE']);
     $options = ['background' => true, 'w' => 0];
     $collection->ensureIndex(['normalizedData.completenesses.ecommerce-en_US' => 1], $options)->shouldBeCalled();
     $collection->ensureIndex(['normalizedData.completenesses.ecommerce-de_DE' => 1], $options)->shouldBeCalled();
     $collection->ensureIndex(['normalizedData.description-en_US' => 1], $options)->shouldBeCalled();
     $collection->ensureIndex(['normalizedData.description-de_DE' => 1], $options)->shouldBeCalled();
     $this->ensureIndexesFromLocale($en_US);
 }
 /**
  * Remove channel
  *
  * @param Request $request
  * @param Channel $channel
  *
  * @AclAncestor("pim_enrich_channel_remove")
  * @return Response
  */
 public function removeAction(Request $request, Channel $channel)
 {
     $channelCount = $this->getRepository('PimCatalogBundle:Channel')->countAll();
     if ($channelCount <= 1) {
         throw new DeleteException($this->getTranslator()->trans('flash.channel.not removable'));
     }
     foreach ($channel->getLocales() as $locale) {
         $locale->removeChannel($channel);
     }
     $this->channelRemover->remove($channel);
     if ($request->isXmlHttpRequest()) {
         return new Response('', 204);
     } else {
         return $this->redirect($this->generateUrl('pim_enrich_channel_index'));
     }
 }
 /**
  * {@inheritdoc}
  */
 public function buildByChannelAndCompleteness(Channel $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 the completeness fields for the channel
  *
  * @param Channel $channel
  *
  * @return array
  */
 protected function getCompletenessNormFields(Channel $channel = null)
 {
     $normFields = [];
     $channels = [];
     if (null === $channel) {
         $channels = $this->namingUtility->getChannels();
     } else {
         $channels[] = $channel;
     }
     foreach ($channels as $channel) {
         foreach ($channel->getLocales() as $locale) {
             $normFields[] = sprintf('%s.completenesses.%s-%s', ProductQueryUtility::NORMALIZED_FIELD, $channel->getCode(), $locale->getCode());
         }
     }
     return $normFields;
 }
 /**
  * Generate a list of potential completeness value from existing channel
  * or from the provided channel
  *
  * @param Channel $channel
  *
  * @return array
  */
 protected function getChannelLocaleCombinations(Channel $channel = null)
 {
     $channels = array();
     $combinations = array();
     if (null !== $channel) {
         $channels = [$channel];
     } else {
         $channels = $this->channelManager->getFullChannels();
     }
     foreach ($channels as $channel) {
         $locales = $channel->getLocales();
         foreach ($locales as $locale) {
             $combinations[] = $channel->getCode() . '-' . $locale->getCode();
         }
     }
     return $combinations;
 }
 /**
  * {@inheritDoc}
  */
 public function getLocales()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getLocales', array());
     return parent::getLocales();
 }