Author: Adam Piotrowski (adam@wellcommerce.org)
Inheritance: extends WellCommerce\Bundle\CoreBundle\Entity\TimestampableInterface, extends WellCommerce\Bundle\CoreBundle\Entity\BlameableInterface, extends WellCommerce\Bundle\CurrencyBundle\Entity\CurrencyAwareInterface
Esempio n. 1
0
 private function duplicateTranslatableEntity(LocaleAwareInterface $entity, array $properties, LocaleInterface $targetLocale)
 {
     $duplicate = clone $entity;
     foreach ($properties as $propertyName) {
         $value = sprintf('%s-%s', $this->propertyAccessor->getValue($entity, $propertyName), $targetLocale->getCode());
         $this->propertyAccessor->setValue($duplicate, $propertyName, $value);
         $duplicate->setLocale($targetLocale->getCode());
         $this->doctrineHelper->getEntityManager()->persist($duplicate);
     }
 }
Esempio n. 2
0
 protected function findTranslatableEntities(EntityRepository $repository, LocaleInterface $locale) : Collection
 {
     $criteria = new Criteria();
     $criteria->where($criteria->expr()->eq('locale', $locale->getCode()));
     $collection = $repository->matching($criteria);
     return $collection;
 }
 /**
  * Returns an array containing all previously imported translations
  *
  * @param LocaleInterface $locale
  *
  * @return array
  */
 protected function getDatabaseTranslations(LocaleInterface $locale)
 {
     $messages = [];
     $collection = $this->repository->matching(new Criteria());
     $collection->map(function (DictionaryInterface $dictionary) use($locale, &$messages) {
         $messages[$dictionary->getIdentifier()] = $dictionary->translate($locale->getCode())->getValue();
     });
     return $messages;
 }
 /**
  * Deletes the translatable entities for locale
  *
  * @param EntityRepository $repository
  * @param LocaleInterface  $locale
  * @param OutputInterface  $output
  */
 protected function deleteTranslatableEntities(EntityRepository $repository, LocaleInterface $locale, OutputInterface $output)
 {
     $entityManager = $this->getDoctrineHelper()->getEntityManager();
     $criteria = new Criteria();
     $criteria->where($criteria->expr()->eq('locale', $locale->getCode()));
     $collection = $repository->matching($criteria);
     $collection->map(function (LocaleAwareInterface $entity) use($entityManager) {
         $entityManager->remove($entity);
     });
     $output->write(sprintf('Deleted <info>%s</info> entities <info>%s</info>', $collection->count(), $repository->getClassName()), true);
 }