public function toArrayI18N(Entity $entity, array $locales=[], $depth=0) {
		if(!$locales)
			$locales = $entity->getLocales();
		$res = [];

		foreach($entity->getDefinition()->properties() as $name=>$property) {
			if($property->get('i18n')) {
				foreach($locales as $locale) {
					if($entity->getDefinition()->property($name)->get('many')) {
						foreach($entity->get($name, $locale)->all() as $k=>$v)
							$res[$name][$locale][$k] = $this->propertyToArray($v, $property);
					}
					else
						$res[$name][$locale] = $this->propertyToArray($entity->get($name, $locale), $property);
				}
			}
			elseif($entity->getDefinition()->property($name)->get('type') == 'entity') {
				if($depth < 1)
					continue;
				if($entity->getDefinition()->property($name)->get('many')) {
					foreach($entity->get($name) as $entity)
						$res[$name][] = $entity->toArrayI18N($locales, $depth-1);
				}
				else
					$res[$name] = $entity->toArrayI18N($depth-1);
			}
			elseif($entity->getDefinition()->property($name)->get('many')) {
				$res[$name] = [];
				foreach($entity->get($name)->all() as $k=>$v)
					$res[$name][$k] = $this->propertyToArray($v, $property);
			}
			else
				$res[$name] = $this->propertyToArray($entity->get($name), $property);
		}

		return $res;
	}
public function toArrayI18N(Entity $entity, array $locales=[], $depth=0) {
		if(!$locales)
			$locales = $entity->getLocales();
		$res = [];

		foreach($entity->getDefinition()->properties() as $name=>$property) {
			if($property->get('i18n')) {
				foreach($locales as $locale) {
					if($entity->getDefinition()->property($name)->get('many')) {
						foreach($entity->get($name, $locale)->all() as $k=>$v)
							$res[$name][$locale][$k] = $this->propertyToArray($v, $property);
					}
					else
						$res[$name][$locale] = $this->propertyToArray($entity->get($name, $locale), $property);
				}
			}
			elseif($entity->getDefinition()->property($name)->get('type') == 'entity') {
				if($depth < 1)
					continue;
				if($entity->getDefinition()->property($name)->get('many')) {
					foreach($entity->get($name) as $entity)
						$res[$name][] = $entity->toArrayI18N($locales, $depth-1);
				}
				else
					$res[$name] = $entity->toArrayI18N($depth-1);
			}
			elseif($entity->getDefinition()->property($name)->get('many')) {
				$res[$name] = [];
				foreach($entity->get($name)->all() as $k=>$v)
					$res[$name][$k] = $this->propertyToArray($v, $property);
			}
			else
				$res[$name] = $this->propertyToArray($entity->get($name), $property);
		}

		return $res;
	}
public function toArrayI18N ( Entity $ entity , array $ locales = [ ] , $ depth = 0 ) { if ( ! $ locales ) $ locales = $ entity -> getLocales ( ) ; $ res = [ ] ; foreach ( $ entity -> getDefinition ( ) -> properties ( ) as $ name => $ property ) { if ( $ property -> get ( 'i18n' ) ) { foreach ( $ locales as $ locale ) { if ( $ entity -> getDefinition ( ) -> property ( $ name ) -> get ( 'many' ) ) { foreach ( $ entity -> get ( $ name , $ locale ) -> all ( ) as $ k => $ v ) $ res [ $ name ] [ $ locale ] [ $ k ] = $ this -> propertyToArray ( $ v , $ property ) ; } else $ res [ $ name ] [ $ locale ] = $ this -> propertyToArray ( $ entity -> get ( $ name , $ locale ) , $ property ) ; } } elseif ( $ entity -> getDefinition ( ) -> property ( $ name ) -> get ( 'type' ) == 'entity' ) { if ( $ depth < 1 ) continue ; if ( $ entity -> getDefinition ( ) -> property ( $ name ) -> get ( 'many' ) ) { foreach ( $ entity -> get ( $ name ) as $ entity ) $ res [ $ name ] [ ] = $ entity -> toArrayI18N ( $ locales , $ depth - 1 ) ; } else $ res [ $ name ] = $ entity -> toArrayI18N ( $ depth - 1 ) ; } elseif ( $ entity -> getDefinition ( ) -> property ( $ name ) -> get ( 'many' ) ) { $ res [ $ name ] = [ ] ; foreach ( $ entity -> get ( $ name ) -> all ( ) as $ k => $ v ) $ res [ $ name ] [ $ k ] = $ this -> propertyToArray ( $ v , $ property ) ; } else $ res [ $ name ] = $ this -> propertyToArray ( $ entity -> get ( $ name ) , $ property ) ; } return $ res ; }
Convert entity to a formatted array with translations.
@param  Entity  $entity
@param  array $locales
@param  integer $depth
@return array
Convert entity to a formatted array with translations .