diff --git a/src/Benzina/ProjectsRewardsPump.php b/src/Benzina/ProjectsRewardsPump.php index cf29234..8c53a22 100644 --- a/src/Benzina/ProjectsRewardsPump.php +++ b/src/Benzina/ProjectsRewardsPump.php @@ -7,6 +7,7 @@ use App\Entity\Project\BudgetItemType; use App\Entity\Project\Project; use App\Entity\Project\Reward; use App\Repository\Project\ProjectRepository; +use Gedmo\Translatable\Entity\Translation; use Goteo\Benzina\Pump\ArrayPumpTrait; use Goteo\Benzina\Pump\DoctrinePumpTrait; use Goteo\Benzina\Pump\PumpInterface; @@ -14,6 +15,7 @@ use Goteo\Benzina\Pump\PumpInterface; class ProjectsRewardsPump implements PumpInterface { use ArrayPumpTrait; + use DatabasePumpTrait; use DoctrinePumpTrait; private const REWARD_KEYS = [ @@ -67,6 +69,8 @@ class ProjectsRewardsPump implements PumpInterface $reward = new Reward(); $reward->setTranslatableLocale($project->getLocales()[0]); $reward->setProject($project); + $reward->setMigrated(true); + $reward->setMigratedId($record['id']); $reward->setTitle($record['reward']); $reward->setDescription($record['description'] ?? $record['reward']); $reward->setMoney(new Money($record['amount'] * 100, 'EUR')); @@ -74,6 +78,18 @@ class ProjectsRewardsPump implements PumpInterface $reward->setUnitsTotal($record['units'] ?? 0); $reward->setUnitsAvailable($record['units'] ?? 0); + $localizations = $this->getRewardLocalizations($reward, $context); + $translations = $this->entityManager->getRepository(Translation::class); + foreach ($localizations as $localization) { + $locale = $localization['lang']; + + $reward->addLocale($locale); + $translations + ->translate($reward, 'title', $locale, $localization['reward'] ?? $record['reward']) + ->translate($reward, 'description', $locale, $localization['description'] ?? $record['description']) + ; + } + $this->persist($reward, $context); } @@ -93,4 +109,15 @@ class ProjectsRewardsPump implements PumpInterface return BudgetItemType::Infrastructure; } } + + private function getRewardLocalizations(Reward $reward, array $context): array + { + $query = $this->getDbConnection($context)->prepare( + 'SELECT * FROM `reward_lang` l WHERE l.id = :reward' + ); + + $query->execute(['reward' => $reward->getMigratedId()]); + + return $query->fetchAll(); + } } diff --git a/src/Entity/Project/Reward.php b/src/Entity/Project/Reward.php index 27cbad5..dc3f60d 100644 --- a/src/Entity/Project/Reward.php +++ b/src/Entity/Project/Reward.php @@ -2,8 +2,10 @@ namespace App\Entity\Project; +use App\Entity\Interface\LocalizedEntityInterface; use App\Entity\Money; use App\Entity\Trait\LocalizedEntityTrait; +use App\Entity\Trait\MigratedEntity; use App\Mapping\Provider\EntityMapProvider; use App\Repository\Project\RewardRepository; use AutoMapper\Attribute\MapProvider; @@ -19,8 +21,9 @@ use Gedmo\Mapping\Annotation as Gedmo; #[MapProvider(EntityMapProvider::class)] #[ORM\Table(name: 'project_reward')] #[ORM\Entity(repositoryClass: RewardRepository::class)] -class Reward +class Reward implements LocalizedEntityInterface { + use MigratedEntity; use LocalizedEntityTrait; #[ORM\Id]