function let(UserContext $userContext, EntityManager $em, ClassMetadata $classMetadata)
 {
     $classMetadata->name = 'group_type';
     $userContext->getCurrentLocaleCode()->willReturn('en_US');
     $em->getClassMetadata('groupTypeClass')->willReturn($classMetadata);
     $this->beConstructedWith($userContext, $em, 'groupTypeClass');
 }
 /**
  * Return the number of unread notifications for the currently logged in user
  *
  * @return int
  */
 public function countNotifications()
 {
     $user = $this->userContext->getUser();
     if (null === $user) {
         return 0;
     }
     return $this->manager->countUnreadForUser($user);
 }
 /**
  * Displays completeness for a product
  *
  * @param int $id
  *
  * @return Response
  */
 public function completenessAction($id)
 {
     $product = $this->productManager->getProductRepository()->getFullProduct($id);
     $channels = $this->channelManager->getFullChannels();
     $locales = $this->userContext->getUserLocales();
     $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $locales, $this->userContext->getCurrentLocale()->getCode());
     return $this->templating->renderResponse('PimEnrichBundle:Completeness:_completeness.html.twig', array('product' => $product, 'channels' => $channels, 'locales' => $locales, 'completenesses' => $completenesses));
 }
Ejemplo n.º 4
0
 /**
  * {@inheritdoc}
  */
 public function getMetadata()
 {
     $metadata = parent::getMetadata();
     $defaultScope = $this->userContext->getUserChannel();
     $metadata['populateDefault'] = false;
     unset($metadata['placeholder']);
     return $metadata;
 }
 function let(SecurityContextInterface $securityContext, AddLocaleListener $listener, CatalogContext $catalogContext, UserContext $userContext, GetResponseEvent $event)
 {
     $securityContext->getToken()->willReturn(true);
     $event->getRequestType()->willReturn(HttpKernel::MASTER_REQUEST);
     $userContext->getCurrentLocaleCode()->willReturn('de_DE');
     $userContext->getUserChannelCode()->willReturn('schmetterling');
     $this->beConstructedWith($securityContext, $listener, $catalogContext, $userContext);
 }
 /**
  * Remove a notification
  *
  * @param integer $id
  *
  * @return JsonResponse
  */
 public function removeAction($id)
 {
     $user = $this->userContext->getUser();
     if (null !== $user) {
         $this->manager->remove($user, $id);
     }
     return new JsonResponse();
 }
