Pump localizations of project rewards

This commit is contained in:
2025-09-03 16:05:16 +02:00
parent 8aa962fec2
commit ac231c8a62
2 changed files with 31 additions and 1 deletions
+27
View File
@@ -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();
}
}
+4 -1
View File
@@ -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]