diff --git a/src/Benzina/ProjectsPump.php b/src/Benzina/ProjectsPump.php index 65e27ee..929116d 100644 --- a/src/Benzina/ProjectsPump.php +++ b/src/Benzina/ProjectsPump.php @@ -57,13 +57,9 @@ class ProjectsPump implements PumpInterface } $project = new Project(); - $project->setTranslatableLocale($record['lang']); - $project->setTitle($record['name']); $project->setSlug($record['id']); - $project->setSubtitle($record['subtitle']); $project->setCategory($this->getProjectCategory($record)); $project->setTerritory($this->getProjectTerritory($record)); - $project->setDescription($record['description']); $project->setVideo($this->getProjectVideo($record)); $project->setOwner($owner); $project->setStatus($status); @@ -72,6 +68,19 @@ class ProjectsPump implements PumpInterface $project->setDateCreated(new \DateTime($record['created'])); $project->setDateUpdated(new \DateTime()); + $project->setTranslatableLocale($record['lang']); + $project->setTitle($record['name']); + $project->setSubtitle($record['subtitle']); + $project->setDescription($this->getProjectDescription($record)); + + $localizations = $this->getProjectLocalizations($project, $context); + foreach ($localizations as $localization) { + $project->setTranslatableLocale($localization['lang']); + $project->setTitle($localization['name']); + $project->setSubtitle($localization['subtitle']); + $project->setDescription($this->getProjectDescription($localization)); + } + $updates = $this->getProjectUpdates($project, $context); foreach ($updates as $update) { $project->addUpdate($update); @@ -90,6 +99,35 @@ class ProjectsPump implements PumpInterface return $this->userRepository->findOneBy(['migratedId' => $record['owner']]); } + private function getProjectDescription(array $record): string + { + $hasTitles = \array_key_exists($record['lang'], self::PROJECT_DESC_TITLES); + + $description = $record['description']; + + $description .= \sprintf("\n##%s", $hasTitles ? self::PROJECT_DESC_TITLES[$record['lang']]['about'] : ''); + $description .= \sprintf("\n%s", $record['about']); + + $description .= \sprintf("\n##%s", $hasTitles ? self::PROJECT_DESC_TITLES[$record['lang']]['motivation'] : ''); + $description .= \sprintf("\n%s", $record['motivation']); + + $description .= \sprintf("\n##%s", $hasTitles ? self::PROJECT_DESC_TITLES[$record['lang']]['related'] : ''); + $description .= \sprintf("\n%s", $record['related']); + + return $description; + } + + private function getProjectLocalizations(Project $project, array $context): array + { + $query = $this->getDbConnection($context)->prepare( + 'SELECT * FROM `project_lang` l WHERE l.id = :project' + ); + + $query->execute(['project' => $project->getMigratedId()]); + + return $query->fetchAll(); + } + private function getProjectCalendar(array $record): ProjectCalendar { $calendar = new ProjectCalendar(); diff --git a/src/Benzina/ProjectsPumpTrait.php b/src/Benzina/ProjectsPumpTrait.php index 1069c2e..9bf33a1 100644 --- a/src/Benzina/ProjectsPumpTrait.php +++ b/src/Benzina/ProjectsPumpTrait.php @@ -127,6 +127,49 @@ trait ProjectsPumpTrait 'PAMLONA' => ['IRUÑEA'], ]; + private const PROJECT_DESC_TITLES = [ + 'es' => [ + 'about' => 'Descripción del proyecto. Características, fortalezas y diferenciales.', + 'motivation' => 'Motivación y a quién va dirigido el proyecto.', + 'related' => 'Experiencia previa y equipo.', + ], + 'gl' => [ + 'about' => 'Características básicas.', + 'motivation' => 'Motivación e a quen vai dirixido o proxecto.', + 'related' => 'Experiencia previa e equipo.', + ], + 'eu' => [ + 'about' => 'Oinarrizko ezaugarriak eta helburuak.', + 'motivation' => 'Zerk bultzatzen zaitu eta zeini zuzenduta dago proiektua.', + 'related' => 'Proiektuaren deskribapenean derrigorrekoa da azaltzea kontutan hartzen den taldearen esperientzia.', + ], + 'ca' => [ + 'about' => 'Característiques bàsiques i objectius.', + 'motivation' => 'Motivació i a qui va dirigit el projecte.', + 'related' => 'Experiència prèvia i equip.', + ], + 'en' => [ + 'about' => 'Main features and goals of the crowdfunding campaign.', + 'motivation' => 'Why this is important.', + 'related' => 'Team and experience.', + ], + 'fr' => [ + 'about' => 'Caractéristiques principales.', + 'motivation' => 'Pourquoi est-ce important.', + 'related' => 'Expérience antérieure et équipe.', + ], + 'it' => [ + 'about' => 'Caratteristiche fondamentali.', + 'motivation' => 'Obiettivo e a chi si dirige il progetto.', + 'related' => 'Esperienza e team.', + ], + 'de' => [ + 'about' => 'Hauptmerkmale.', + 'motivation' => 'Warum das wichtig ist.', + 'related' => 'Team und Erfahrung.', + ], + ]; + private const PROJECT_KEYS = [ 'id', 'name',