Ejemplo n.º 7
0
 /**
  * {@inheritdoc}
  */
 public function findTranslatedLabels(array $options = [])
 {
     $query = $this->createQueryBuilder('f')->select('f.id')->addSelect('COALESCE(NULLIF(ft.label, \'\'), CONCAT(\'[\', f.code, \']\')) as label')->leftJoin('f.translations', 'ft', 'WITH', 'ft.locale = :locale_code')->orderBy('label')->setParameter('locale_code', $this->userContext->getCurrentLocaleCode())->getQuery();
     $choices = [];
     foreach ($query->getArrayResult() as $family) {
         $choices[$family['id']] = $family['label'];
     }
     return $choices;
 }
 /**
  * {@inheritdoc}
  */
 public function finishView(FormView $view, FormInterface $form, array $options)
 {
     $values = null !== $view->vars['value'] ? $view->vars['value']->getValues() : [];
     $view->vars['groups'] = $this->productFormView->getView();
     $view->vars['orderedGroups'] = $this->getOrderedGroups($values);
     $view->vars['locales'] = $this->userContext->getUserLocales();
     $view->vars['channels'] = $this->channelManager->getChannels();
     $view->vars['currentLocale'] = $options['currentLocale'];
 }
 /**
  * Action for product sequential edition
  * @param Request $request
  *
  * @AclAncestor("pim_enrich_product_edit_attributes")
  * @return RedirectResponse
  */
 public function sequentialEditAction(Request $request)
 {
     $sequentialEdit = $this->seqEditManager->createEntity($this->getObjects($request), $this->userContext->getUser());
     if ($this->seqEditManager->findByUser($this->userContext->getUser())) {
         return new RedirectResponse($this->router->generate('pim_enrich_product_index', ['dataLocale' => $request->get('dataLocale')]));
     }
     $this->seqEditManager->save($sequentialEdit);
     return new RedirectResponse($this->router->generate('pim_enrich_product_edit', ['dataLocale' => $request->get('dataLocale'), 'id' => current($sequentialEdit->getObjectSet())]));
 }
 function let(UserContext $userContext, EntityManager $em, ClassMetadata $classMetadata, EventManager $eventManager, TreeListener $treeListener, Nested $strategy)
 {
     $classMetadata->name = 'category';
     $userContext->getCurrentLocaleCode()->willReturn('en_US');
     $em->getEventManager()->willReturn($eventManager);
     $eventManager->getListeners()->willReturn([[$treeListener]]);
     $treeListener->getStrategy(Argument::cetera())->willReturn($strategy);
     $treeListener->getConfiguration(Argument::cetera())->willReturn(['parent' => 'parent', 'left' => 'left']);
     $this->beConstructedWith($userContext, $em, $classMetadata);
 }
 /**
  * List category trees. The select_node_id request parameter
  * allow to send back the tree where the node belongs with a selected
  * attribute
  *
  * @param Request $request
  *
  * @return array
  *
  * @Template
  * @AclAncestor("pim_enrich_category_list")
  */
 public function listTreeAction(Request $request)
 {
     $selectNodeId = $request->get('select_node_id', -1);
     try {
         $selectNode = $this->findCategory($selectNodeId);
     } catch (NotFoundHttpException $e) {
         $selectNode = $this->userContext->getUserTree();
     }
     return array('trees' => $this->categoryManager->getTrees(), 'selectedTreeId' => $selectNode->isRoot() ? $selectNode->getId() : $selectNode->getRoot(), 'include_sub' => (bool) $this->getRequest()->get('include_sub', false), 'product_count' => (bool) $this->getRequest()->get('with_products_count', true), 'related_entity' => $this->getRequest()->get('related_entity', 'product'));
 }
 /**
  * Get completeness for a product
  *
  * @param int $id
  *
  * @return JSONResponse
  */
 public function getAction($id)
 {
     $product = $this->productRepository->getFullProduct($id);
     $this->completenessManager->generateMissingForProduct($product);
     $channels = $this->channelRepository->getFullChannels();
     $locales = $this->userContext->getUserLocales();
     $filteredLocales = $this->collectionFilter->filterCollection($locales, 'pim.internal_api.locale.view');
     $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $filteredLocales, $this->userContext->getCurrentLocale()->getCode());
     return new JsonResponse($this->completenessNormalizer->normalize($completenesses, 'internal_api'));
 }
