Ejemplo n.º 1
0
 private function createMetadata($className, Metadata $metadata = null)
 {
     $parentClass = get_parent_class($className);
     if ($parentClass) {
         $parentMetadata = $this->createMetadata($parentClass, $metadata);
         if ($parentMetadata !== null) {
             $metadata = $parentMetadata;
         }
     }
     $metadataArray = $this->getMetadataArray();
     if (array_key_exists($className, $metadataArray)) {
         if ($metadata === null) {
             $metadata = new Metadata();
         }
         $metadata->setClass($className);
         if (isset($metadataArray[$className]['properties']) && is_array($metadataArray[$className]['properties'])) {
             $properties = $metadataArray[$className]['properties'];
             foreach ($properties as $name => $propertyData) {
                 $property = new Property();
                 $property->setName($name);
                 if (isset($propertyData['strategy'])) {
                     $property->setStrategy($propertyData['strategy']);
                 }
                 $metadata->addProperty($property);
             }
         }
         return $metadata;
     }
     return null;
 }
Ejemplo n.º 2
0
 public function translate($entity, Metadata $metadata, Property $property, $locale)
 {
     if ($locale === $this->defaultLocale) {
         return;
     }
     $accessor = PropertyAccess::createPropertyAccessor();
     /** @var Translation $translation */
     $translation = $this->getRepository()->findOneBy(['class' => $metadata->getClass(), 'refId' => $entity->getId(), 'property' => $property->getName(), 'locale' => $locale]);
     $value = '';
     if ($translation !== null && $translation->getTranslation() !== null) {
         $value = $translation->getTranslation();
     }
     $accessor->setValue($entity, $property->getName(), $value);
 }
Ejemplo n.º 3
0
 public function getTranslations($entity, Metadata $metadata, Property $property)
 {
     $data = [];
     foreach ($this->locales as $locale) {
         $data[$locale] = null;
     }
     if (!$entity instanceof Route) {
         return $data;
     }
     $translationRoutes = $this->getRepository('EnhavoTranslationBundle:TranslationRoute')->findBy(['type' => $entity->getType(), 'typeId' => $entity->getTypeId()]);
     foreach ($this->locales as $locale) {
         if ($locale === $this->defaultLocale) {
             $accessor = PropertyAccess::createPropertyAccessor();
             $value = $accessor->getValue($entity, $property->getName());
             $data[$locale] = $value;
             continue;
         }
         $value = null;
         foreach ($translationRoutes as $translationRoute) {
             if ($translationRoute->getLocale() === $locale) {
                 $value = $translationRoute->getRoute()->getStaticPrefix();
                 break;
             }
         }
         $data[$locale] = $value;
     }
     return $data;
 }