Generate coordinates when offer added

This commit is contained in:
Jannis Portmann 2022-01-12 14:42:02 +01:00
parent 3a525f397c
commit c6eadf742c
3 changed files with 64 additions and 2 deletions

View file

@ -38,7 +38,7 @@ class OfferController extends AbstractController
}
#[Route('/new', name: 'new_offer')]
public function newOffer(Request $request, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
public function newOffer(Request $request, PlzToCoordinate $plzconverter, string $photoDir, OfferPhotoHelper $offerPhotoHelper): Response
{
$offer = new Offering();
$form = $this->createForm(OfferingFormType::class, $offer);
@ -50,6 +50,11 @@ class OfferController extends AbstractController
$offer->setByUser($user);
$offer->setCreatedAt(new \DateTime());
$coordinate = $plzconverter->convertPlzToCoordinate($form['zipCode']->getData());
if ($coordinate != null) {
$offer->setCoordinate($coordinate);
}
if ($photo = $form['photo']->getData()) {
$offerPhotoHelper->uploadOfferPhoto($photoDir, $photo, $offer);
}

View file

@ -4,6 +4,7 @@ namespace App\Entity;
use App\Repository\OfferingRepository;
use Doctrine\ORM\Mapping as ORM;
use Location\Coordinate;
use Symfony\Component\Validator\Constraints as Assert;
/**
@ -51,6 +52,16 @@ class Offering
*/
private $description;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $lat;
/**
* @ORM\Column(type="float", nullable=true)
*/
private $lng;
public function getId(): ?int
{
return $this->id;
@ -132,4 +143,19 @@ class Offering
{
return (string) $this-getTitle();
}
}
public function getCoordinate(): ?Coordinate
{
$coordinate = new Coordinate($this->long, $this->lat);
return $coordinate;
}
public function setCoordinate(Coordinate $coordinate): self
{
$this->lat = $coordinate->getLat();
$this->lng = $coordinate->getLng();
return $this;
}
}