Ejemplo n.º 13
0
 /**
  * {@inheritdoc}
  */
 public function getMetadata()
 {
     $metadata = parent::getMetadata();
     $defaultScope = $this->userContext->getUserChannel();
     $metadata['populateDefault'] = true;
     $metadata['placeholder'] = $defaultScope->getLabel();
     $metadata['choices'] = array_filter($metadata['choices'], function ($choice) use($defaultScope) {
         return $choice['value'] !== $defaultScope->getCode();
     });
     return $metadata;
 }
 /**
  * {@inheritdoc}
  */
 public function findTranslatedLabels(array $options = [])
 {
     $queryBuilder = $this->createQueryBuilder('g')->select('g.id')->addSelect('COALESCE(NULLIF(t.label, \'\'), CONCAT(\'[\', g.code, \']\')) as label')->leftJoin('g.translations', 't', 'WITH', 't.locale = :locale')->setParameter('locale', $this->userContext->getCurrentLocaleCode())->orderBy('t.label');
     if (isset($options['type'])) {
         $queryBuilder->andWhere('g.type = :type')->setParameter('type', $options['type']);
     }
     $choices = [];
     foreach ($queryBuilder->getQuery()->getArrayResult() as $code) {
         $choices[$code['id']] = $code['label'];
     }
     return $choices;
 }
 function let(ProductBuilder $productBuilder, ProductUpdaterInterface $productUpdater, UserContext $userContext, LocaleInterface $en, LocaleInterface $de, ProductValueInterface $productValue, CatalogContext $catalogContext, ProductMassActionManager $massActionManager, NormalizerInterface $normalizer, BulkSaverInterface $productSaver)
 {
     $en->getCode()->willReturn('en_US');
     $de->getCode()->willReturn('de_DE');
     $userContext->getCurrentLocale()->willReturn($en);
     $userContext->getUserLocales()->willReturn([$en, $de]);
     $catalogContext->setLocaleCode(Argument::any())->willReturn($catalogContext);
     $productValue->setAttribute(Argument::any())->willReturn($productValue);
     $productValue->setLocale(Argument::any())->willReturn($productValue);
     $productValue->setScope(Argument::any())->willReturn($productValue);
     $productValue->addPrice(Argument::any())->willReturn($productValue);
     $this->beConstructedWith($productBuilder, $productUpdater, $userContext, $catalogContext, $massActionManager, $normalizer, $productSaver, ['product_price' => 'Pim\\Bundle\\CatalogBundle\\Model\\ProductPrice', 'product_media' => 'Pim\\Bundle\\CatalogBundle\\Model\\ProductMedia']);
 }
 /**
  * @param BuildAfter $event
  */
 public function onBuildAfter(BuildAfter $event)
 {
     $defaults = $this->context->getUser()->getProductGridFilters();
     if (empty($defaults)) {
         return;
     }
     $configuration = $event->getDatagrid()->getAcceptor()->getConfig();
     foreach ($configuration['filters']['columns'] as $code => $filter) {
         if (in_array($code, $this->disallowed)) {
             continue;
         }
         $configuration->offsetSetByPath(sprintf('%s[%s][enabled]', Configuration::COLUMNS_PATH, $code), in_array($code, $defaults));
     }
 }
 function let(ProductManager $productManager, UserContext $userContext, CurrencyManager $currencyManager, Locale $en, Locale $de, AttributeRepository $attributeRepository, AbstractProductValue $productValue, CatalogContext $catalogContext, ProductBuilder $productBuilder, ProductMassActionManager $massActionManager, MetricFactory $metricFactory)
 {
     $en->getCode()->willReturn('en_US');
     $de->getCode()->willReturn('de_DE');
     $userContext->getCurrentLocale()->willReturn($en);
     $userContext->getUserLocales()->willReturn([$en, $de]);
     $catalogContext->setLocaleCode(Argument::any())->willReturn($catalogContext);
     $productManager->createProductValue()->willReturn($productValue);
     $productValue->setAttribute(Argument::any())->willReturn($productValue);
     $productValue->setLocale(Argument::any())->willReturn($productValue);
     $productValue->setScope(Argument::any())->willReturn($productValue);
     $productValue->addPrice(Argument::any())->willReturn($productValue);
     $productManager->getAttributeRepository()->willReturn($attributeRepository);
     $this->beConstructedWith($productManager, $userContext, $currencyManager, $catalogContext, $productBuilder, $massActionManager, $metricFactory, ['product_price' => 'Pim\\Bundle\\CatalogBundle\\Model\\ProductPrice', 'product_media' => 'Pim\\Bundle\\CatalogBundle\\Model\\ProductMedia']);
 }
 /**
  * {@inheritdoc}
  */
 public function findTranslatedLabels(array $options = [])
 {
     $queryBuilder = $this->createQueryBuilder('a')->select('a.code')->addSelect('COALESCE(NULLIF(at.label, \'\'), CONCAT(\'[\', a.code, \']\')) as attribute_label')->addSelect('COALESCE(NULLIF(gt.label, \'\'), CONCAT(\'[\', g.code, \']\')) as group_label')->leftJoin('a.translations', 'at', 'WITH', 'at.locale = :locale_code')->leftJoin('a.group', 'g')->leftJoin('g.translations', 'gt', 'WITH', 'gt.locale = :locale_code')->orderBy('g.sortOrder, a.sortOrder')->setParameter('locale_code', $this->userContext->getCurrentLocaleCode());
     if (isset($options['excluded_attribute_ids']) && !empty($options['excluded_attribute_ids'])) {
         $queryBuilder->andWhere($queryBuilder->expr()->notIn('a.id', $options['excluded_attribute_ids']));
     }
     if (isset($options['useable_as_grid_filter'])) {
         $queryBuilder->andWhere($queryBuilder->expr()->eq('a.useableAsGridFilter', $options['useable_as_grid_filter']));
     }
     $choices = [];
     foreach ($queryBuilder->getQuery()->getArrayResult() as $attribute) {
         $choices[$attribute['group_label']][$attribute['code']] = $attribute['attribute_label'];
     }
     return $choices;
 }
