Skip to content

Commit

Permalink
Pump project language and territory
Browse files Browse the repository at this point in the history
  • Loading branch information
subiabre committed Jan 28, 2025
1 parent 84fa63d commit ce99f57
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Benzina/ProjectsPump.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@

use App\Entity\Project\Project;
use App\Entity\Project\ProjectStatus;
use App\Entity\Project\ProjectTerritory;
use App\Entity\User\User;
use App\Repository\User\UserRepository;
use Doctrine\ORM\EntityManagerInterface;
use App\Service\Project\TerritoryService;
use Goteo\Benzina\Pump\AbstractPump;
use Goteo\Benzina\Pump\ArrayPumpTrait;
use Goteo\Benzina\Pump\DoctrinePumpTrait;
Expand All @@ -19,7 +20,7 @@ class ProjectsPump extends AbstractPump

public function __construct(
private UserRepository $userRepository,
private EntityManagerInterface $entityManager,
private TerritoryService $territoryService,
) {}

public function supports(mixed $sample): bool
Expand Down Expand Up @@ -48,8 +49,10 @@ public function pump(mixed $record): void
}

$project = new Project();
$project->setTranslatableLocale($record['lang']);
$project->setTitle($record['name']);
$project->setSubtitle($record['subtitle']);
$project->setTerritory($this->getProjectTerritory($record));
$project->setDescription($record['description']);
$project->setOwner($owner);
$project->setStatus($status);
Expand Down Expand Up @@ -85,4 +88,15 @@ private function getProjectStatus(array $record): ProjectStatus
return ProjectStatus::Fulfilled;
}
}

private function getProjectTerritory(array $record): ProjectTerritory
{
$cleanAddress = $this->cleanProjectLocation($record['project_location'], 2);

if ($cleanAddress === '') {
return ProjectTerritory::unknown();
}

return $this->territoryService->search($cleanAddress);
}
}

0 comments on commit ce99f57

Please sign in to comment.