<?php
namespace Evo\Infrastructure\MappingORM;
use ApiPlatform\Core\Annotation\ApiFilter;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\BooleanFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\ExistsFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Core\Serializer\Filter\GroupFilter;
use App\Controller\Api\CreateOrUpdateLetterAction;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Gedmo\Mapping\Annotation as Gedmo;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
/**
* @ApiResource(
* attributes={
* "normalization_context"={"groups"={"read_letter"}},
* "denormalization_context"={"groups"={"write_letter"}}
* },
* collectionOperations={
* "post"={
* "controller"=CreateOrUpdateLetterAction::class,
* },
* "get",
* },
* itemOperations={
* "get",
* "put"={
* "controller"=CreateOrUpdateLetterAction::class,
* },
* "delete"={"security"="is_granted('ROLE_ADMIN')"}
* }
* )
* @ApiFilter(OrderFilter::class, arguments={"orderParameterName"="order"})
* @ApiFilter(
* SearchFilter::class,
* properties={
* "status": "exact",
* "organization": "exact",
* "type": "exact",
* "organization.status": "exact",
* "id": "partial",
* "isRead": "exact",
* "organization.store": "exact",
* "organization.id": "exact"
* })
* @ApiFilter(BooleanFilter::class, properties={"isRead", "isScanned", "isImportant", "isArchived"})
* @ApiFilter(GroupFilter::class, arguments={"parameterName": "groups", "overrideDefaultGroups": true})
* @ApiFilter(ExistsFilter::class, properties={"contentUrl"})
* @ApiFilter(DateFilter::class, properties={"createdAt"})
* @ORM\Entity(repositoryClass="App\Repository\LetterRepository")
* @ORM\Table(name="letter")
* @Vich\Uploadable
*/
class Letter
{
/**
* @Groups({"read_letter", "read_letter_forward", "admin:read:letter", "read_npai", "admin:filter:letter", "read_letter_signature", "read_letter_tag"})
* @ORM\Id()
* @ORM\GeneratedValue()
* @ORM\Column(type="integer")
*/
private ?int $id = null;
/**
* @Groups({"read_letter", "write_letter", "read_letter_forward", "admin:read:letter", "read_letter_signature"})
* @ORM\Column(type="boolean")
*/
private $isRead;
/**
* @Groups({"read_letter", "write_letter", "read_letter_forward", "admin:read:letter", "read_letter_signature"})
* @ORM\Column(type="string", length=255)
*/
private ?string $status = null;
/**
* @Groups({"read_letter", "admin:read:letter"})
*
* @var string The url
*/
private $envelopeBackUrl;
/**
* @Groups({"read_letter", "write_letter","read_zappier_letter", "admin:read:letter"})
* @ORM\Column(type="string", nullable=true)
*/
private $contentUrl;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="letter", fileNameProperty="contentPath")
* @Assert\File(
* maxSize = "5M",
* mimeTypes = {"application/pdf", "application/x-pdf", "image/jpeg", "image/png"},
* mimeTypesMessage = "Please upload a valid Image or PDF file"
* )
*/
private ?File $contentFile = null;
/**
* @var string The content letter file path
*
* @ApiProperty(writable=false)
* @Groups({"read_letter", "admin:read:letter"})
* @ORM\Column(type="string", nullable=true)
*/
private ?string $contentPath = null;
/**
* @Groups({"read_letter", "write_letter", "admin:read:letter", "read_zappier_letter"})
* @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\Organization", inversedBy="letters")
*/
private ?Organization $organization = null;
/**
* @Groups({"read_letter","read_zappier_letter", "write_letter", "read_letter_forward", "admin:read:letter", "admin:filter:letter", "read_letter_signature"})
* @ORM\Column(type="string", length=255)
*/
private ?string $type = null;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="letter", fileNameProperty="envelopeFrontPath")
* @Assert\File(
* maxSize = "5M",
* mimeTypes = {"application/pdf", "application/x-pdf", "image/jpeg", "image/png"},
* mimeTypesMessage = "Please upload a valid Image or PDF file"
* )
*/
private ?File $envelopeFrontFile = null;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
* @Vich\UploadableField(mapping="letter", fileNameProperty="envelopeBackPath")
* @Assert\File(
* maxSize = "5M",
* mimeTypes = {"application/pdf", "application/x-pdf", "image/jpeg", "image/png"},
* mimeTypesMessage = "Please upload a valid Image or PDF file"
* )
*/
private ?File $envelopeBackFile = null;
/**
* @var string The envelopeFront letter file path
*
* @ApiProperty(writable=false)
* @Groups({"read_letter", "admin:read:letter"})
* @ORM\Column(type="string", nullable=true)
*/
private ?string $envelopeFrontPath = null;
/**
* @var string The envelopeFront letter file path
*
* @ApiProperty(writable=false)
* @Groups({"read_letter", "admin:read:letter"})
* @ORM\Column(type="string", nullable=true)
*/
private ?string $envelopeBackPath = null;
/**
* @var \DateTime
*
* @Groups({"read_letter", "admin:read:letter"})
* @Gedmo\Timestampable(on="update")
* @ORM\Column(type="datetime")
*/
private $updatedAt;
/**
* @Groups({"read_letter", "write_letter", "read_zappier_letter", "admin:read:letter"})
* @ORM\Column(type="datetime")
*/
private \DateTimeInterface $createdAt;
/**
* @Groups({"read_letter", "write_letter", "write_letter_signature", "admin:read:letter"})
* @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\LetterSignature", inversedBy="letters", cascade={"persist"})
*/
private ?LetterSignature $letterSignature = null;
/**
* @Groups({"read_letter", "write_letter", "write_letter_forward", "admin:read:letter"})
* @ORM\ManyToOne(targetEntity="Evo\Infrastructure\MappingORM\LetterForward", inversedBy="letters", cascade={"persist"})
*/
private ?LetterForward $letterForward = null;
/**
* @ApiProperty(writable=false)
* @Groups({"read_letter", "admin:read:letter", "read_zappier_letter"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $envelopeFrontPathAWS = null;
/**
* @ApiProperty(writable=false)
* @Groups({"read_letter", "admin:read:letter", "read_zappier_letter"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $envelopeBackPathAWS = null;
/**
* @ApiProperty(writable=false)
* @Groups({"read_letter", "admin:read:letter", "read_zappier_letter"})
* @ORM\Column(type="string", length=255, nullable=true)
*/
private ?string $contentPathAWS = null;
/**
* @Groups({"read_letter", "write_letter", "admin:read:letter"})
* @ORM\Column(type="boolean", nullable=true)
*/
private $isScanned;
/**
* @Groups({"read_letter", "write_letter", "admin:read:letter"})
* @ORM\Column(type="boolean", nullable=true)
*/
private $isImportant;
/**
* @Groups({"read_letter", "write_letter", "admin:read:letter"})
* @ORM\Column(type="boolean", options={"default": false})
*/
private bool $isArchived = false;
/**
* @Groups({"read_letter", "write_letter", "admin:read:letter"})
* @ORM\Column(type="datetime", nullable=true)
*/
private ?\DateTimeInterface $deletedAt = null;
/**
* @Groups({"read_letter", "write_letter"})
* @ORM\ManyToMany(targetEntity="LetterTag", inversedBy="letters")
*/
private ?Collection $tags;
public function __construct()
{
$this->setIsArchived(false);
$this->setIsRead(false);
$this->setIsScanned(false);
$this->createdAt = new \DateTime();
$this->tags = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getCreatedAt(): \DateTimeInterface
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeInterface $createdAt): self
{
$this->createdAt = $createdAt;
return $this;
}
public function getIsRead(): ?bool
{
return $this->isRead;
}
public function setIsRead(bool $isRead): self
{
$this->isRead = $isRead;
return $this;
}
public function getStatus(): ?string
{
return $this->status;
}
public function setStatus(string $status): self
{
$this->status = $status;
return $this;
}
public function getOrganization(): ?Organization
{
return $this->organization;
}
public function setOrganization(?Organization $organization): self
{
$this->organization = $organization;
return $this;
}
/**
* @return mixed
*/
public function getEnvelopeBackUrl()
{
return $this->envelopeBackUrl;
}
/**
* @param mixed $envelopeBackUrl
*/
public function setEnvelopeBackUrl($envelopeBackUrl): void
{
$this->envelopeBackUrl = $envelopeBackUrl;
}
/**
* @return mixed
*/
public function getContentUrl()
{
return $this->contentUrl;
}
/**
* @param mixed $contentUrl
*/
public function setContentUrl($contentUrl): void
{
$this->contentUrl = $contentUrl;
}
public function getType(): ?string
{
return $this->type;
}
public function setType(string $type): self
{
$this->type = $type;
return $this;
}
/**
* @return File
*/
public function getEnvelopeFrontFile(): ?File
{
return $this->envelopeFrontFile;
}
/**
* @param File $envelopeFrontFile
*/
public function setEnvelopeFrontFile(?File $envelopeFrontFile): Letter
{
$this->envelopeFrontFile = $envelopeFrontFile;
if (null !== $envelopeFrontFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTime();
}
return $this;
}
/**
* @return File
*/
public function getContentFile(): ?File
{
return $this->contentFile;
}
/**
* @param File $contentFile
*/
public function setContentFile(?File $contentFile): Letter
{
$this->contentFile = $contentFile;
if (null !== $contentFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTime();
}
return $this;
}
/**
* @return File
*/
public function getEnvelopeBackFile(): ?File
{
return $this->envelopeBackFile;
}
/**
* @param File $envelopeBackFile
*/
public function setEnvelopeBackFile(?File $envelopeBackFile): Letter
{
$this->envelopeBackFile = $envelopeBackFile;
if (null !== $envelopeBackFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTime();
}
return $this;
}
/**
* @return string
*/
public function getContentPath()
{
return $this->contentPath;
}
/**
* @param string $contentPath
*/
public function setContentPath(?string $contentPath): Letter
{
$this->contentPath = $contentPath;
return $this;
}
/**
* @return string
*/
public function getEnvelopeFrontPath()
{
return $this->envelopeFrontPath;
}
/**
* @param string $envelopeFrontPath
*/
public function setEnvelopeFrontPath(?string $envelopeFrontPath): Letter
{
$this->envelopeFrontPath = $envelopeFrontPath;
return $this;
}
/**
* @return string
*/
public function getEnvelopeBackPath()
{
return $this->envelopeBackPath;
}
/**
* @param string $envelopeBackPath
*/
public function setEnvelopeBackPath(?string $envelopeBackPath): Letter
{
$this->envelopeBackPath = $envelopeBackPath;
return $this;
}
/**
* @return \DateTime|\DateTimeImmutable|null
*/
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
/**
* @param \DateTime|\DateTimeImmutable|null $updatedAt
*/
public function setUpdatedAt(?\DateTimeInterface $updatedAt): Letter
{
$this->updatedAt = $updatedAt;
return $this;
}
/**
* @return LetterSignature
*/
public function getLetterSignature()
{
return $this->letterSignature;
}
/**
* @param LetterSignature $letterSignature
*
* @return Letter
*/
public function setLetterSignature(?LetterSignature $letterSignature)
{
$this->letterSignature = $letterSignature;
return $this;
}
public function getLetterForward(): ?LetterForward
{
return $this->letterForward;
}
public function setLetterForward(?LetterForward $letterForward): self
{
$this->letterForward = $letterForward;
return $this;
}
public function __toString()
{
return '#'.$this->getId();
}
public function getEnvelopeFrontPathAWS(): ?string
{
return $this->envelopeFrontPathAWS;
}
public function setEnvelopeFrontPathAWS(?string $envelopeFrontPathAWS): self
{
$this->envelopeFrontPathAWS = $envelopeFrontPathAWS;
return $this;
}
public function getEnvelopeBackPathAWS(): ?string
{
return $this->envelopeBackPathAWS;
}
public function setEnvelopeBackPathAWS(?string $envelopeBackPathAWS): self
{
$this->envelopeBackPathAWS = $envelopeBackPathAWS;
return $this;
}
public function getContentPathAWS(): ?string
{
return $this->contentPathAWS;
}
public function setContentPathAWS(?string $contentPathAWS): self
{
$this->contentPathAWS = $contentPathAWS;
return $this;
}
public function getIsScanned(): ?bool
{
return $this->isScanned;
}
public function setIsScanned(?bool $isScanned): self
{
$this->isScanned = $isScanned;
return $this;
}
public function getIsImportant(): ?bool
{
return $this->isImportant;
}
public function setIsImportant(?bool $isImportant): self
{
$this->isImportant = $isImportant;
return $this;
}
public function getTags(): ?Collection
{
return $this->tags;
}
public function addTag(LetterTag $tag): self
{
if (!$this->tags->contains($tag)) {
$this->tags[] = $tag;
}
return $this;
}
public function removeTag(LetterTag $tag): self
{
$this->tags->removeElement($tag);
return $this;
}
public function getIsArchived(): bool
{
return $this->isArchived;
}
public function setIsArchived(bool $isArchived): self
{
$this->isArchived = $isArchived;
return $this;
}
public function getDeletedAt(): ?\DateTimeInterface
{
return $this->deletedAt;
}
public function setDeletedAt(?\DateTimeInterface $deletedAt): self
{
$this->deletedAt = $deletedAt;
return $this;
}
public function isDeleted(): bool
{
return null !== $this->deletedAt;
}
}