Ejemplo n.º 19
0
 /**
  * Updates product with the provided request data
  *
  * @param ProductInterface $product
  * @param array            $data
  */
 protected function updateProduct(ProductInterface $product, array $data)
 {
     $values = $this->localizedConverter->convertToDefaultFormats($data['values'], ['locale' => $this->userContext->getUiLocale()->getCode()]);
     $values = $this->emptyValuesFilter->filter($product, $values);
     unset($data['values']);
     $data = array_replace($data, $values);
     $this->productUpdater->update($product, $data);
 }
 /**
  * @param string $id Product id
  *
  * @throws NotFoundHttpException If product is not found or the user cannot see it
  *
  * @return JsonResponse
  */
 public function getAction($id)
 {
     $product = $this->findProductOr404($id);
     $this->productBuilder->addMissingAssociations($product);
     $channels = array_keys($this->userContext->getChannelChoicesWithUserChannel());
     $locales = $this->userContext->getUserLocaleCodes();
     return new JsonResponse($this->normalizer->normalize($product, 'internal_api', ['locales' => $locales, 'channels' => $channels, 'filter_type' => 'pim.internal_api.product_value.view']));
 }
 /**
  * Get completeness for a product
  *
  * @param int|string $id
  *
  * @return JSONResponse
  */
 public function getAction($id)
 {
     $product = $this->productRepository->getFullProduct($id);
     if (null === $product->getFamily()) {
         return new JsonResponse();
     }
     $this->completenessManager->generateMissingForProduct($product);
     // Product have to be refreshed to have the completeness values generated by generateMissingForProduct()
     // (on ORM, completeness is not calculated the same way and product doesn't need to be refreshed)
     if (AkeneoStorageUtilsExtension::DOCTRINE_MONGODB_ODM === $this->storageDriver) {
         $this->productManager->refresh($product);
     }
     $channels = $this->channelRepository->getFullChannels();
     $locales = $this->userContext->getUserLocales();
     $filteredLocales = $this->collectionFilter->filterCollection($locales, 'pim.internal_api.locale.view');
     $completenesses = $this->completenessManager->getProductCompleteness($product, $channels, $filteredLocales);
     return new JsonResponse($this->compNormalizer->normalize($completenesses, 'internal_api'));
 }
 /**
  * Get current scope from datagrid parameters, then user config
  *
  * @return string
  */
 protected function getCurrentScopeCode()
 {
     $filterValues = $this->requestParams->get('_filter');
     if (isset($filterValues['scope']['value']) && $filterValues['scope']['value'] !== null) {
         return $filterValues['scope']['value'];
     } else {
         $channel = $this->userContext->getUser()->getCatalogScope();
         return $channel->getCode();
     }
 }
 /**
  * Remove a notification
  *
  * @param int $id
  *
  * @return JsonResponse
  */
 public function removeAction($id)
 {
     $user = $this->userContext->getUser();
     if (null !== $user) {
         $notification = $this->userNotifRepository->findOneBy(['id' => $id, 'user' => $user]);
         if ($notification) {
             $this->userNotifRemover->remove($notification);
         }
     }
     return new JsonResponse();
 }
 /**
  * Helper method to generate field names in format : '<locale>' => '<field>|<locale>'
  *
  * @return string[]
  */
 protected function getFieldNames()
 {
     $userLocales = $this->userContext->getUserLocaleCodes();
     $collection = array();
     foreach ($this->getOption('locales') as $locale) {
         if (in_array($locale, $userLocales)) {
             $collection[$locale] = $locale;
         }
     }
     return $collection;
 }
 /**
  * Get scope from datagrid's filters, fallback on request parameters to deal with the mass edit case
  *
  * @return string
  */
 protected function getScope()
 {
     $filterValues = $this->requestParams->get('_filter');
     if (empty($filterValues)) {
         $filterValues = $this->request->get('filters');
     }
     if (isset($filterValues['scope']['value']) && $filterValues['scope']['value'] !== null) {
         return $filterValues['scope']['value'];
     } else {
         return $this->userContext->getUserChannelCode();
     }
 }
 /**
  * {@inheritdoc}
  */
 public function getActions()
 {
     $actions = [];
     $options = ['entity' => 'product', 'locale' => $this->userContext->getUiLocale(), 'disable_grouping_separator' => true];
     foreach ($this->values as $value) {
         $rawData = $this->normalizer->normalize($value->getData(), 'json', $options);
         // if the value is localizable, let's use the locale the user has chosen in the form
         $locale = null !== $value->getLocale() ? $this->getLocale()->getCode() : null;
         $actions[] = ['field' => $value->getAttribute()->getCode(), 'value' => $rawData, 'options' => ['locale' => $locale, 'scope' => $value->getScope()]];
     }
     return $actions;
 }
 /**
  * List category trees. The select_node_id request parameter
  * allow to send back the tree where the node belongs with a selected  reef attribute
  *
  * @param Request $request
  *
  * @throws AccessDeniedException
  *
  * @return array
  *
  * @Template
  */
 public function listTreeAction(Request $request)
 {
     if (false === $this->securityFacade->isGranted($this->buildAclName('category_list'))) {
         throw new AccessDeniedException();
     }
     $selectNodeId = $request->get('select_node_id', -1);
     try {
         $selectNode = $this->findCategory($selectNodeId);
     } catch (NotFoundHttpException $e) {
         $selectNode = $this->userContext->getUserCategoryTree($this->rawConfiguration['related_entity']);
     }
     return ['trees' => $this->categoryRepository->getTrees(), 'selectedTreeId' => $selectNode->isRoot() ? $selectNode->getId() : $selectNode->getRoot(), 'include_sub' => (bool) $request->get('include_sub', false), 'item_count' => (bool) $request->get('with_items_count', true), 'related_entity' => $this->rawConfiguration['related_entity']];
 }
 /**
  * Apply current values to a fake product and test its integrity with the product validator.
  * If violations are raised, values are not valid.
  *
  * Errors are stored in json format to be useable by the Product Edit Form.
  *
  * @return bool
  */
 public function hasValidValues()
 {
     $data = json_decode($this->values, true);
     $locale = $this->userContext->getUiLocale()->getCode();
     $data = $this->localizedConverter->convertToDefaultFormats($data, ['locale' => $locale]);
     $product = $this->productBuilder->createProduct('FAKE_SKU_FOR_MASS_EDIT_VALIDATION_' . microtime());
     $this->productUpdater->update($product, $data);
     $violations = $this->productValidator->validate($product);
     $violations->addAll($this->localizedConverter->getViolations());
     $errors = ['values' => $this->internalNormalizer->normalize($violations, 'internal_api', ['product' => $product])];
     $this->errors = json_encode($errors);
     return 0 === $violations->count();
 }
