You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
herbarium/src/Entity/Post.php

155 lines
3.5 KiB

<?php
namespace App\Entity;
use ApiPlatform\Metadata;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\GetCollection;
use App\Repository\PostRepository;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Serializer\Attribute\Groups;
#[ORM\Entity(repositoryClass: PostRepository::class)]
#[ORM\HasLifecycleCallbacks]
#[ApiResource(
operations: [new Metadata\Post(), new Metadata\Get(), new Metadata\Put(), new Metadata\Delete(), new Metadata\Patch()],
normalizationContext: ['groups' => ['post:collection:read', 'post:read']],
)]
#[GetCollection(normalizationContext: ['groups' => ['post:collection:read']])]
class Post
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['post:collection:read'])]
private ?int $id = null;
#[ORM\Column]
#[Groups(['post:collection:read'])]
private ?\DateTimeImmutable $foundDate = null;
#[ORM\Column]
#[ApiProperty(writable: false)]
#[Groups(['post:collection:read'])]
private ?\DateTimeImmutable $publicationDate = null;
#[ORM\Column(nullable: true)]
#[Groups(['post:collection:read'])]
private ?float $latitude = null;
#[ORM\Column(nullable: true)]
#[Groups(['post:collection:read'])]
private ?float $longitude = null;
#[ORM\Column(nullable: true)]
#[Groups(['post:collection:read'])]
private ?float $altitude = null;
#[ORM\Column(type: Types::TEXT)]
#[Groups(['post:read'])]
private ?string $commentary = null;
#[ORM\ManyToOne(inversedBy: 'posts')]
#[ApiProperty(readableLink: false)]
#[Groups(['post:collection:read'])]
private ?Species $species = null;
public function getId(): ?int
{
return $this->id;
}
public function getFoundDate(): ?\DateTimeImmutable
{
return $this->foundDate;
}
public function setFoundDate(\DateTimeImmutable $foundDate): static
{
$this->foundDate = $foundDate;
return $this;
}
public function getPublicationDate(): ?\DateTimeImmutable
{
return $this->publicationDate;
}
public function setPublicationDate(\DateTimeImmutable $publicationDate): static
{
$this->publicationDate = $publicationDate;
return $this;
}
public function getLatitude(): ?float
{
return $this->latitude;
}
public function setLatitude(?float $latitude): static
{
$this->latitude = $latitude;
return $this;
}
public function getLongitude(): ?float
{
return $this->longitude;
}
public function setLongitude(?float $longitude): static
{
$this->longitude = $longitude;
return $this;
}
public function getAltitude(): ?float
{
return $this->altitude;
}
public function setAltitude(?float $altitude): static
{
$this->altitude = $altitude;
return $this;
}
public function getCommentary(): ?string
{
return $this->commentary;
}
public function setCommentary(string $commentary): static
{
$this->commentary = $commentary;
return $this;
}
public function getSpecies(): ?Species
{
return $this->species;
}
public function setSpecies(?Species $species): static
{
$this->species = $species;
return $this;
}
#[ORM\PrePersist]
#[ORM\PreUpdate]
public function setPublicationDateValue(): void
{
$this->publicationDate = new \DateTimeImmutable();
}
}