Ejemplo n.º 29
0
 /**
  * @param Request $request
  * @param string  $code
  *
  * @throws NotFoundHttpException     If product is not found or the user cannot see it
  * @throws AccessDeniedHttpException If the user does not have permissions to edit the product
  *
  * @return JsonResponse
  */
 public function postAction(Request $request, $code)
 {
     $group = $this->groupRepository->findOneByIdentifier($code);
     if (null === $group) {
         throw new NotFoundHttpException(sprintf('Group with code "%s" not found', $code));
     }
     $data = json_decode($request->getContent(), true);
     $this->updater->update($group, $data);
     $violations = $this->validator->validate($group);
     if (0 < $violations->count()) {
         $errors = $this->violationNormalizer->normalize($violations, 'internal_api', $this->userContext->toArray());
         return new JsonResponse($errors, 400);
     }
     $this->saver->save($group);
     return new JsonResponse($this->normalizer->normalize($group, 'internal_api', $this->userContext->toArray()));
 }
 /**
  * {@inheritdoc}
  */
 public function setDefaultOptions(OptionsResolverInterface $resolver)
 {
     $resolver->setRequired(array('class'));
     $resolver->setOptional(array('locale', 'url'));
     $resolver->setDefaults(array('multiple' => false, 'transformer_options' => array(), 'collection_id' => null, 'route' => 'pim_ui_ajaxentity_list', 'route_parameters' => array(), 'data_class' => null, 'error_bubbling' => false, 'minimum_input_length' => 0));
     $resolver->setNormalizers(array('locale' => function (Options $options, $value) {
         if (!$value) {
             $value = $this->userContext->getCurrentLocaleCode();
         }
         return $value;
     }, 'url' => function (Options $options, $value) {
         if (!$value) {
             $parameters = $this->getRouteParameters($options);
             $value = $this->router->generate($options['route'], $parameters);
         }
         return $value;
     }));
 }